* 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) */
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
+#include "utils-sbus.h"
#include "utils-jbus.h"
+static const char _added_[] = "added";
static const char _auto_[] = "auto";
static const char _continue_[] = "continue";
+static const char _changed_[] = "changed";
static const char _detail_[] = "detail";
static const char _id_[] = "id";
static const char _install_[] = "install";
static const char _uri_[] = "uri";
static const struct AFB_interface *interface;
+static struct afb_evmgr evmgr;
static struct jbus *jbus;
+static void application_list_changed(const char *data, void *closure)
+{
+ afb_evmgr_push(evmgr, "application-list-changed", NULL);
+}
+
static struct json_object *embed(const char *tag, struct json_object *obj)
{
struct json_object *result;
{
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;
}
+ obj = json_object_get(obj);
obj = embed(method, obj);
if (obj == NULL) {
afb_req_fail(request, "failed", "framework daemon failure");
}
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");
return;
}
+ obj = json_object_get(obj);
afb_req_success(request, obj, NULL);
}
afb_req_fail(request, "failed", "framework daemon failure");
return;
}
+ obj = json_object_get(obj);
afb_req_success(request, obj, NULL);
}
/* 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 */
+ obj = json_object_get(obj);
if (obj == NULL) {
afb_req_fail(request, "failed", "framework daemon failure");
return;
static void install(struct afb_req request)
{
- struct json_object *obj;
+ struct json_object *obj, *added;
char *query;
const char *filename;
struct afb_arg arg;
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 */
}
/* embed if needed */
+ if (json_object_object_get_ex(obj, _added_, &added))
+ obj = added;
+ obj = json_object_get(obj);
obj = embed(_id_, obj);
afb_req_success(request, obj, NULL);
}
.apis = plug_apis
};
+static struct sbus_itf sbusitf;
+
const struct AFB_plugin *pluginRegister(const struct AFB_interface *itf)
{
+ int rc;
+ struct afb_pollmgr pollmgr;
+ struct sbus *sbus;
+
+ /* records the interface */
+ assert (interface == NULL);
interface = itf;
+ evmgr = afb_daemon_get_evmgr(itf->daemon);
+
+ /* creates the sbus for session */
+ pollmgr = afb_daemon_get_pollmgr(itf->daemon);
+ sbusitf.wait = pollmgr.itf->wait;
+ sbusitf.open = pollmgr.itf->open;
+ sbusitf.on_readable = pollmgr.itf->on_readable;
+ sbusitf.on_writable = pollmgr.itf->on_writable;
+ sbusitf.on_hangup = pollmgr.itf->on_hangup;
+ sbusitf.close = pollmgr.itf->close;
+ sbus = sbus_session(&sbusitf, pollmgr.closure);
+ 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 == NULL) {
+ sbus_unref(sbus);
+ return NULL;
+ }
+
+ /* records the signal handler */
+ rc = jbus_on_signal_s(jbus, _changed_, application_list_changed, NULL);
+ if (rc < 0) {
+ jbus_unref(jbus);
+ return NULL;
+ }
- jbus = create_jbus_session("/org/AGL/afm/user");
- if (jbus)
- return &plug_desc;
- fprintf(stderr, "ERROR: %s:%d: can't connect to DBUS session\n", __FILE__, __LINE__);
- return NULL;
+ return &plug_desc;
}