It's need for internal interface among device modules.
Change-Id: I994d56ac2f33718253e98bf9f4cd05036ab66d22
Signed-off-by: Krzysztof Sasiak <k.sasiak@samsung.com>
SET(SRCS
src/battery/lowbat-handler.c
src/bs/bs.c
+ src/core/device-notifier.c
src/core/main.c
src/core/sysnoti.c
src/core/launch.c
#include "core/queue.h"
#include "core/data.h"
#include "core/devices.h"
+#include "core/device-notifier.h"
#define USB_CON_PIDFILE "/var/run/.system_server.pid"
#define PM_STATE_LOG_FILE "/var/log/pm_state.log"
return EINA_FALSE;
}
-struct pm_listener {
- enum pm_status status;
- int (*func)(void *data);
-};
-
-Eina_List *pm_listener_list;
-
-int pm_add_listener(enum pm_status status, int (*func)(void *data))
-{
- Eina_List *n;
- struct pm_listener *data, *listener;
-
- LOGINFO("%d, %x", status, func);
-
- if (!func) {
- LOGERR("invalid func address!");
- return -1;
- }
-
- EINA_LIST_FOREACH(pm_listener_list, n, data)
- if (status == data->status && func == (data->func)) {
- LOGERR("function is already registered! [%d, %x]",
- status, func);
- return -1;
- }
-
- listener = malloc(sizeof(struct pm_listener));
- if (!listener) {
- LOGERR("Fail to malloc for listener!");
- return -1;
- }
-
- listener->status = status;
- listener->func = func;
-
- pm_listener_list = eina_list_append(pm_listener_list, listener);
-
- return 0;
-}
-
-int pm_del_listener(enum pm_status status, int (*func)(void *data))
-{
- Eina_List *n, *next;
- struct pm_listener *listener;
-
- if (!func) {
- LOGERR("invalid func address!");
- return -1;
- }
-
- EINA_LIST_FOREACH_SAFE(pm_listener_list, n, next, listener)
- if (status == listener->status && func == (listener->func)) {
- LOGINFO("[%d, %x]", status, func);
- free(listener);
- pm_listener_list = eina_list_remove_list(
- pm_listener_list, n);
- }
-
- return 0;
-}
-
-static void pm_del_listener_all(void)
-{
- Eina_List *n, *next;
- struct pm_listener *listener;
-
- EINA_LIST_FOREACH_SAFE(pm_listener_list, n, next, listener)
- if (listener) {
- free(listener);
- pm_listener_list = eina_list_remove_list(pm_listener_list, n);
- }
-
- LOGINFO("all deleted!");
-}
-
-void pm_talker(enum pm_status status, void *data)
-{
- Eina_List *n;
- struct pm_listener *listener;
- int cnt = 0;
-
- EINA_LIST_FOREACH(pm_listener_list, n, listener) {
- if (status == listener->status) {
- if (listener->func) {
- listener->func(data);
- cnt++;
- }
- }
- }
-
- LOGINFO("cb is called! status:%d, cnt:%d ", status, cnt);
-}
-
/* update transition condition for application requrements */
static int proc_condition(PMMsg *data)
{
if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) {
set_setting_pmstate(pm_cur_state);
- pm_talker(PM_STATUS_LCD, pm_cur_state);
+ device_notify(DEVICE_NOTIFIER_LCD, pm_cur_state);
}
switch (pm_cur_state) {
case S_NORMAL:
int i;
end_battinfo_gathering();
- pm_del_listener_all();
for (i = i - 1; i >= INIT_SETTING; i--) {
switch (i) {
int timeout;
} states[S_END];
-enum pm_status {
- PM_STATUS_LCD,
- PM_STATUS_MAX
-};
-
-int pm_add_listener(enum pm_status status, int (*func)(void *data));
-int pm_del_listener(enum pm_status status, int (*func)(void *data));
-void pm_talker(enum pm_status status, void *value);
-
/* If the bit in a condition variable is set,
* we cannot transit the state until clear this bit. */
int trans_condition;
--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 <Ecore.h>
+
+#include "log.h"
+#include "devices.h"
+#include "device-notifier.h"
+#include "list.h"
+
+struct device_notifier {
+ enum device_notifier_type status;
+ int (*func)(void *data);
+};
+
+static Eina_List *device_notifier_list;
+
+#define FIND_NOTIFIER(a, b, c, d, e, f) \
+ EINA_LIST_FOREACH_SAFE(a, b, c, d) \
+ if (e == d->e && f == (d->f))
+
+int register_notifier(enum device_notifier_type status, int (*func)(void *data))
+{
+ Eina_List *n, *next;
+ struct device_notifier *data, *notifier;
+
+ PRT_TRACE("%d, %x", status, func);
+
+ if (!func) {
+ PRT_TRACE_ERR("invalid func address!");
+ return -EINVAL;
+ }
+
+ FIND_NOTIFIER(device_notifier_list, n, next, notifier, status, func) {
+ PRT_TRACE_ERR("function is already registered! [%d, %x]",
+ status, func);
+ return -EINVAL;
+ }
+
+ notifier = malloc(sizeof(struct device_notifier));
+ if (!notifier) {
+ PRT_TRACE_ERR("Fail to malloc for notifier!");
+ return -ENOMEM;
+ }
+
+ notifier->status = status;
+ notifier->func = func;
+
+ EINA_LIST_APPEND(device_notifier_list, notifier);
+
+ return 0;
+}
+
+int unregister_notifier(enum device_notifier_type status, int (*func)(void *data))
+{
+ Eina_List *n, *next;
+ struct device_notifier *notifier;
+
+ if (!func) {
+ PRT_TRACE_ERR("invalid func address!");
+ return -EINVAL;
+ }
+
+ FIND_NOTIFIER(device_notifier_list, n, next, notifier, status, func) {
+ PRT_TRACE("[%d, %x]", status, func);
+ free(notifier);
+ EINA_LIST_REMOVE_LIST(device_notifier_list, n);
+ }
+
+ return 0;
+}
+
+void device_notify(enum device_notifier_type status, void *data)
+{
+ Eina_List *n;
+ struct device_notifier *notifier;
+ int cnt = 0;
+
+ EINA_LIST_FOREACH(device_notifier_list, n, notifier) {
+ if (status == notifier->status) {
+ if (notifier->func) {
+ notifier->func(data);
+ cnt++;
+ }
+ }
+ }
+
+ PRT_TRACE("cb is called! status:%d, cnt:%d ", status, cnt);
+}
+
+static void device_notifier_exit(void)
+{
+ Eina_List *n, *next;
+ struct device_notifier *notifier;
+
+ EINA_LIST_FOREACH_SAFE(device_notifier_list, n, next, notifier)
+ if (notifier) {
+ free(notifier);
+ EINA_LIST_REMOVE_LIST(device_notifier_list, n);
+ }
+
+ PRT_TRACE("all deleted!");
+}
+
+const struct device_ops notifier_device_ops = {
+ .exit = device_notifier_exit,
+};
+
--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __DEVICE_NOTIFIER_H__
+#define __DEVICE_NOTIFIER_H__
+
+enum device_notifier_type {
+ DEVICE_NOTIFIER_LCD,
+ DEVICE_NOTIFIER_MAX,
+};
+
+/*
+ * This is for internal callback method.
+ */
+int register_notifier(enum device_notifier_type status, int (*func)(void *data));
+int unregister_notifier_del(enum device_notifier_type status, int (*func)(void *data));
+void device_notify(enum device_notifier_type status, void *value);
+
+#endif /* __DEVICE_NOTIFIER_H__ */
&mmc_device_ops,
&led_device_ops,
&vibrator_device_ops,
+ ¬ifier_device_ops,
};
void devices_init(void *data)
extern const struct device_ops mmc_device_ops;
extern const struct device_ops led_device_ops;
extern const struct device_ops vibrator_device_ops;
+extern const struct device_ops notifier_device_ops;
#endif
--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __LIST_H__
+#define __LIST_H__
+
+#include <Ecore.h>
+
+#define EINA_LIST_APPEND(a, b) \
+ a = eina_list_append(a, b)
+
+#define EINA_LIST_REMOVE(a, b) \
+ a = eina_list_remove(a, b)
+
+#define EINA_LIST_REMOVE_LIST(a, b) \
+ a = eina_list_remove_list(a, b)
+
+#define EINA_LIST_FREE(a) \
+ a = eina_list_free(a)
+
+#endif