ZeroconfConnector.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __ZEROCONFCONNECTOR_H__
00025 #define __ZEROCONFCONNECTOR_H__
00026
00027 #undef HAVE_AVAHI
00028
00029 #ifdef HAVE_AVAHI
00030
00031 class BootstrapNodeHandle;
00032 class NodeHandle;
00033
00034 #include <omnetpp.h>
00035 #include <oversim_mapset.h>
00036 #include <semaphore.h>
00037
00038 #include <avahi-client/client.h>
00039 #include <avahi-client/lookup.h>
00040 #include <avahi-client/publish.h>
00041
00042 #include <avahi-common/alternative.h>
00043 #include <avahi-common/thread-watch.h>
00044 #include <avahi-common/malloc.h>
00045 #include <avahi-common/error.h>
00046
00047 #define AVAHI_INIT_FAILED 0
00048 #define AVAHI_INIT_SUCCEEDED 1
00049
00050 struct EqualStr
00051 {
00052 bool operator()(const char* s1, const char* s2) const {
00053 return strcmp(s1, s2) == 0;
00054 }
00055 };
00056
00057 typedef std::pair<char *, BootstrapNodeHandle *> LocalNodePair;
00058
00059
00060 typedef UNORDERED_MAP<char *, BootstrapNodeHandle*, HASH_NAMESPACE::hash<char *>,
00061 EqualStr> LocalBNodeSet;
00070 class ZeroconfConnector : public cSimpleModule
00071 {
00072 friend void entry_group_callback(AvahiEntryGroup *, AvahiEntryGroupState, AVAHI_GCC_UNUSED void *);
00073 friend void create_services(AvahiClient *, ZeroconfConnector *);
00074 friend void resolv_callback(AvahiServiceResolver *,
00075 AVAHI_GCC_UNUSED AvahiIfIndex,
00076 AVAHI_GCC_UNUSED AvahiProtocol,
00077 AvahiResolverEvent,
00078 const char *,
00079 const char *,
00080 const char *,
00081 const char *,
00082 const AvahiAddress *,
00083 uint16_t, AvahiStringList *,
00084 AvahiLookupResultFlags,
00085 AVAHI_GCC_UNUSED void*);
00086 friend void browse_callback(AvahiServiceBrowser *,
00087 AvahiIfIndex,
00088 AvahiProtocol,
00089 AvahiBrowserEvent,
00090 const char *,
00091 const char *,
00092 const char *,
00093 AVAHI_GCC_UNUSED AvahiLookupResultFlags,
00094 void *);
00095 friend void client_callback(AvahiClient *,
00096 AvahiClientState,
00097 AVAHI_GCC_UNUSED void *);
00098
00099 public:
00100 ZeroconfConnector();
00101 ~ZeroconfConnector();
00102
00108 int getInitResult();
00109
00118 int insertNode(char *name, BootstrapNodeHandle *node);
00119
00127 int removeNode(char *name);
00128
00134 void announceService(const NodeHandle &node);
00135
00139 void revokeService();
00140
00141
00142
00143
00144
00145
00146 bool isEnabled() { return enabled; };
00147
00148 protected:
00149 virtual void initialize();
00150 virtual void handleMessage(cMessage *msg);
00151
00152 private:
00153 int initResult;
00154
00155 sem_t nodeSetSem;
00156 LocalBNodeSet newSet;
00157
00158 cMessage *pollingTimer;
00159
00160 AvahiClient *client;
00161 AvahiEntryGroup *group;
00162 AvahiThreadedPoll *threadedPoll;
00163
00164 AvahiServiceBrowser *sbMDNS;
00165 AvahiServiceBrowser *sbUDNS;
00166
00167 const char *serviceType;
00168 char *serviceName;
00169 const char *overlayName;
00170 const char *overlayType;
00171
00172 const NodeHandle *thisNode;
00173 bool enabled;
00174 };
00175
00176 #else
00177
00178 #include <NodeHandle.h>
00179
00188 class ZeroconfConnector : public cSimpleModule
00189 {
00190 public:
00191 ZeroconfConnector() {};
00192 ~ZeroconfConnector() {};
00193
00199 void announceService(const NodeHandle &node) {};
00200
00204 void revokeService() {};
00205
00206
00207
00208
00209
00210
00211 bool isEnabled() { return false; };
00212 };
00213 #endif
00214
00215 #endif