improves formatting
[src/app-framework-binder.git] / plugins / afm-main-plugin / afm-main-plugin.c
index 418cc50..2d350df 100644 (file)
@@ -2,18 +2,17 @@
  * Copyright (C) 2015 "IoT.bzh"
  * Author "Fulup Ar Foll"
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 #define _GNU_SOURCE         /* See feature_test_macros(7) */
@@ -76,7 +75,8 @@ static void embed_call_void(struct afb_req request, const char *method)
 {
        struct json_object *obj = jbus_call_sj_sync(jbus, method, "true");
        if (interface->verbosity)
-               fprintf(stderr, "(afm-main-plugin) %s(true) -> %s\n", method, obj ? json_object_to_json_string(obj) : "NULL");
+               fprintf(stderr, "(afm-main-plugin) %s(true) -> %s\n", method,
+                       obj ? json_object_to_json_string(obj) : "NULL");
        if (obj == NULL) {
                afb_req_fail(request, "failed", "framework daemon failure");
                return;
@@ -104,7 +104,8 @@ static void call_appid(struct afb_req request, const char *method)
        }
        obj = jbus_call_sj_sync(jbus, method, sid);
        if (interface->verbosity)
-               fprintf(stderr, "(afm-main-plugin) %s(%s) -> %s\n", method, sid, obj ? json_object_to_json_string(obj) : "NULL");
+               fprintf(stderr, "(afm-main-plugin) %s(%s) -> %s\n", method, sid,
+                       obj ? json_object_to_json_string(obj) : "NULL");
        free(sid);
        if (obj == NULL) {
                afb_req_fail(request, "failed", "framework daemon failure");
@@ -174,7 +175,8 @@ static void start(struct afb_req request)
        /* calls the service */
        obj = jbus_call_sj_sync(jbus, _start_, query);
        if (interface->verbosity)
-               fprintf(stderr, "(afm-main-plugin) start(%s) -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL");
+               fprintf(stderr, "(afm-main-plugin) start(%s) -> %s\n", query,
+                       obj ? json_object_to_json_string(obj) : "NULL");
        free(query);
 
        /* check status */
@@ -237,7 +239,8 @@ static void install(struct afb_req request)
 
        obj = jbus_call_sj_sync(jbus, _install_, query);
        if (interface->verbosity)
-               fprintf(stderr, "(afm-main-plugin) install(%s) -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL");
+               fprintf(stderr, "(afm-main-plugin) install(%s) -> %s\n", query,
+                       obj ? json_object_to_json_string(obj) : "NULL");
        free(query);
 
        /* check status */
@@ -284,27 +287,30 @@ const struct AFB_plugin *pluginRegister(const struct AFB_interface *itf)
 {
        struct sbus *sbus;
 
-       if (interface != NULL)
-               return NULL;
+       /* records the interface */
+       assert (interface == NULL);
 
-       interface = itf;
+       /* creates the sbus for session */
        sbusitf.wait = itf->pollitf->wait;
        sbusitf.open = itf->pollitf->open;
        sbusitf.on_readable = itf->pollitf->on_readable;
        sbusitf.on_writable = itf->pollitf->on_writable;
        sbusitf.on_hangup = itf->pollitf->on_hangup;
        sbusitf.close = itf->pollitf->close;
-
        sbus = sbus_session(&sbusitf, itf->pollclosure);
        if (sbus == NULL) {
                fprintf(stderr, "ERROR: %s:%d: can't connect to DBUS session\n", __FILE__, __LINE__);
                return NULL;
        }
 
+       /* creates the jbus for accessing afm-user-daemon */
        jbus = create_jbus(sbus, "/org/AGL/afm/user");
-        if (jbus)
-               return &plug_desc;
-       sbus_unref(sbus);
-       return NULL;
+        if (jbus == NULL) {
+               sbus_unref(sbus);
+               return NULL;
+       }
+
+       
+       return &plug_desc;
 }