src/event.c
src/file_service.c
src/conf.c
+ src/monitor.c
)
IF (WAYLAND_SUPPORT)
data-provider-master::bin data-provider-master::data r-x--- ------
data-provider-master::bin data-provider-master::share rwx--- ------
data-provider-master::bin data-provider-master::db rw---- ------
-data-provider-master::bin data-provider-master --x--- ------
+data-provider-master::bin data-provider-master rwx--- ------
data-provider-master::bin pkgmgr::db rw----- ------
data-provider-master::bin _ rw---- ------
data-provider-master::bin security-server::api-privilege-by-pid rw---- ------
--- /dev/null
+/*
+ * Copyright 2013 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+enum monitor_event_type {
+ MONITOR_EVENT_UNKNOWN = 0x0,
+ MONITOR_EVENT_CREATED = CMD_MONITOR_CREATE,
+ MONITOR_EVENT_DESTROYED = CMD_MONITOR_DESTROY,
+ MONITOR_EVENT_PAUSED = CMD_MONITOR_PAUSE,
+ MONITOR_EVENT_RESUMED = CMD_MONITOR_RESUME
+};
+
+struct monitor_client;
+
+extern struct monitor_client *monitor_create_client(const char *widget_id, pid_t pid, int handle);
+extern int monitor_destroy_client(struct monitor_client *monitor);
+
+extern struct monitor_client *monitor_find_client_by_pid(const char *widget_id, pid_t pid);
+extern struct monitor_client *monitor_find_client_by_handle(const char *widget_id, int handle);
+
+extern int monitor_multicast_state_change_event(const char *widget_id, enum monitor_event_type event, const char *instance_id, const char *content_info);
+
+/* End of a file */
#include "script_handler.h"
#include "buffer_handler.h"
#include "setting.h"
+#include "monitor.h"
int errno;
const char *widget_file;
const char *gbar_file;
unsigned int cmd = CMD_CREATED;
+ int ret;
widget_type = package_widget_type(inst->info);
gbar_type = package_gbar_type(inst->info);
owner_packet = NULL;
}
- return client_send_event(inst, packet, owner_packet);
+ ret = client_send_event(inst, packet, owner_packet);
+
+ monitor_multicast_state_change_event(package_name(inst->info), MONITOR_EVENT_CREATED, instance_id(inst), instance_content(inst));
+
+ return ret;
}
HAPI int instance_unicast_deleted_event(struct inst_info *inst, struct client_node *client, int reason)
instance_del_client(inst, client);
}
+ monitor_multicast_state_change_event(package_name(inst->info), MONITOR_EVENT_DESTROYED, instance_id(inst), instance_content(inst));
+
return ret;
}
} else {
inst->visible = state;
}
+ monitor_multicast_state_change_event(package_name(inst->info), MONITOR_EVENT_RESUMED, instance_id(inst), instance_content(inst));
break;
case WIDGET_HIDE_WITH_PAUSE:
}
instance_freeze_updator(inst);
+ monitor_multicast_state_change_event(package_name(inst->info), MONITOR_EVENT_PAUSED, instance_id(inst), instance_content(inst));
break;
default:
--- /dev/null
+/*
+ * Copyright 2013 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 <stdlib.h>
+
+#include <Eina.h>
+#include <dlog.h>
+
+#include <widget_errno.h>
+#include <widget_cmd_list.h>
+#include <packet.h>
+#include <com-core_packet.h>
+
+#include "debug.h"
+#include "dead_monitor.h"
+#include "monitor.h"
+#include "util.h"
+
+int errno;
+
+struct monitor_client {
+ char *widget_id;
+ pid_t pid;
+ int handle;
+};
+
+static struct info {
+ Eina_List *monitor_list;
+} s_info = {
+ .monitor_list = NULL,
+};
+
+static void monitor_disconnected_cb(int handle, void *data)
+{
+ struct monitor_client *monitor = data;
+
+ DbgPrint("monitor: %d is deleted (%s)\n", monitor->handle, monitor->widget_id);
+ s_info.monitor_list = eina_list_remove(s_info.monitor_list, monitor);
+ DbgFree(monitor);
+}
+
+HAPI struct monitor_client *monitor_create_client(const char *widget_id, pid_t pid, int handle)
+{
+ struct monitor_client *monitor;
+
+ monitor = calloc(1, sizeof(*monitor));
+ if (!monitor) {
+ ErrPrint("calloc: %d\n", errno);
+ return NULL;
+ }
+
+ if (widget_id) {
+ monitor->widget_id = strdup(widget_id);
+ if (!monitor->widget_id) {
+ ErrPrint("strdup: %s, %d\n", widget_id, errno);
+ DbgFree(monitor);
+ return NULL;
+ }
+ }
+ monitor->pid = pid;
+ monitor->handle = handle;
+
+ if (dead_callback_add(handle, monitor_disconnected_cb, monitor) < 0) {
+ ErrPrint("Failed to register the disconnected callback\n");
+ DbgFree(monitor);
+ return NULL;
+ }
+
+ s_info.monitor_list = eina_list_append(s_info.monitor_list, monitor);
+
+ return monitor;
+}
+
+HAPI int monitor_destroy_client(struct monitor_client *monitor)
+{
+ if (dead_callback_del(monitor->handle, monitor_disconnected_cb) != monitor) {
+ ErrPrint("Registered monitor object is not valid\n");
+ }
+
+ s_info.monitor_list = eina_list_remove(s_info.monitor_list, monitor);
+ DbgFree(monitor->widget_id);
+ DbgFree(monitor);
+ return WIDGET_ERROR_NONE;
+}
+
+HAPI struct monitor_client *monitor_find_client_by_pid(const char *widget_id, pid_t pid)
+{
+ Eina_List *l;
+ struct monitor_client *monitor;
+
+ monitor = NULL;
+ EINA_LIST_FOREACH(s_info.monitor_list, l, monitor) {
+ if (monitor->pid == pid) {
+ if (monitor->widget_id && widget_id) {
+ if (!strcmp(monitor->widget_id, widget_id)) {
+ break;
+ }
+ } else if (monitor->widget_id == widget_id) {
+ break;
+ }
+ }
+
+ monitor = NULL;
+ }
+
+ return monitor;
+}
+
+HAPI struct monitor_client *monitor_find_client_by_handle(const char *widget_id, int handle)
+{
+ Eina_List *l;
+ struct monitor_client *monitor;
+
+ monitor = NULL;
+ EINA_LIST_FOREACH(s_info.monitor_list, l, monitor) {
+ if (monitor->handle == handle) {
+ if (monitor->widget_id && widget_id) {
+ if (!strcmp(monitor->widget_id, widget_id)) {
+ break;
+ }
+ } else if (monitor->widget_id == widget_id) {
+ break;
+ }
+ }
+
+ monitor = NULL;
+ }
+
+ return monitor;
+}
+
+HAPI int monitor_multicast_state_change_event(const char *widget_id, enum monitor_event_type event, const char *instance_id, const char *content_info)
+{
+ struct monitor_client *monitor;
+ Eina_List *l;
+ int cnt;
+ unsigned int cmd;
+ struct packet *packet;
+
+ cmd = (unsigned int)event;
+
+ packet = packet_create_noack((const char *)&cmd, "dsss", util_timestamp(), widget_id, instance_id, content_info);
+ if (!packet) {
+ ErrPrint("Failed to create a packet\n");
+ return WIDGET_ERROR_FAULT;
+ }
+
+ cnt = 0;
+ EINA_LIST_FOREACH(s_info.monitor_list, l, monitor) {
+ if (widget_id && monitor->widget_id) {
+ if (!strcmp(widget_id, monitor->widget_id)) {
+ com_core_packet_send_only(monitor->handle, packet);
+ }
+ } else if (monitor->widget_id == NULL) {
+ com_core_packet_send_only(monitor->handle, packet);
+ }
+ }
+
+ packet_destroy(packet);
+
+ DbgPrint("%d events are multicasted\n", cnt);
+ return cnt;
+}
+
+/* End of a file */
#include "io.h"
#include "event.h"
#include "dead_monitor.h"
+#include "monitor.h"
#define GBAR_OPEN_MONITOR_TAG "gbar,open,monitor"
#define GBAR_RESIZE_MONITOR_TAG "gbar,resize,monitor"
return result;
}
+static struct packet *service_get_content(pid_t pid, int handle, const struct packet *packet)
+{
+ const char *inst_id;
+ const char *widget_id;
+ struct inst_info *inst;
+ struct packet *result;
+
+ if (packet_get(packet, "ss", &widget_id, &inst_id) != 1) {
+ ErrPrint("Invalid parameter\n");
+ return NULL;
+ }
+
+ inst = package_find_instance_by_id(widget_id, inst_id);
+ if (!inst) {
+ result = packet_create_reply(packet, "is", WIDGET_ERROR_NOT_EXIST, "?");
+ } else {
+ result = packet_create_reply(packet, "is", WIDGET_ERROR_NONE, instance_content(inst));
+ }
+
+ if (!result) {
+ ErrPrint("Failed to create a result packet\n");
+ }
+
+ return result;
+}
+
+static struct packet *service_get_inst_list(pid_t pid, int handle, const struct packet *packet)
+{
+ const char *widget_id;
+ struct pkg_info *pkg;
+ struct packet *result;
+
+ if (packet_get(packet, "s", &widget_id) != 1) {
+ ErrPrint("Invalid parameter\n");
+ return NULL;
+ }
+
+ pkg = package_find(widget_id);
+ if (!pkg) {
+ result = packet_create_reply(packet, "iis", WIDGET_ERROR_NOT_EXIST, 0, NULL);
+ } else {
+ Eina_List *inst_list;
+
+ inst_list = package_instance_list(pkg);
+ if (!inst_list) {
+ result = packet_create_reply(packet, "iis", WIDGET_ERROR_NOT_EXIST, 0, NULL);
+ } else {
+ char *id_buffer;
+ int size = sysconf(_SC_PAGESIZE);
+ Eina_List *l;
+ struct inst_info *inst;
+ int offset;
+ int len;
+ int cnt = 0;
+
+ id_buffer = malloc(size);
+ if (!id_buffer) {
+ result = packet_create_reply(packet, "iis", WIDGET_ERROR_OUT_OF_MEMORY, 0, NULL);
+ goto out;
+ }
+
+ offset = 0;
+ EINA_LIST_FOREACH(inst_list, l, inst) {
+ len = strlen(instance_id(inst));
+ if (offset + len > size) {
+ /* Expanding the ID_BUFFER */
+ char *resized_buffer;
+ size += sysconf(_SC_PAGESIZE);
+
+ DbgPrint("Expanding heap to %d\n", size);
+
+ resized_buffer = realloc(id_buffer, size);
+ if (!resized_buffer) {
+ ErrPrint("realloc: %d\n", errno);
+ DbgFree(id_buffer);
+ result = packet_create_reply(packet, "iis", WIDGET_ERROR_OUT_OF_MEMORY, 0, NULL);
+ goto out;
+ }
+
+ id_buffer = resized_buffer;
+ cnt++;
+ }
+
+ strcpy(id_buffer + offset, instance_id(inst));
+ /* Replace last NULL with NEW_LINE */
+ id_buffer[offset + len] = '\n';
+ offset += (len + 1);
+ }
+
+ id_buffer[offset] = '\0';
+ result = packet_create_reply(packet, "iis", WIDGET_ERROR_NONE, cnt, id_buffer);
+ DbgFree(id_buffer);
+ }
+ }
+
+out:
+ return result;
+}
+
+static struct packet *monitor_register(pid_t pid, int handle, const struct packet *packet)
+{
+ const char *widget_id;
+
+ if (packet_get(packet, "s", &widget_id) != 1) {
+ ErrPrint("Invalid parameter\n");
+ goto out;
+ }
+
+ if (widget_id[0] == '*' && widget_id[1] == '\0') {
+ widget_id = NULL;
+ }
+
+ DbgPrint("Register monitor target for [%s]\n", widget_id);
+
+ if (monitor_find_client_by_pid(widget_id, pid)) {
+ ErrPrint("Already registered: [%s], %d\n", widget_id, pid);
+ } else {
+ if (monitor_create_client(widget_id, pid, handle) == NULL) {
+ ErrPrint("Failed to create a new monitor client\n");
+ }
+ }
+
+out:
+ return NULL;
+}
+
+static struct packet *monitor_unregister(pid_t pid, int handle, const struct packet *packet)
+{
+ const char *widget_id;
+ struct monitor_client *monitor;
+
+ if (packet_get(packet, "s", &widget_id) != 1) {
+ ErrPrint("Invalid parameter\n");
+ goto out;
+ }
+
+ if (widget_id[0] == '*' && widget_id[1] == '\0') {
+ widget_id = NULL;
+ }
+
+ monitor = monitor_find_client_by_pid(widget_id, pid);
+ if (monitor) {
+ DbgPrint("Unregister monitor target: %s\n", widget_id);
+ monitor_destroy_client(monitor);
+ } else {
+ ErrPrint("Monitor for %s is not exists(%d)\n", widget_id, pid);
+ }
+
+out:
+ return NULL;
+}
+
static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet)
{
struct inst_info *inst;
.handler = service_instance_count,
},
{
+ .cmd = CMD_STR_MONITOR_REGISTER,
+ .handler = monitor_register,
+ },
+ {
+ .cmd = CMD_STR_MONITOR_UNREGISTER,
+ .handler = monitor_unregister,
+ },
+ {
+ .cmd = CMD_STR_SERVICE_GET_CONTENT,
+ .handler = service_get_content,
+ },
+ {
+ .cmd = CMD_STR_SERVICE_GET_INST_LIST,
+ .handler = service_get_inst_list,
+ },
+ {
.cmd = NULL,
.handler = NULL,
},
#include <com-core_packet.h>
#include <com-core.h>
+#include <widget_errno.h>
#include <widget_service.h>
#include <widget_service_internal.h>
static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler);
+static inline const char *trim_cmd(const char *cmd)
+{
+ while (*cmd && *cmd == ' ') cmd++;
+
+ return cmd;
+}
+
static Eina_Bool process_line_cb(void *data)
{
input_cb(NULL, NULL);
ROOT,
} type;
- cmd += 5;
- while (*cmd && *cmd == ' ') cmd++;
-
+ cmd = trim_cmd(cmd + 5);
if (!*cmd){
printf("Invalid argument\n");
return -EINVAL;
cmd += 4;
i = get_token(cmd, variable);
- cmd += i;
- while (*cmd && *cmd == ' ') {
- cmd++;
- }
-
+ cmd = trim_cmd(cmd + i);
if (!i || !*cmd) {
printf("Invalid argument(%s): set [VAR] [VAL]\n", cmd);
return -EINVAL;
static inline int do_get(const char *cmd)
{
- cmd += 4;
-
- while (*cmd && *cmd == ' ') cmd++;
+ cmd = trim_cmd(cmd + 4);
if (!*cmd) {
printf("Invalid argument(%s): get [VAR]\n", cmd);
return -EINVAL;
const char *name;
struct node *parent;
- cmd += 2;
-
- while (*cmd && *cmd == ' ') {
- cmd++;
- }
+ cmd = trim_cmd(cmd + 2);
s_info.targetdir = *cmd ? update_target_dir(cmd) : s_info.curdir;
if (!s_info.targetdir) {
static inline int do_cd(const char *cmd)
{
- cmd += 2;
-
- while (*cmd && *cmd == ' ') {
- cmd++;
- }
-
+ cmd = trim_cmd(cmd + 2);
if (!*cmd) {
return -1;
}
static inline int do_rm(const char *cmd)
{
- cmd += 2;
- while (*cmd && *cmd == ' ') cmd++;
+ cmd = trim_cmd(cmd + 2);
if (!*cmd) {
return -1;
}
static inline int do_fault(const char *cmd)
{
- cmd += 5;
- while (*cmd && *cmd == ' ') cmd++;
+ cmd = trim_cmd(cmd + 5);
if (!*cmd) {
return -1;
}
{
pid_t pid;
- cmd += 3;
-
- while (*cmd && *cmd == ' ') {
- cmd++;
- }
-
+ cmd = trim_cmd(cmd + 3);
if (!*cmd) {
return;
}
return 0;
}
+static int widget_lifecycle_event(const char *widget_id, widget_lifecycle_event_e ev, const char *instance_id, void *data)
+{
+ printf("[%s] [%s] [STATE: 0x%X]\n", widget_id, instance_id, (unsigned int)ev);
+ return WIDGET_ERROR_NONE;
+}
+
+static void do_monitor(const char *cmd)
+{
+ cmd = trim_cmd(cmd + strlen("monitor"));
+
+ if (!*cmd) {
+ /* Monitor all instances */
+ } else {
+ /* Monitor one */
+ printf("Instance = [%s]\n", cmd);
+ }
+
+ widget_service_set_lifecycle_event_cb(*cmd ? cmd : NULL, widget_lifecycle_event, NULL);
+}
+
+static void do_demonitor(const char *cmd)
+{
+ cmd = trim_cmd(cmd + strlen("demonitor"));
+ if (!*cmd) {
+ } else {
+ printf("Instance = [%s]\n", cmd);
+ }
+
+ widget_service_unset_lifecycle_event_cb(*cmd ? cmd : NULL, NULL);
+}
+
static void do_dump(const char *cmd)
{
char path[256];
struct node *curdir;
struct node *target;
- cmd += 5;
-
- while (*cmd && *cmd == ' ') {
- cmd++;
- }
-
+ cmd = trim_cmd(cmd + 5);
if (!*cmd) {
return;
}
{
Display *disp;
- cmd += 2;
-
- while (*cmd && *cmd == ' ') {
- cmd++;
- }
-
+ cmd = trim_cmd(cmd + 2);
if (!*cmd) {
return;
}
static void do_command(const char *cmd)
{
/* Skip the first spaces */
- while (*cmd && *cmd == ' ') {
- cmd++;
- }
+ cmd = trim_cmd(cmd);
if (strlen(cmd) && *cmd != '#') {
if (!strncasecmp(cmd, "exit", 4) || !strncasecmp(cmd, "quit", 4)) {
if (do_fault(cmd) == 0) {
return;
}
- } else if (!strncasecmp(cmd, "sh ", 3)) {
+ } else if (!strncasecmp(cmd, "sh ", strlen("sh "))) {
do_sh(cmd);
- } else if (!strncasecmp(cmd, "x ", 2)) {
+ } else if (!strncasecmp(cmd, "x ", strlen("x "))) {
do_x(cmd);
- } else if (!strncasecmp(cmd, "dump", 4)) {
+ } else if (!strncasecmp(cmd, "dump", strlen("dump"))) {
do_dump(cmd);
+ } else if (!strncasecmp(cmd, "monitor", strlen("monitor"))) {
+ do_monitor(cmd);
+ } else if (!strncasecmp(cmd, "demonitor", strlen("demonitor"))) {
+ do_demonitor(cmd);
} else {
help();
}