90fa3b506765823a0c63d0aea8fe102919859a1b
[src/app-framework-binder.git] / src / dbus-api.c
1 /*
2  * Copyright (C) 2015 "IoT.bzh"
3  * Author "Fulup Ar Foll"
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "local-def.h"
21
22 STATIC json_object* pingSample (AFB_session *session, AFB_request *request, void* handle) {
23     static pingcount = 0;
24     json_object *response;
25     char query [512];
26     int len;
27
28     // request all query key/value
29     len = getQueryAll (request, query, sizeof(query));
30     if (len == 0) strcpy (query,"NoSearchQueryList");
31     
32     // check if we have some post data
33     if (request->post == NULL)  request->post="NoData";  
34         
35     // return response to caller
36     response = jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon %d query={%s} PostData: \'%s\' ", pingcount++, query, request->post);
37     
38     if (verbose) fprintf(stderr, "%d: \n", pingcount);
39     return (response);
40 }
41
42 STATIC json_object* pingFail (AFB_session *session, AFB_request *request, void* handle) {
43     return NULL;
44 }
45
46 STATIC json_object* pingBug (AFB_session *session, AFB_request *request, void* handle) {
47     int a,b,c;
48     
49     fprintf (stderr, "Use --timeout=10 to trap error\n");
50     b=4;
51     c=0;
52     a=b/c;
53     
54     // should never return
55     return NULL;
56 }
57
58 STATIC struct {
59     void * somedata;
60 } handle;
61
62
63 STATIC  AFB_restapi pluginApis[]= {
64   {"ping"     , (AFB_apiCB)pingSample , "Ping Application Framework",NULL},
65   {"pingnull" , (AFB_apiCB)pingFail   , "Return NULL", NULL},
66   {"pingbug"  , (AFB_apiCB)pingBug     , "Do a Memory Violation", NULL},
67   {"ctx-store", (AFB_apiCB)pingSample , "Verbose Mode", NULL},
68   {"ctx-load" , (AFB_apiCB)pingSample , "Verbose Mode", NULL},
69   {0,0,0}
70 };
71
72
73 PUBLIC AFB_plugin *dbusRegister (AFB_session *session) {
74     AFB_plugin *plugin = malloc (sizeof (AFB_plugin));
75     plugin->type  = AFB_PLUGIN;
76     plugin->info  = "Application Framework Binder Service";
77     plugin->prefix= "dbus";        
78     plugin->apis  = pluginApis;
79     
80     return (plugin);
81 };