service_discovery
Client.hpp
Go to the documentation of this file.
1 #ifndef _SERVICE_DISCOVERY_AVAHICLIENT_H_
2 #define _SERVICE_DISCOVERY_AVAHICLIENT_H_
3 
4 #define DEFAULT_THREAD_POLL
5 
6 #ifdef DEFAULT_THREAD_POLL
7 #define DEFAULT_POLL ThreadPoll
8 #else
9 #define DEFAULT_POLL SimplePoll
10 #endif
11 
12 #include <avahi-client/client.h>
13 #include <sigc++/sigc++.h>
14 
15 #include <string>
16 #include <iostream>
17 #include <cassert>
18 #include <vector>
19 
20 #include <avahi-common/error.h>
21 #include <avahi-common/thread-watch.h>
22 #include <base-logging/Singleton.hpp>
23 
24 namespace servicediscovery {
25 namespace avahi {
26 
34 {
35 public:
36  // Client events
38 
39  // Event structure
40  struct Event
41  {
43  };
44 
45  virtual ~ClientObserver() {}
46 
50  virtual void update(const Event& event) = 0;
51 
56  virtual void stop() = 0;
57 };
58 
64 class Client : public base::Singleton<Client>
65 {
66  friend class base::Singleton<Client>;
67  friend class UniqueClientLock;
68 
69 
70 protected:
74  Client();
75 
76 private:
77  // Internal modes in order to handle reconnection to the avahi-daemon
78  enum Mode { INIT, NORMAL, RECOVERY };
79 
83  static AvahiClient* msAvahiClient;
84 
89  static AvahiThreadedPoll* msPoll;
90 
95  std::vector<ClientObserver*> msObservers;
96 
100  Mode mMode;
101 
105  static void stateUpdateCallback(AvahiClient* client, AvahiClientState state, void* userdata);
106 
111  void start(bool runningDaemonRequired);
112 
116  void cleanup();
117 
118 public:
119  virtual ~Client();
120 
125  static AvahiClient* getAvahiClient();
126 
131  static AvahiClientState getAvahiClientState();
132 
136  void addObserver(ClientObserver* clientObserver);
137 
141  void removeObserver(ClientObserver* clientObserver);
142 
143 protected:
144  static void lock();
145 
146  static void unlock();
147 };
148 
154 {
155  public:
160 
164  ~UniqueClientLock();
165 };
166 
167 } // end namespace avahi
168 } // end namespace servicediscovery
169 #endif /* _SERVICE_DISCOVERY_AVAHICLIENT_H_ */
Client represent a wrapper to access the avahi_client (a singleton). Every avahi program must set up ...
Definition: Client.hpp:64
Definition: Client.cpp:7
EventType type
Definition: Client.hpp:42
virtual void update(const Event &event)=0
EventType
Definition: Client.hpp:37
virtual ~ClientObserver()
Definition: Client.hpp:45