00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _DISCOVERY_SERVICE_H_
00036 #define _DISCOVERY_SERVICE_H_
00037
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041
00042
00043 enum DiscoveryError {
00044 RegistryFull, AlreadyRegistered, BadORB,
00045 InvalidObject, NoNode, NoNetwork, NoCapability
00046 };
00047
00048
00049 #ifndef IDL
00050
00051 #define DISCOVERY_PORT 2999
00052 #define MCAST_ADDR_IPv6 "FF18::178"
00053 #define MCAST_ADDR_IPv4 "224.0.0.178"
00054
00055 #ifdef IPV6
00056 #define MCAST_ADDR MCAST_ADDR_IPv6
00057 #else
00058 #define MCAST_ADDR MCAST_ADDR_IPv4
00059 #endif
00060
00061
00062
00063 #define TX_TIMEOUT 12 // max ms between hdr & body
00064 #define RETRY_ITVL 4 // tx retry buffer time (ms)
00065 #define EMPTY_TIMEOUT 1000 // ms block on recv
00066 #define DISCOVERY_HEADER_SIZE 8
00067
00068
00069 #define TOO_SMALL -100
00070 #define REGISTRY_FULL (0 - RegistryFull)
00071 #define ALREADY_REGISTERED (0 - AlreadyRegistered)
00072 #define INVALID_OBJECT (0 - InvalidObject)
00073 #define NO_NODE (0 - NoNode)
00074 #define NO_NETWORK (0 - NoNetwork)
00075 #define NO_CAPABILITY (0 - NoCapability)
00076
00077
00079
00080
00081 #include <stdint.h>
00082 #include "sense_impl.h"
00083
00084
00085 #define OBJ_REF_SIZE 2048
00086
00087 typedef struct _obj_ref {
00088 uint32_t id;
00089 uint8_t type;
00090 char ior[OBJ_REF_SIZE];
00091 bool_t valid;
00092 } object_reference_t;
00093
00094
00096
00097
00098 #define ANNOUNCE_SIZE 5
00099
00100 typedef struct _announce {
00101 uint32_t nodeIdent;
00102 uint8_t hLevel;
00103 } Announce;
00104
00105
00106 #define REPORT_SIZE 6
00107
00108 typedef struct _report {
00109 uint32_t nodeIdent;
00110 uint8_t hLevel;
00111 uint8_t cType;
00112 } Report;
00113
00114
00115 #define REQUIRE_SIZE 10
00116
00117 typedef struct _require {
00118 uint32_t nodeIdent;
00119 uint8_t hLevel;
00120 uint8_t cType;
00121 uint32_t targetIdent;
00122 } Require;
00123
00124
00125 typedef struct _share {
00126 uint32_t nodeIdent;
00127 uint8_t hLevel;
00128 uint8_t cType;
00129 unsigned char ior[OBJ_REF_SIZE + 1];
00130 } Share;
00131
00132
00133 void announceHeader(uint8_t *hdr);
00134 void reportHeader(uint8_t *hdr);
00135 void requireHeader(uint8_t *hdr);
00136 void shareHeader(uint8_t *hdr, Share *shr);
00137
00138 void loadAnnounce(uint8_t *msg, Announce *ann);
00139 void loadReport(uint8_t *msg, Report *rpt);
00140 void loadRequire(uint8_t *msg, Require *req);
00141 void loadShare(uint8_t *msg, Share *shr);
00142
00143
00144 typedef struct _discoverhdr {
00145 bool_t little_endian;
00146 uint8_t announceType;
00147 size_t announceSize;
00148 } DiscoverHeader;
00149
00150 typedef struct _discovermsg {
00151 uint32_t nodeIdent;
00152 uint8_t hLevel;
00153 uint8_t cType;
00154 uint32_t targetIdent;
00155 unsigned char ior[OBJ_REF_SIZE + 1];
00156 } DiscoverMessage;
00157
00158
00159 int parseDiscoverHeader(DiscoverHeader *hdr, unsigned char *bytes);
00160 int parseDiscoverMessage(DiscoverMessage *dm, DiscoverHeader *hdr,
00161 unsigned char *bytes);
00162
00163
00165
00166
00167 uint8_t self_level();
00168 uint32_t self_identifier();
00169 int self_capabilities(uint8_t *caps, size_t *size);
00170 int self_register_object(uint8_t capability, object_reference_t *obj,
00171 bool_t override);
00172
00173
00174 bool_t descendants_findNode(uint32_t id);
00175 int descendants_queryNetwork(object_reference_t *objrefs, size_t *num,
00176 uint8_t capability);
00177 int descendants_queryNode(object_reference_t *objref,
00178 uint32_t id, uint8_t capability);
00179 int descendants_capabilities(uint8_t *caps, size_t *num);
00180 int descendants_nodes(uint32_t *ids, size_t *num);
00181
00182
00183 bool_t siblings_findNode(uint32_t id);
00184 int siblings_queryNetwork(object_reference_t *objrefs, size_t *num,
00185 uint8_t capability);
00186 int siblings_queryNode(object_reference_t *objref,
00187 uint32_t id, uint8_t capability);
00188 int siblings_capabilities(uint8_t *caps, size_t *num);
00189 int siblings_nodes(uint32_t *ids, size_t *num);
00190
00191
00192 bool_t ancestors_findNode(uint32_t id);
00193 int ancestors_nodes(uint32_t *ids, size_t *num);
00194
00195
00196 bool_t family_findNode(uint32_t id);
00197 int family_queryNetwork(object_reference_t *objrefs, size_t *num,
00198 uint8_t capability);
00199 int family_queryNode(object_reference_t *objref,
00200 uint32_t id, uint8_t capability);
00201
00202
00204
00205
00206 typedef struct _disc_args {
00207 uint32_t node_id;
00208 uint8_t h_level;
00209 uint32_t service_port;
00210 } discovery_args_t;
00211
00212 void *discovery_service(void *args);
00213
00214
00215 #endif // IDL
00216
00217 #ifdef __cplusplus
00218 }
00219 #endif
00220
00221 #endif // _DISCOVERY_SERVICE_H_