[interfacekit] Re: BHandler::fToken

  • From: "Marc Flerackers" <mflerackers@xxxxxxxxxx>
  • To: <interfacekit@xxxxxxxxxxxxx>
  • Date: Mon, 10 Mar 2003 15:38:33 +0100

> Until here, I agree with you.
>
> But with the following paragraph, I don't!
>
> > Since ServerViews are completely bound to their ServerWindow (since they
> are
> > created/deleted when the client side BView is attached/Detached), the
> tokens
> > for these don't need to be unique, however it seems that the tokens come
> > from one big pool on the server-side.
>
> A Layer's( BView's counterpart in app_server) token must be unique within
> app_server!!!; or, at least, in ServerWindow - that is until
> DarkWyrm tells
> us how it's gonna be.

But I was talking about BeOS R5, not about the OpenBeOS app_server, I am
aware that the OpenBeOS app_server works differently :)

> > For the people who are new to tokens. You use tokens instead of
> pointer to
> > objects because of safety. With a pointer you don't know if the
> object is
> > valid. Tokens sit in a hashtable, and are inserted and removed when the
> > object they point to gets created/deleted. So when you look up a token,
> you
> > know you have a valid object.
>
> I've proposed to DarkWyrm to use as a server token a BView pointer, for a
> faster retrieval of the BView that's gonna receive the message.

I suppose you mean a ServerView(or Layer) pointer?

> I don't see
> how a token received form app_server can be invalid! Once a BView
> object is
> instantiated, it has the same address until it's deleted. But before it is
> deleted, it is detached form the window it belongs, thus a message is sent
> to ServerWindow. The Layer that was associated with, is deleted, and the
> token(the BView's address) is removed from the ServerWindow's
> list of known
> tokens.

Actually a ServerView(or Layer) exists as long as the BView is attached to a
BWindow, once the BView gets detached, the corresponding ServerView is
deleted. A new one is created when the BView gets attached again.

I just explained tokens, for the people who are wondering why they are used
:)

Why would they be invalid, well, lets say a developer overwrites the memory
in a wrong place, like BView::server_token, this would cause a wrong token
to be sent to the server. So to keep the server from crashing in such case,
it looks up the token to see if it's valid. No one keeps you from storing
the pointer as a key in the hash table. As long as your keys are unique you
can use any value you prefer.
The only point I see with using pointers is that a new object can get the
same address as one that was deleted previously, which can cause problems
since an invalid reference could be seen as a valid one. This could make a
mess in a multithreaded environment.

Marc Flerackers (mflerackers@xxxxxxxxxx)
Software Engineer


Other related posts: