Add control logic for start/stop device. 87/14687/1
authorsh.pi <sh.pi@samsung.com>
Wed, 10 Apr 2013 11:22:16 +0000 (20:22 +0900)
committerKrzysztof Sasiak <k.sasiak@samsung.com>
Thu, 9 Jan 2014 16:36:13 +0000 (17:36 +0100)
Change-Id: I9d2d8767fbf12b0ee993e0f4ad4f993322ed7fb9
Signed-off-by: Krzysztof Sasiak <k.sasiak@samsung.com>
CMakeLists.txt
packaging/system-server.spec
src/control/control.c [new file with mode: 0644]
src/core/devices.c
src/core/devices.h
src/deviced/dd-control.h [new file with mode: 0644]
src/shared/control.c [new file with mode: 0644]

index de34f2b..797b659 100755 (executable)
@@ -53,9 +53,13 @@ SET(SRCS ${SRCS}
 SET(SRCS ${SRCS}
        src/led/led.c)
 
+SET(SRCS ${SRCS}
+       src/control/control.c)
+
 # libdeviced
 SET(DEVICED_SRCS
        src/shared/battery.c
+       src/shared/control.c
        src/shared/deviced-conf.c
        src/shared/deviced-noti.c
        src/shared/deviced-util.c
@@ -66,6 +70,7 @@ SET(DEVICED_SRCS
 
 SET(DEVICED_HEADERS
        src/deviced/dd-battery.h
+       src/deviced/dd-control.h
        src/deviced/dd-deviced.h
        src/deviced/dd-deviced-managed.h
        src/deviced/dd-display.h
index 1333bd1..056cb19 100755 (executable)
@@ -414,6 +414,7 @@ systemctl daemon-reload
 %files -n libdeviced-devel
 %defattr(-,root,root,-)
 %{_includedir}/deviced/dd-battery.h
+%{_includedir}/deviced/dd-control.h
 %{_includedir}/deviced/dd-deviced.h
 %{_includedir}/deviced/dd-deviced-managed.h
 %{_includedir}/deviced/dd-display.h
diff --git a/src/control/control.c b/src/control/control.c
new file mode 100644 (file)
index 0000000..455ca20
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * deviced
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * 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 <stdio.h>
+#include <errno.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <dd-control.h>
+
+#include "core/log.h"
+#include "core/common.h"
+#include "core/devices.h"
+
+static const struct control_device {
+       const int id;
+       const struct device_ops *ops;
+} devices[] = {
+       /*  code example
+        * { DEVICE_CONTROL_DISPLAY,       &display_device_ops },
+        */
+       /* Add id & ops to provide start/stop control */
+};
+
+static int control_handler(int argc, char **argv)
+{
+       int i;
+       int pid;
+       int device;
+       bool enable;
+       int ret;
+
+       PRT_TRACE("argc : %d", argc);
+       for (i = 0; i < argc; ++i)
+               PRT_TRACE("[%2d] %s", i, argv[i]);
+
+       if (argc > 5) {
+               PRT_TRACE_ERR("Invalid argument");
+               errno = EINVAL;
+               return -1;
+       }
+
+       pid = atoi(argv[0]);
+       device = atoi(argv[1]);
+       enable = atoi(argv[2]);
+       PRT_TRACE("pid : %d, device : %d, enable :%d", pid, device, enable);
+
+       for (i = 0; i < ARRAY_SIZE(devices); i++)
+               if (devices[i].id == device)
+                       break;
+
+       if (i >= ARRAY_SIZE(devices))
+               return -EINVAL;
+
+       if (enable)
+               ret = device_start(devices[i].ops);
+       else
+               ret = device_stop(devices[i].ops);
+
+       return ret;
+}
+
+static void control_init(void *data)
+{
+       ss_action_entry_add_internal(CONTROL_HANDLER_NAME, control_handler, NULL, NULL);
+}
+
+const struct device_ops control_device_ops = {
+       .init = control_init,
+};
+
index 4373b80..13a85b7 100644 (file)
@@ -29,6 +29,7 @@ static const struct device_ops *devices[] = {
        /* The below devices don't have any init dependency */
        &sysnoti_device_ops,
        &noti_device_ops,
+       &control_device_ops,
        &core_device_ops,
        &signal_device_ops,
        &predefine_device_ops,
index 268a125..308df65 100644 (file)
@@ -51,6 +51,7 @@ extern const struct device_ops edbus_device_ops;
 extern const struct device_ops display_device_ops;
 extern const struct device_ops sysnoti_device_ops;
 extern const struct device_ops noti_device_ops;
+extern const struct device_ops control_device_ops;
 extern const struct device_ops core_device_ops;
 extern const struct device_ops signal_device_ops;
 extern const struct device_ops predefine_device_ops;
diff --git a/src/deviced/dd-control.h b/src/deviced/dd-control.h
new file mode 100644 (file)
index 0000000..563499d
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * deviced
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+
+#ifndef __DD_CONTROL_H__
+#define __DD_CONTROL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdbool.h>
+
+/**
+ * @file        dd-control.h
+ * @ingroup     DEVICED_LIBRARY
+ * @brief       This file provides to enable/disable devices
+ */
+
+#define CONTROL_HANDLER_NAME           "control"
+
+enum control_device_type {
+       /* Add device define here  */
+       /* DEVICE_CONTROL_DISPLAY, */
+       DEVICE_CONTROL_MAX,
+};
+
+/*
+ * Add new function to control in library.
+ */
+/*
+ * exmaple code
+ * int deviced_display_control(bool enable);
+ */
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/shared/control.c b/src/shared/control.c
new file mode 100644 (file)
index 0000000..cfc7331
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * deviced
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * 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 <stdio.h>
+#include <vconf.h>
+#include <errno.h>
+#include <device-node.h>
+
+#include "log.h"
+#include "dd-control.h"
+
+static int deviced_control_common(int device, bool enable)
+{
+       char buf_pid[6];
+       char buf_dev[3];
+       char buf_enable[2];
+
+       snprintf(buf_pid, sizeof(buf_pid), "%d", getpid());
+       snprintf(buf_dev, sizeof(buf_dev), "%d", device);
+       snprintf(buf_enable, sizeof(buf_enable), "%d", enable);
+
+       return deviced_call_predef_action(CONTROL_HANDLER_NAME, 3, buf_pid,
+                   buf_dev, buf_enable);
+}
+
+/*
+ * example of control api
+ * API int deviced_display_control(bool enable)
+ * {
+ *     return deviced_control_common(DEVICE_CONTROL_DISPLAY, enable);
+ * }
+ */
+