00001 #include <stdio.h>
00002 #include <stdbool.h>
00003 #include <glib.h>
00004 #include <json.h>
00005
00006 #ifdef WIN32
00007 #define WIN32_LEAN_AND_MEAN
00008 #define NOGDI
00009 #include <winsock2.h>
00010 #else
00011 #include <sys/select.h>
00012 #endif
00013
00014 #include <lunaservice-errors.h>
00015
00016 #ifndef _LUNASERVICE_H_
00017 #define _LUNASERVICE_H_
00018
00019 #ifdef __cplusplus
00020 extern "C" {
00021 #endif
00022
00219 typedef unsigned long LSMessageToken;
00220
00228 #define LSMESSAGE_TOKEN_INVALID 0
00229
00234 struct LSError {
00235 int error_code;
00236 char *message;
00238 const char *file;
00239 int line;
00240 const char *func;
00242 void *padding;
00243 unsigned long magic;
00244 };
00245
00246 typedef struct LSError LSError;
00247
00251 typedef struct LSHandle LSHandle;
00252
00256 typedef struct LSPalmService LSPalmService;
00257
00261 typedef struct LSMessage LSMessage;
00262
00278 typedef bool (*LSMethodFunction) (LSHandle *sh, LSMessage *msg, void *category_context);
00279
00280
00290 typedef bool (*LSPropertyGetFunction) (LSHandle *sh, LSMessage *msg, void *category_context);
00291
00301 typedef bool (*LSPropertySetFunction) (LSHandle *sh, LSMessage *msg, void *category_context);
00302
00306 typedef enum {
00307 LUNA_METHOD_FLAG_DEPRECATED = (1 << 0),
00308 } LSMethodFlags;
00309
00313 typedef enum {
00314 LUNA_SIGNAL_FLAG_DEPRECATED = (1 << 0),
00315 } LSSignalFlags;
00316
00320 typedef enum {
00321 LUNA_PROPERTY_FLAG_DEPRECATED = (1 << 0),
00322 } LSPropertyFlags;
00323
00324 typedef struct {
00325 const char *name;
00326 LSMethodFunction function;
00327 LSMethodFlags flags;
00328 } LSMethod;
00329
00330 typedef struct {
00331 const char *name;
00332 LSSignalFlags flags;
00333 } LSSignal;
00334
00335 typedef struct {
00336 const char *name;
00337 const char *type;
00338 LSPropertyGetFunction get;
00339 LSPropertySetFunction set;
00340 LSPropertyFlags flags;
00341 } LSProperty;
00342
00343
00344
00345 bool LSErrorInit(LSError *error);
00346 void LSErrorFree(LSError *error);
00347
00348 bool LSErrorIsSet(LSError *lserror);
00349
00350 void LSErrorPrint(LSError *lserror, FILE *out);
00351
00352
00353
00354 bool LSRegister(const char *name, LSHandle **sh,
00355 LSError *lserror);
00356
00357 bool LSRegisterPubPriv(const char *name, LSHandle **sh,
00358 bool public_bus,
00359 LSError *lserror);
00360
00361 typedef void (*LSDisconnectHandler)(LSHandle *sh, void *user_data);
00362 bool LSSetDisconnectHandler(LSHandle *sh, LSDisconnectHandler disconnect_handler,
00363 void *user_data, LSError *lserror);
00364
00365 bool LSRegisterCategory(LSHandle *sh, const char *category,
00366 LSMethod *methods,
00367 LSSignal *signals,
00368 LSProperty *properties, LSError *lserror);
00369
00370 bool LSRegisterCategoryAppend(LSHandle *sh, const char *category,
00371 LSMethod *methods,
00372 LSSignal *signals,
00373 LSError *lserror);
00374
00375 bool LSCategorySetData(LSHandle *sh, const char *category,
00376 void *user_data, LSError *lserror);
00377
00378 bool LSUnregister(LSHandle *service, LSError *lserror);
00379
00380 const char * LSHandleGetName(LSHandle *sh);
00381
00382
00383
00384 bool LSRegisterPalmService(const char *name,
00385 LSPalmService **ret_palm_service,
00386 LSError *lserror);
00387
00388 bool LSUnregisterPalmService(LSPalmService *psh, LSError *lserror);
00389
00390 bool LSPalmServiceRegisterCategory(LSPalmService *psh,
00391 const char *category,
00392 LSMethod *methods_public, LSMethod *methods_private,
00393 LSSignal *signals, void *category_user_data, LSError *lserror);
00394
00395 LSHandle * LSPalmServiceGetPrivateConnection(LSPalmService *psh);
00396 LSHandle * LSPalmServiceGetPublicConnection(LSPalmService *psh);
00397
00398
00399
00400 LSHandle * LSMessageGetConnection(LSMessage *message);
00401 bool LSMessageIsPublic(LSPalmService *psh, LSMessage *message);
00402
00403 void LSMessageRef(LSMessage *message);
00404 void LSMessageUnref(LSMessage *message);
00405
00406 bool LSMessagePrint(LSMessage *lmsg, FILE *out);
00407
00408 const char * LSMessageGetUniqueToken(LSMessage *message);
00409 const char * LSMessageGetKind(LSMessage *message);
00410
00411 const char * LSMessageGetApplicationID(LSMessage *message);
00412
00413 const char * LSMessageGetSender(LSMessage *message);
00414 const char * LSMessageGetCategory(LSMessage *message);
00415 const char * LSMessageGetMethod(LSMessage *message);
00416
00417 const char * LSMessageGetPayload(LSMessage *message);
00418
00419 json_t * LSMessageGetPayloadJSON(LSMessage *message);
00420
00421 bool LSMessageIsSubscription(LSMessage *lsmgs);
00422
00423 LSMessageToken LSMessageGetToken(LSMessage *call);
00424 LSMessageToken LSMessageGetResponseToken(LSMessage *reply);
00425
00426 bool LSMessageRespond(LSMessage *message, const char *reply_payload,
00427 LSError *lserror);
00428
00429 bool LSMessageReply(LSHandle *sh, LSMessage *lsmsg, const char *replyPayload,
00430 LSError *lserror);
00431
00432 bool LSMessageReturn(LSHandle *sh, LSMessage *message, const char *replyPayload,
00433 LSError *error);
00434
00435
00436
00437 bool LSGmainAttach(LSHandle *sh, GMainLoop *mainLoop, LSError *lserror);
00438
00439 bool LSGmainAttachPalmService(LSPalmService *psh,
00440 GMainLoop *mainLoop, LSError *lserror);
00441
00442 bool LSGmainSetPriority(LSHandle *sh, int priority, LSError *lserror);
00443
00444 bool LSGmainSetPriorityPalmService(LSPalmService *psh, int priority, LSError *lserror);
00445
00446
00447
00463 typedef bool (*LSServerStatusFunc) (LSHandle *sh, const char *serviceName,
00464 bool connected,
00465 void *ctx);
00466
00476 typedef bool (*LSFilterFunc) (LSHandle *sh, LSMessage *reply, void *ctx);
00477
00478 bool LSCall(LSHandle *sh, const char *uri, const char *payload,
00479 LSFilterFunc callback, void *user_data,
00480 LSMessageToken *ret_token, LSError *lserror);
00481
00482 bool LSCallOneReply(LSHandle *sh, const char *uri, const char *payload,
00483 LSFilterFunc callback, void *ctx,
00484 LSMessageToken *ret_token, LSError *lserror);
00485
00486 bool LSCallFromApplication(LSHandle *sh, const char *uri, const char *payload,
00487 const char *applicationID,
00488 LSFilterFunc callback, void *ctx,
00489 LSMessageToken *ret_token, LSError *lserror);
00490
00491 bool LSCallFromApplicationOneReply(
00492 LSHandle *sh, const char *uri, const char *payload,
00493 const char *applicationID,
00494 LSFilterFunc callback, void *ctx,
00495 LSMessageToken *ret_token, LSError *lserror);
00496
00497 bool LSCallCancel(LSHandle *sh, LSMessageToken token, LSError *lserror);
00498
00499
00500
00505 typedef struct LSSubscriptionIter LSSubscriptionIter;
00506
00507 bool LSSubscriptionProcess (LSHandle *sh, LSMessage *message, bool *subscribed,
00508 LSError *lserror);
00509
00510 bool LSSubscriptionSetCancelFunction(LSHandle *sh,
00511 LSFilterFunc cancelFunction,
00512 void *ctx, LSError *lserror);
00513
00514 bool LSSubscriptionAdd(LSHandle *sh, const char *key,
00515 LSMessage *message, LSError *lserror);
00516
00517 bool LSSubscriptionAcquire(LSHandle *sh, const char *key,
00518 LSSubscriptionIter **ret_iter, LSError *lserror);
00519
00520 void LSSubscriptionRelease(LSSubscriptionIter *iter);
00521
00522 bool LSSubscriptionHasNext(LSSubscriptionIter *iter);
00523
00524 LSMessage *LSSubscriptionNext(LSSubscriptionIter *iter);
00525
00526 void LSSubscriptionRemove(LSSubscriptionIter *iter);
00527
00528 bool LSSubscriptionReply(LSHandle *sh, const char *key,
00529 const char *payload, LSError *lserror);
00530
00531 bool LSSubscriptionRespond(LSPalmService *psh, const char *key,
00532 const char *payload, LSError *lserror);
00533
00534 bool LSSubscriptionPost(LSHandle *sh, const char *category,
00535 const char *method,
00536 const char *payload, LSError *lserror);
00537
00538
00539
00545 bool LSSignalSend(LSHandle *sh, const char *uri, const char *payload,
00546 LSError *lserror);
00547
00548 bool LSSignalSendNoTypecheck(LSHandle *sh,
00549 const char *uri, const char *payload, LSError *lserror);
00550
00551 bool LSSignalCall(LSHandle *sh,
00552 const char *category, const char *methodName,
00553 LSFilterFunc filterFunc, void *ctx,
00554 LSMessageToken *ret_token,
00555 LSError *lserror);
00556
00557 bool LSSignalCallCancel(LSHandle *sh, LSMessageToken token, LSError *lserror);
00558
00559
00560 bool LSRegisterServerStatus(LSHandle *sh, const char *serviceName,
00561 LSServerStatusFunc func, void *ctx, LSError *lserror);
00562
00563
00564
00565
00566
00567
00568 #ifdef __cplusplus
00569 }
00570 #endif
00571
00572 #endif //_LUNASERVICE_H_