adbus_ConnectionCallbacks Struct Reference

Structure to hold callbacks registered with adbus_conn_new(). More...

Data Fields

adbus_Callback release
 Called when the connection is destroyed.
adbus_SendMsgCallback send_message
 This is a callback to send messages.
adbus_ProxyCallback proxy
 Callback to send messages across to the connection thread.
adbus_ShouldProxyCallback should_proxy
adbus_GetProxyCallback get_proxy
adbus_BlockCallback block

Detailed Description

Structure to hold callbacks registered with adbus_conn_new().


Field Documentation

Callback to send messages across to the connection thread.

  • user - User data associated with this callback.
  • cb - Function to call on the target thread.
  • release - Function to free the data in the cbuser argument.
  • cbuser - Data associated with the cb and release arguments.

For example:

    class ProxyEvent
    {
    public:
        ProxyEvent(adbus_Callback cb, adbus_Callback release, void* user)
        : m_Cb(cb), m_Release(release), m_User(user) {}
 
        ~ProxyEvent()
        { if (m_Release) m_Release(m_User); }
 
        void call()
        { if (m_Cb) m_Cb(m_User); }
 
        adbus_Callback  m_Cb;
        adbus_Callback  m_Release;
        void*           m_User;
    };
  
    void Proxy(void* user, adbus_Callback cb, adbus_Callback release, void* cbuser)
    {
        if (OnConnectionThread())
        {
            ProxyEvent e(cb, release, user);
            e.call();
        }
        else
        {
           ProxyEvent* e = new ProxyEvent(cb, release, user);
           PostEvent(e);
        }
    }
  
    // On the connection thread
    void ProcessEvent(ProxyEvent* e)
    {
        e->call();
        delete e;
    }

Called when the connection is destroyed.

Since the connection is internally ref counted via adbus_conn_ref() and adbus_conn_deref() it can occur after the call to adbus_conn_free().

This is a callback to send messages.

The return value should be the number of bytes written or -1 on error (ie the return value of recv). The connection considers any value except the full message length to be an error.

For example:

    adbus_ssize_t SendMsg(void* user, adbus_Message* m)
    { return send(*(adbus_Socket*) user, m->data, m->size, 0);

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

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