X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=plugins%2Fsamples%2FHelloWorld.c;h=01275aa35778cf165e32a03c4075d7d987206f8e;hb=dde70b62b09f49ad672c104a3f81714bf11047be;hp=619c075ac6c33ad21ef6bb76943071f9779ed88f;hpb=41c462374fb25fae29f3b4a28eb99fdb639e8547;p=src%2Fapp-framework-binder.git
diff --git a/plugins/samples/HelloWorld.c b/plugins/samples/HelloWorld.c
index 619c075a..01275aa3 100644
--- a/plugins/samples/HelloWorld.c
+++ b/plugins/samples/HelloWorld.c
@@ -15,35 +15,40 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+#define _GNU_SOURCE
+#include
+#include
#include "local-def.h"
+#include "afb-req-itf.h"
-STATIC json_object* pingSample (AFB_request *request) {
- static pingcount = 0;
- json_object *response;
+static json_object* ping (AFB_request *request, json_object *jresp) {
+ static int pingcount = 0;
char query [512];
- int len;
+ size_t len;
// request all query key/value
len = getQueryAll (request, query, sizeof(query));
if (len == 0) strcpy (query,"NoSearchQueryList");
- // check if we have some post data
- if (request->post == NULL) request->post->data="NoData";
-
// return response to caller
- response = jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon %d query={%s} PostData: \'%s\' ", pingcount++, query, request->post);
+// response = jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon %d query={%s}", pingcount++, query);
+ afb_req_success_f(*request->areq, jresp, "Ping Binder Daemon %d query={%s}", pingcount++, query);
if (verbose) fprintf(stderr, "%d: \n", pingcount);
- return (response);
+ return jresp;
}
-STATIC json_object* pingFail (AFB_request *request) {
- return NULL;
+static json_object* pingSample (AFB_request *request) {
+ return ping(request, json_object_new_string ("Some String"));
}
-STATIC json_object* pingBug (AFB_request *request) {
+static json_object* pingFail (AFB_request *request) {
+ return ping(request, NULL);
+}
+
+static json_object* pingBug (AFB_request *request) {
int a,b,c;
fprintf (stderr, "Use --timeout=10 to trap error\n");
@@ -57,7 +62,7 @@ STATIC json_object* pingBug (AFB_request *request) {
// For samples https://linuxprograms.wordpress.com/2010/05/20/json-c-libjson-tutorial/
-STATIC json_object* pingJson (AFB_session *session, AFB_request *request) {
+static json_object* pingJson (AFB_request *request) {
json_object *jresp, *embed;
jresp = json_object_new_object();
@@ -69,12 +74,13 @@ STATIC json_object* pingJson (AFB_session *session, AFB_request *request) {
json_object_object_add(embed, "subObjInt", json_object_new_int (5678));
json_object_object_add(jresp,"eobj", embed);
-
- return jresp;
-}
+ return ping(request, jresp);
+}
-STATIC AFB_restapi pluginApis[]= {
+// NOTE: this sample does not use session to keep test a basic as possible
+// in real application most APIs should be protected with AFB_SESSION_CHECK
+static AFB_restapi pluginApis[]= {
{"ping" , AFB_SESSION_NONE, (AFB_apiCB)pingSample , "Ping Application Framework"},
{"pingnull" , AFB_SESSION_NONE, (AFB_apiCB)pingFail , "Return NULL"},
{"pingbug" , AFB_SESSION_NONE, (AFB_apiCB)pingBug , "Do a Memory Violation"},
@@ -82,12 +88,13 @@ STATIC AFB_restapi pluginApis[]= {
{NULL}
};
+static const AFB_plugin plugin = {
+ .type = AFB_PLUGIN_JSON,
+ .info = "Minimal Hello World Sample",
+ .prefix = "hello",
+ .apis = pluginApis
+};
-PUBLIC AFB_plugin *helloWorldRegister () {
- AFB_plugin *plugin = malloc (sizeof (AFB_plugin));
- plugin->type = AFB_PLUGIN_JSON;
- plugin->info = "Application Framework Binder Service";
- plugin->prefix= "dbus";
- plugin->apis = pluginApis;
- return (plugin);
-};
\ No newline at end of file
+const AFB_plugin *pluginRegister () {
+ return &plugin;
+};