WvStreams
wvdbusserver.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 2004-2006 Net Integration Technologies, Inc.
00004  *
00005  * Pathfinder Software:
00006  *   Copyright (C) 2007, Carillon Information Security Inc.
00007  *
00008  * This library is licensed under the LGPL, please read LICENSE for details.
00009  * 
00010  * This class represents a dbus server, which may have multiple connections
00011  * at the same time. It is intended purely for unit testing and debugging
00012  * purposes and by no means should be used in production code (use the
00013  * dbus daemon for that).
00014  * 
00015  */ 
00016 #ifndef __WVDBUSSERVER_H
00017 #define __WVDBUSSERVER_H
00018 
00019 #include "wvlistener.h"
00020 #include "wvhashtable.h"
00021 #include "wvlog.h"
00022 #include "wvistreamlist.h"
00023 #include <stdint.h>
00024 
00025 class WvDBusMsg;
00026 class WvDBusConn;
00027 DeclareWvList(WvDBusConn);
00028 
00029 
00030 class WvDBusServer : public WvIStreamList
00031 {
00032     WvIStreamList listeners;
00033 public:
00034     /* 
00035      * Constructs a new DBus server.  You must then call listen() to
00036      * actually listen for new connections.
00037      */
00038     WvDBusServer();
00039     
00043     WvDBusServer(WvDBusServer &c);
00044     
00048     virtual ~WvDBusServer();
00049     
00059     void listen(WvStringParm moniker);
00060 
00061     virtual bool isok() const;
00062     virtual int geterr() const;
00063     
00068     void register_name(WvStringParm name, WvDBusConn *conn);
00069     
00073     void unregister_name(WvStringParm name, WvDBusConn *conn);
00074     
00080     void unregister_conn(WvDBusConn *conn);
00081     
00086     WvString get_addr();
00087 
00088 private:
00089     WvLog log;
00090     WvDBusConnList all_conns;
00091     std::map<WvString,WvDBusConn*> name_to_conn;
00092     
00093     void new_connection_cb(IWvStream *s);
00094     void conn_closed(WvStream &s);
00095         
00096     bool do_server_msg(WvDBusConn &conn, WvDBusMsg &msg);
00097     bool do_bridge_msg(WvDBusConn &conn, WvDBusMsg &msg);
00098     bool do_broadcast_msg(WvDBusConn &conn, WvDBusMsg &msg);
00099     bool do_gaveup_msg(WvDBusConn &conn, WvDBusMsg &msg);
00100 };
00101 
00102 #endif // __WVDBUSSERVER_H