adbus_State Struct Reference

Helper class to manage connection services (binds, matches and replies). More...

Related Functions

(Note that these are not member functions.)



void adbus_state_bind (adbus_State *s, adbus_Connection *c, const adbus_Bind *b)
 Adds a binding to the supplied connection.
void adbus_state_addmatch (adbus_State *s, adbus_Connection *c, const adbus_Match *m)
 Adds a match to the supplied connection.
void adbus_state_addreply (adbus_State *s, adbus_Connection *c, const adbus_Reply *r)
 Adds a reply to the supplied connection.
void adbus_state_reset (adbus_State *s)
 Resets the state, removing all services.
void adbus_state_free (adbus_State *s)
 Frees the state, removing all services.

Detailed Description

Helper class to manage connection services (binds, matches and replies).

adbus_State provides two benefits over using the connection services directly:

  1. The connection services can only be added and removed on the connection thread (using adbus_conn_addreply(), adbus_conn_bind(), etc). An adbus_State instance acts as a proxy from the local thread to one or more connection threads managing the thread jumping needed to register/unregister services.
  2. Keeps track of services as the connection removes them, so that the remaining services can be removed in a single call.

The general idea is to keep an adbus_State associated with any callback data (ie the local object, data structure, etc). Thus when the local object gets destroyed it simply needs to reset or free the state and all remaining callbacks are cleared out.

Some points to note:

For example:

  struct Foo
  {
      adbus_State* state;
  };

  struct Foo* CreateFoo()
  {
      struct Foo* f = (struct Foo*) calloc(sizeof(struct Foo), 1);
      f->state = adbus_state_new();
      return f;
  }

  void DeleteFoo(struct Foo* f)
  {
      if (f) {
          adbus_state_free(f->state);
          free(f);
      }
  }

  static int SomeCallback(adbus_CbData* d)
  {
      struct Foo* f = (struct Foo*) d->user1;
      // Do something
      return 0;
  }

  void AddMatch(struct Foo* f, adbus_Connection* c)
  {
      adbus_Match m;      
      adbus_match_init(&m);
      m.sender    = "com.example.ExampleService";
      m.path      = "/";
      m.member    = "ExampleSignal";
      m.callback  = &SomeCallback;
      m.cuser     = f;

      adbus_state_addmatch(f->state, c, &m);
  }
See also:
adbus_Proxy

Friends And Related Function Documentation

void adbus_state_addmatch ( adbus_State s,
adbus_Connection c,
const adbus_Match m 
) [related]

Adds a match to the supplied connection.

Note:
The proxy and relproxy fields must not be set. They will be overwritten by proxy methods to proxy messages to the local thread.
Warning:
This must be called on the state's local thread.
See also:
adbus_conn_addmatch()
void adbus_state_addreply ( adbus_State s,
adbus_Connection c,
const adbus_Reply r 
) [related]

Adds a reply to the supplied connection.

Note:
The proxy and relproxy fields must not be set. They will be overwritten by proxy methods to proxy messages to the local thread.
Warning:
This must be called on the state's local thread.
See also:
adbus_conn_addreply()
void adbus_state_bind ( adbus_State s,
adbus_Connection c,
const adbus_Bind b 
) [related]

Adds a binding to the supplied connection.

Note:
The proxy and relproxy fields must not be set. They will be overwritten by proxy methods to proxy messages to the local thread.
Warning:
This must be called on the state's local thread.
See also:
adbus_conn_bind()
void adbus_state_reset ( adbus_State s  )  [related]

Resets the state, removing all services.

This will not free the state, so it is ready for reuse.

Warning:
This must be called on the state's local thread.

The documentation for this struct was generated from the following file:
 All Data Structures Files Functions Variables Friends Defines

Generated on Mon Mar 22 00:10:02 2010 for adbus by  doxygen 1.6.1