00001
00011 #include <xmlrpc-c/base.h>
00012 #include <xmlrpc-c/client.h>
00013 #include <xmlrpc-c/server.h>
00014 #include <xmlrpc-c/server_abyss.h>
00015 #include <sys/types.h>
00016 #include <sys/stat.h>
00017 #include <unistd.h>
00018
00019 #include "xrpc.h"
00020
00021
00022 #define SZ_NAME 256
00023 #define SZ_LINE 256
00024 #define SZ_SECRET 64
00025 #define SZ_DESC 8192
00026 #define SZ_URL 1024
00027 #define SZ_CMD 1024
00028 #define SZ_SBUF 65536
00029 #define SZ_RESSTR 1024
00031 #define DEF_PORT 9876
00032 #define DEF_TIMEOUT "15"
00034 #define MAX_SAMPS 16
00035 #define MAX_HUBS 16
00036 #define MAX_MDATTRS 32
00037 #define MAX_SUBS 256
00038 #define MAX_CLIENTS 32
00039 #define MAX_ROWS 256
00041 #define SAMP_ERR -1
00042 #define SAMP_PENDING 0
00043 #define SAMP_OK 1
00045 #define SAMP_CBR 0
00046 #define SAMP_CBV 1
00048 #define SAMP_SYNCH 0
00049 #define SAMP_ASYNCH 1
00050 #define SAMP_NOTIFY 2
00052 #define SAMP_INT TY_INT
00053 #define SAMP_DOUBLE TY_DOUBLE
00054 #define SAMP_BOOL TY_BOOL
00055 #define SAMP_STRING TY_STRING
00056 #define SAMP_DATETIME TY_DATETIME
00057 #define SAMP_SAMPRUCT TY_STRUCT
00058 #define SAMP_ARRAY TY_ARRAY
00059
00060 #define SAMP_TRACE 0
00066 #define HUB_SHUTDOWN 0
00067 #define HUB_REGISTER 1
00068 #define HUB_UNREGISTER 2
00069 #define HUB_SUBSCRIPTIONS 3
00070 #define HUB_METADATA 4
00071 #define HUB_DISCONNECT 5
00074 #define LEN_DESC 32768
00077 typedef long handle_t;
00078 typedef int Map;
00079 typedef int List;
00080 typedef int Msg;
00081 typedef int Param;
00082 typedef char *String;
00088 typedef struct {
00089 char name[SZ_LINE];
00090 char desc[SZ_DESC];
00091 char iconURL[SZ_URL];
00092 char docURL[SZ_URL];
00094 char *descHTML;
00096 int nkeys;
00097 char *aKey[MAX_MDATTRS];
00098 char *aVal[MAX_MDATTRS];
00099 } appMD, *appMDP;
00100
00101
00105 #define MAX_PARAMS 32
00106
00107 #ifdef ZZMSG_MAP
00108 typedef struct {
00109 char keyw[SZ_LINE];
00110 Map val[SZ_LINE];
00111 } zzParam, *zzParamP;
00112
00113 typedef struct {
00114 char mtype[SZ_LINE];
00115 char tag[SZ_LINE];
00116 Param params[MAX_PARAMS];
00117 } zzMsg, *zzMsgP;
00118 #endif
00119
00120
00124 typedef struct {
00125 char mtype[SZ_LINE];
00126 int (*userFunc)(void *p);
00128 int (*sampFunc)(char *sid, char *sender, char *msgid, Map map);
00129 } Subs, *SubsP;
00130
00131
00135 typedef struct {
00136 char pubId[SZ_NAME];
00137 char name[SZ_NAME];
00138 } Client, *ClientP;
00139
00140
00145 typedef struct {
00146 char appName[SZ_LINE];
00147 char appVer[SZ_LINE];
00148 char description[SZ_LINE];
00150 appMD meta;
00152 char secret[SZ_SECRET];
00153 char url[SZ_URL];
00154 char version[SZ_NAME];
00156 int id;
00158 char appId[SZ_NAME];
00159 char privateKey[SZ_LINE];
00160 char hubId[SZ_LINE];
00161 char selfId[SZ_LINE];
00162 char timeout[SZ_NAME];
00164 void *samp;
00165 } Hub, *HubP;
00166
00167
00173 typedef struct {
00174 char appName[SZ_NAME];
00175 char appVer[SZ_LINE];
00176 char description[SZ_NAME];
00178 char errortxt[SZ_LINE];
00180 appMD meta;
00182 pthread_t svrThread;
00185 int (*defaultUserFunc)(char *sender, char *msgid, Map map);
00186
00187 Subs subs[MAX_SUBS];
00188 int nsubs;
00190 Client clients[MAX_CLIENTS];
00191 int nclients;
00193 int serverTid;
00194 int serverPort;
00196 Hub *hub;
00197 handle_t hubHandle;
00198 int hubThreadID;
00200 int active;
00201 int msgMode;
00202 int handlerMode;
00204 FILE *logfd;
00205 int debug;
00206 int trace;
00207 } Samp, *SampP;
00208
00209
00210 #define MSG_SYNC 0
00211 #define MSG_ASYNC 1
00212 #define MSG_NOTIFY 2
00213 #define DEF_CALLMODE MSG_ASYNC
00214
00215
00216
00221
00222
00223
00224
00225
00226
00227 handle_t sampInit (String appName, String description);
00228 void samp_Metadata (handle_t handle, String field, String value);
00229 void samp_Subscribe (handle_t handle, String mtype, void *func);
00230 void samp_Unsubscribe (handle_t handle, String mtype);
00231 int sampStartup (handle_t handle);
00232 int sampShutdown (handle_t handle);
00233 void sampClose (handle_t handle);
00234
00235 void samp_setSyncMode (handle_t handle);
00236 void samp_setASyncMode (handle_t handle);
00237 void samp_setNotifyMode (handle_t handle);
00238 void samp_setCallByRef (handle_t handle);
00239 void samp_setCallMode (handle_t handle, int mode);
00240
00241 void samp_setReplyCallback (handle_t handle, int *func);
00242 void samp_setResponseCallback (handle_t handle, int *func);
00243 void samp_setTimeout (handle_t handle, int timeout);
00244 void samp_setAppName (handle_t handle, String name);
00245 void samp_setAppVersion (handle_t handle, String version);
00246
00247 void samp_defaultReplyHandler (handle_t handle);
00248 void samp_deaultfResponseHandler (handle_t handle);
00249 int samp_replyStatus (handle_t handle);
00250
00251 int samp_mapClients (handle_t handle);
00252 int samp_listClients (handle_t handle);
00253 int samp_addClient (handle_t handle, String name, String id);
00254 int samp_removeClient (handle_t handle, String id);
00255
00256 Map samp_getOKMap (void);
00257 Map samp_getNullMap (void);
00258
00259
00260
00261
00262 int samp_Register (handle_t handle);
00263 int samp_UnRegister (handle_t handle);
00264 int samp_DeclareMetadata (handle_t handle);
00265 int samp_Ping (handle_t handle, String appName);
00266 Map samp_GetMetadata (handle_t handle, String pubId);
00267 int samp_DeclareSubscriptions (handle_t handle);
00268 Map samp_GetSubscriptions (handle_t handle, String pubId);
00269 List samp_GetRegisteredClients (handle_t handle);
00270 List samp_GetSubscribedClients (handle_t handle, String mtype);
00271
00272
00273
00274
00275 int samp_tableLoadVOTable (handle_t handle, String recip, String url,
00276 String tableId, String name);
00277 int samp_tableLoadFITS (handle_t handle, String recip, String url,
00278 String tableId, String name);
00279 int samp_imageLoadFITS (handle_t handle, String recip, String url,
00280 String imageId, String name);
00281
00282 int samp_tableHighlightRow (handle_t handle, String recip, String tableId,
00283 String url, int row);
00284 int samp_tableSelectRowList (handle_t handle, String recip, String tableId,
00285 String url, int rows[]);
00286 int samp_coordPointAtSky (handle_t handle, String recip,
00287 float ra, float dec);
00288 int samp_specLoadSSAGeneric (handle_t handle, String recip, String url,
00289 Map meta, String spectrumId, String name);
00290
00291 int samp_cmdExec (handle_t handle, String recip, String cmd);
00292 char *samp_envGet (handle_t handle, String recip, String name);
00293 int samp_envSet (handle_t handle, String recip, String name, String value);
00294 char *samp_paramGet (handle_t handle, String recip, String name);
00295 int samp_paramSet(handle_t handle, String recip, String name, String value);
00296 int samp_bibLoad (handle_t handle, String recip, String bibcode);
00297 int samp_resourceLoad (handle_t handle, String recip, String type,
00298 String name, Map resMap);
00299
00300 int samp_sendMsg (handle_t handle, String recip, Map msg);
00301
00302
00303
00304
00305
00306 void samp_notify (handle_t handle, String recipId, Map msg);
00307 List samp_notifyAll (handle_t handle, Map msg);
00308 String samp_call (handle_t handle, String recipId, String tag, Map msg);
00309 int samp_callAll (handle_t handle, String msg_tag, Map msg);
00310 int samp_callAndWait (handle_t handle, String recipId, String msg_tag,
00311 Map msg);
00312 int samp_Reply (handle_t handle, String msg_id, Map resp);
00313
00314 String samp_clientName (handle_t handle, String pubId);
00315 int samp_setErr (handle_t handle, Map resp);
00316 String samp_getErr (handle_t handle);
00317
00318
00319
00320
00321 int samp_receiveCall (void *data);
00322 int samp_receiveNotification (void *data);
00323 int samp_receiveResponse (void *data);
00324
00325
00326
00327
00328 void samp_setUserHandler (handle_t handle, String mtype, void *func);
00329 void samp_setSampHandler (handle_t handle, String mtype, void *func);
00330 void *samp_getUserHandler (String mtype);
00331 void *samp_getSampHandler (String mtype);
00332 void samp_execUserHandler (String mtype, String sender,
00333 String msg_id, Map params);
00334
00335 int samp_PingHandler (String sender, String msg_id, Map msg_map);
00336 int samp_StatusHandler (String sender, String msg_id, Map msg_map);
00337 int samp_imLoadHandler (String sender, String msg_id, Map msg_map);
00338
00339 int samp_tbLoadHandler (String sender, String msg_id, Map msg_map);
00340 int samp_tbHighlightHandler (String sender, String msg_id, Map msg_map);
00341 int samp_tbSelectHandler (String sender, String msg_id, Map msg_map);
00342 int samp_pointAtHandler (String sender, String msg_id, Map msg_map);
00343 int samp_specLoadHandler (String sender, String msg_id, Map msg_map);
00344 int samp_cmdExecHandler (String sender, String msg_id, Map msg_map);
00345 int samp_envGetHandler (String sender, String msg_id, Map msg_map);
00346 int samp_envSetHandler (String sender, String msg_id, Map msg_map);
00347 int samp_paramGetHandler (String sender, String msg_id, Map msg_map);
00348 int samp_paramSetHandler (String sender, String msg_id, Map msg_map);
00349
00350 int samp_bibcodeHandler (String sender, String msg_id, Map msg_map);
00351 int samp_resLoadHandler (String sender, String msg_id, Map msg_map);
00352
00353 void samp_printMessage (String mtype, String sender, String msg_id,
00354 Map params);
00355
00356 void samp_printMap (String name, Map map);
00357 int samp_nullResponse (void *data);
00358 int samp_testEcho (void *data);
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 handle_t samp_hubOpen (Samp *samp);
00369 int samp_hubClose (handle_t handle);
00370 List samp_getAvailableHubs (handle_t handle);
00371 char *samp_getActiveHubName (handle_t handle);
00372 int samp_getActiveHub (handle_t handle);
00373 int samp_hubInit (handle_t samp, char *appName, char *descr);
00374
00375 int samp_processHubEvent (String mtype, Map params);
00376 int samp_hubEvent (String mtype);
00377
00378 int samp_hubRegister (Hub *hub);
00379 int samp_hubUnRegister (Hub *hub);
00380 int samp_hubSendShutdown (Hub *hub);
00381 int samp_hubSetXmlrpcCallback (Hub *hub);
00382 int samp_hubPing (Hub *hub);
00383 int samp_hubDeclareMetadata (Hub *hub);
00384 int samp_hubDeclareSubscriptions (Hub *hub);
00385
00386
00387
00388
00389 handle_t samp_newList ();
00390 void samp_freeList (List list);
00391 int samp_listLen (List list);
00392
00393 void samp_setStringInList (List list, char *value);
00394 void samp_setMapInList (List list, Map map);
00395 void samp_setListInList (List list1, List list2);
00396 void samp_setIntInList (List list, int value);
00397 void samp_setFloatInList (List list, float value);
00398
00399 char *samp_getStringFromList (List list, int index);
00400 Map samp_getMapFromList (List list, int index);
00401 List samp_getListFromList (List list, int index);
00402 int samp_getIntFromList (List list, int index);
00403 float samp_getFloatFromList (List list, int index);
00404
00405
00406
00407
00408 handle_t samp_newMap (void);
00409 void samp_freeMap (Map map);
00410
00411 void samp_setStringInMap (Map map, char *key, char *value);
00412 void samp_setMapInMap (Map map1, char *key, Map map2);
00413 void samp_setListInMap (Map map, char *key, List list);
00414 void samp_setIntInMap (Map map, char *key, int value);
00415 void samp_setFloatInMap (Map map, char *key, float value);
00416
00417 char *samp_getStringFromMap (Map map, char *key);
00418 Map samp_getMapFromMap (Map map, char *key);
00419 List samp_getListFromMap (Map map, char *key);
00420 int samp_getIntFromMap (Map map, char *key);
00421 float samp_getFloatFromMap (Map map, char *key);
00422
00423
00424
00425
00426 Msg samp_newMsg (void);
00427 void samp_freeMsg (Msg msg);
00428 void samp_msgMType (Msg msg, String mtype);
00429 void samp_msgParam (Msg msg, Param param);
00430 char *samp_msgTag (void);
00431
00432
00433
00434
00435 Param samp_newParam (void);
00436 void samp_freeParam (Param param);
00437 Param samp_paramInit (Msg msg);
00438 void samp_addStringParam (Msg msg, char *keyw, String val);
00439 void samp_addMapParam (Msg msg, char *keyw, Map val);
00440 void samp_addListParam (Msg msg, char *keyw, List val);
00441 void samp_addIntParam (Msg msg, char *keyw, int val);
00442 void samp_addFloatParam (Msg msg, char *keyw, float val);
00443 int samp_paramLen (Msg msg);
00444
00445
00446
00447
00448 void sampLog (handle_t handle, char *format, ...);
00449 void sampTrace (handle_t handle, char *format, ...);
00450
00451
00452
00453
00454 handle_t samp_newHandle (void *ptr);
00455 void samp_freeHandle (handle_t handle);
00456
00457 handle_t samp_P2H (void *ptr);
00458 void *samp_H2P (handle_t handle);
00459
00460 char *samp_app2id (handle_t handle, char *appName);
00461 char *samp_id2app (handle_t handle, char *pubId);
00462
00463 int samp_serverPort (void);