14 #ifndef __WVDBUSCONN_H
15 #define __WVDBUSCONN_H
17 #include "wvstreamclone.h"
19 #include "wvdbusmsg.h"
20 #include "wvhashtable.h"
23 #define WVDBUS_DEFAULT_TIMEOUT (300*1000)
32 typedef wv::function<bool(
WvDBusMsg&)> WvDBusCallback;
51 virtual wvuid_t get_uid() = 0;
61 virtual wvuid_t get_uid();
67 bool client, authorized, in_post_select;
106 wvuid_t get_uid() {
return auth ? auth->get_uid() : WVUID_INVALID; }
109 void out(WVSTRING_FORMAT_DECL)
110 {
return out(
WvString(WVSTRING_FORMAT_CALL)); }
120 time_t msec_timeout = WVDBUS_DEFAULT_TIMEOUT);
132 virtual void close();
145 time_t msec_timeout = WVDBUS_DEFAULT_TIMEOUT);
163 time_t msec_timeout = WVDBUS_DEFAULT_TIMEOUT,
164 wv::function<
void(uint32_t)> serial_cb = 0);
220 time_t mintimeout_msec();
221 virtual bool post_select(SelectInfo &si);
230 Pending(
WvDBusMsg &_msg,
const WvDBusCallback &_cb,
234 serial = msg.get_serial();
235 if (msec_timeout < 0)
236 msec_timeout = 5*3600*1000;
237 valid_until = msecadd(wvstime(), msec_timeout);
240 DeclareWvDict(Pending, uint32_t, serial);
245 void expire_pending(Pending *p);
246 void cancel_pending(uint32_t serial);
247 void add_pending(
WvDBusMsg &msg, WvDBusCallback cb,
248 time_t msec_timeout);
258 const WvDBusCallback &_cb,
void *_cookie)
260 { pri = _pri; cookie = _cookie; }
262 static int priority_order(
const CallbackInfo *a,
const CallbackInfo *b);
264 DeclareWvList(CallbackInfo);
265 CallbackInfoList callbacks;
virtual bool authorize(WvDBusConn &c)=0
Main action callback.
virtual bool authorize(WvDBusConn &c)
Main action callback.
virtual void close()
Close the underlying stream.
virtual bool filter_func(WvDBusMsg &msg)
Called by for each received message.
virtual ~WvDBusConn()
Release this connection.
WvDBusConn(WvStringParm moniker, IWvDBusAuth *_auth=NULL, bool _client=true)
Creates a new dbus connection using the given WvStreams moniker.
CallbackPri
The priority level of a callback registration.
WvDBusMsg send_and_wait(WvDBusMsg msg, time_t msec_timeout=WVDBUS_DEFAULT_TIMEOUT, wv::function< void(uint32_t)> serial_cb=0)
Send a message on the bus and wait for a reply to come in, returning the message when it does.
void request_name(WvStringParm name, const WvDBusCallback &onreply=0, time_t msec_timeout=WVDBUS_DEFAULT_TIMEOUT)
Request the given service name on DBus.
bool isidle()
Returns true if there are no outstanding messages that have not received (or timed out) their reply.
uint32_t send(WvDBusMsg msg)
Send a message on the bus, not expecting any reply.
void add_callback(CallbackPri pri, WvDBusCallback cb, void *cookie=NULL)
Adds a callback to the connection: all received messages will be sent to all callbacks to look at and...
void del_callback(void *cookie)
Delete all callbacks that have the given cookie.
WvString uniquename() const
Return this connection's unique name on the bus, assigned by the server at connect time.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
WvStreamClone simply forwards all requests to the "cloned" stream.
WvString is an implementation of a simple and efficient printable-string class.
Based on (and interchangeable with) struct timeval.