Introduce libactd library 40/203540/11
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Mon, 15 Apr 2019 15:19:33 +0000 (17:19 +0200)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Tue, 30 Apr 2019 13:28:20 +0000 (15:28 +0200)
This library exports API for interacting with other modules.

Change-Id: I84ef2eda8bdcb2b3c7f85b199c84017411328a23
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
Makefile.am
configure.ac
include/unit_control.h [new file with mode: 0644]
packaging/activationd.spec
src/libactd/unit_control.c [new file with mode: 0644]

index 42632a974735f20f2e45ce06b302ab6490dbdbfa..0aa85445435c6f51136ce7088f20609c774e1843 100644 (file)
@@ -195,6 +195,13 @@ install-data-local:
        $(MKDIR_P) $(DESTDIR)$(sysconfdir)/actd/available-modules
        $(MKDIR_P) $(DESTDIR)$(sysconfdir)/actd/enabled-modules
 
+lib_LTLIBRARIES = libactd.la
+libactd_la_SOURCES = src/libactd/unit_control.c
+libactd_la_LDFLAGS = -pie -shared
+libactd_la_LIBADD = $(SYSCOMMON_LIBS)
+libactd_la_CFLAGS = $(AM_CFLAGS) $(SYSCOMMON_CFLAGS)
+libactd_includedir = $(includedir)/actd
+libactd_include_HEADERS = include/unit_control.h
 
 bin_PROGRAMS = activationd_acceptance_checker
 
index 6cd5dc83e818107b1126f7d9202e76c2382f05c8..e4b9c143ae96aba4f94b97fa1dd51e4a25139827 100644 (file)
@@ -132,6 +132,13 @@ PKG_CHECK_MODULES(VCONF,
 AS_IF([test "x$have_vconf" = "xno"],
       AC_MSG_ERROR([vconf not found]))
 
+PKG_CHECK_MODULES(SYSCOMMON,
+        [libsyscommon],
+        have_syscommon=yes,
+        have_syscommon=no)
+AS_IF([test "x$have_syscommon" = "xno"],
+      AC_MSG_ERROR([syscommon not found]))
+
 AC_CHECK_FUNCS([ \
        printf\
 ])
@@ -159,6 +166,7 @@ AC_MSG_RESULT([
         libsystemd:             ${have_libsystemd}
         glib                    ${have_glib}
         vconf                    ${have_vconf}
+        libsyscommon            ${have_syscommon}
 
         modules:                ${ENABLED_MODULES/ /}
 ])
diff --git a/include/unit_control.h b/include/unit_control.h
new file mode 100644 (file)
index 0000000..136eb24
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef UNIT_CONTROL_H
+#define UNIT_CONTROL_H
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+typedef void (*actd_unit_cb)(GVariant *var, void *user_data, GError *err);
+
+int actd_start_unit(const char *unit);
+int actd_stop_unit(const char *unit);
+int actd_restart_unit(const char *unit);
+
+int actd_start_unit_async(const char *unit, actd_unit_cb cb, void *user_data);
+int actd_stop_unit_async(const char *unit, actd_unit_cb cb, void *user_data);
+int actd_restart_unit_async(const char *unit, actd_unit_cb cb, void *user_data);
+
+#endif /* UNIT_CONTROL_H */
index c07e58873c4ec093438f4c84b61c1bf1b280a17b..c0f33af03b461b3741b3ae4688cf1ec788ae5129 100644 (file)
@@ -84,6 +84,15 @@ Group:      System/Monitoring
 %description  -n event-processing-devel
 Files used in external modules development
 
+%package -n libactd
+Summary:    Activationd API
+Group:      Development/Libraries
+BuildRequires: pkgconfig(libsyscommon)
+BuildRequires: pkgconfig(dlog)
+
+%description -n libactd
+This library provides API for interaction with modules
+
 %prep
 %setup -q
 cp %{SOURCE1001} .
@@ -139,10 +148,14 @@ mkdir -p %{buildroot}/%{enabled_moduledir}
 
 %files
 
+%files -n libactd
+%{_prefix}/lib/libactd.so*
+
 %files -n event-processing-devel
 %license COPYING
 %{_includedir}/*
 %{_libdir}/pkgconfig/*
+%{_prefix}/include/actd/*
 
 %files -n event-processing-activation-dm -f activation-dm-files
 %license COPYING
diff --git a/src/libactd/unit_control.c b/src/libactd/unit_control.c
new file mode 100644 (file)
index 0000000..71d7a05
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * This file is part of epc.
+ *
+ * Copyright © 2019 Samsung Electronics
+ *
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+#include <libsyscommon/dbus-system.h>
+#include <errno.h>
+
+#include "unit_control.h"
+
+#define UNIT_CONTROL_NAME "org.tizen.Activationd"
+#define UNIT_CONTROL_INTERFACE "org.tizen.Activationd"
+#define UNIT_CONTROL_OBJ_PATH "/org/tizen/activationd"
+
+static int call_uc(const char *method, const char *unit)
+{
+       int ret;
+       GVariant *msg = NULL;
+       const char *result;
+
+       msg = dbus_handle_method_sync_with_reply_var(UNIT_CONTROL_NAME,
+                       UNIT_CONTROL_OBJ_PATH,
+                       UNIT_CONTROL_INTERFACE,
+                       method,
+                       g_variant_new("(s)", unit));
+
+       if (!msg)
+               return -EBADMSG;
+
+       g_variant_get(msg, "(s)", &result);
+       if (g_strcmp0(result, "ok") == 0)
+               ret = 0;
+       else
+               ret = -1;
+
+       g_free(result);
+       return ret;
+}
+
+static int call_uc_async(const char *method, const char *unit, actd_unit_cb cb, void *user_data)
+{
+       return dbus_handle_method_async_with_reply_var(UNIT_CONTROL_NAME,
+                       UNIT_CONTROL_OBJ_PATH,
+                       UNIT_CONTROL_INTERFACE,
+                       method,
+                       g_variant_new("(s)", unit),
+                       cb,
+                       -1,
+                       user_data);
+}
+
+int actd_start_unit(const char *unit)
+{
+       return call_uc("Start", unit);
+}
+
+int actd_stop_unit(const char *unit)
+{
+       return call_uc("Stop", unit);
+}
+
+int actd_restart_unit(const char *unit)
+{
+       return call_uc("Restart", unit);
+}
+
+int actd_start_unit_async(const char *unit, actd_unit_cb cb, void *user_data)
+{
+       return call_uc_async("Start", unit, cb, user_data);
+}
+
+int actd_stop_unit_async(const char *unit, actd_unit_cb cb, void *user_data)
+{
+       return call_uc_async("Stop", unit, cb, user_data);
+}
+
+int actd_restart_unit_async(const char *unit, actd_unit_cb cb, void *user_data)
+{
+       return call_uc_async("Restart", unit, cb, user_data);
+}