Replace dbus with socket (connector)
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 14 Jun 2012 14:20:14 +0000 (23:20 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Sun, 17 Jun 2012 07:05:50 +0000 (16:05 +0900)
And there is more minor patche is applied.
------------------------------------------
Keep the last state of the Buffer

When the slave is deactivated,
all instance on that slave will be destroyed.
And reactivating normal instances again.

While executing this procedure,
master will deactivate the instance then its buffers are destroyed.
But after destroying all buffers, it doesn't re-create after
re-activated the instances.

This patch fix it.

Change-Id: I36367a8c6ce11ad597b899d0841b73e52f2385a2

54 files changed:
CMakeLists.txt
data/data-provider-master
debian/changelog
debian/com.samsung.data-provider-master.install.in
debian/com.samsung.data-provider-master.postinst
deprecated/comm/dbus.c [moved from src/dbus.c with 100% similarity]
deprecated/comm/dbus.h [moved from include/dbus.h with 100% similarity]
deprecated/manager/client_manager.c [moved from deprecated/client_manager.c with 100% similarity]
deprecated/manager/client_manager.h [moved from deprecated/client_manager.h with 100% similarity]
deprecated/manager/pkg_manager.c [moved from deprecated/pkg_manager.c with 100% similarity]
deprecated/manager/pkg_manager.h [moved from deprecated/pkg_manager.h with 100% similarity]
deprecated/manager/rpc_to_slave.c [moved from deprecated/rpc_to_slave.c with 100% similarity]
deprecated/manager/slave_manager.c [moved from deprecated/slave_manager.c with 100% similarity]
deprecated/manager/slave_manager.h [moved from deprecated/slave_manager.h with 100% similarity]
include/client_life.h
include/client_rpc.h
include/connector.h [new file with mode: 0644]
include/connector_packet.h [new file with mode: 0644]
include/debug.h
include/dlist.h [new file with mode: 0644]
include/instance.h
include/package.h
include/packet.h [new file with mode: 0644]
include/secom_socket.h [new file with mode: 0644]
include/server.h [new file with mode: 0644]
include/slave_life.h
include/slave_rpc.h
include/util.h
packaging/com.samsung.data-provider-master.spec
src/client_life.c
src/client_rpc.c
src/connector.c [new file with mode: 0644]
src/connector_packet.c [new file with mode: 0644]
src/ctx_client.c
src/dead_monitor.c
src/dlist.c [new file with mode: 0644]
src/fault_manager.c
src/fb.c
src/group.c
src/instance.c
src/io.c
src/main.c
src/package.c
src/packet.c [new file with mode: 0644]
src/parser.c
src/script_handler.c
src/secom_socket.c [new file with mode: 0644]
src/server.c [new file with mode: 0644]
src/setting.c
src/slave_life.c
src/slave_rpc.c
src/util.c
src/virtual_canvas.c
src/xmonitor.c

index 8bf011d..0232b52 100644 (file)
@@ -56,7 +56,6 @@ ADD_DEFINITIONS(${pkg_LDFLAGS})
 
 ADD_EXECUTABLE(${PROJECT_NAME}
        src/main.c
-       src/dbus.c
        src/util.c
        src/fault_manager.c
        src/parser.c
@@ -76,11 +75,18 @@ ADD_EXECUTABLE(${PROJECT_NAME}
        src/setting.c
        src/package.c
        src/instance.c
+       src/secom_socket.c
+       src/packet.c
+       src/connector.c
+       src/connector_packet.c
+       src/dlist.c
+       src/server.c
 )
 
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkg_LDFLAGS} "-ldl")
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/com.samsung.data-provider-master.desktop DESTINATION /opt/share/applications)
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /opt/apps/com.samsung.${PROJECT_NAME}/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+#INSTALL(FILES ${CMAKE_SOURCE_DIR}/com.samsung.data-provider-master.desktop DESTINATION /opt/share/applications)
+#INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /opt/apps/com.samsung.${PROJECT_NAME}/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
 
 # INCLUDE FOR BUILD & INSTALL .PO FILES
 ADD_SUBDIRECTORY(res)
index 23385a7..3dac7b1 100755 (executable)
@@ -1,15 +1,28 @@
 #!/bin/sh
 
+launch_provider()
+{
+       while [ ! -f "/tmp/.stop.provider" ]; do
+               /usr/bin/data-provider-master 
+       done
+       rm /tmp/.stop.provider
+}
+
 start ()
 {
-       aul_test launch com.samsung.data-provider-master
+       launch_provider &
 }
 
 stop ()
 {
-       PID=`ps ax | grep 'data-provider-master' | grep -v 'grep' | grep -v 'dlogutil' | awk '{print $1}'`
+       touch /tmp/.stop.provider
+       PID=`ps ax | grep 'data-provider-master' | grep -v 'grep' | grep -v 'rpm' | grep -v 'dlogutil' | awk '{print $1}'`
        if [ x"$PID" != x"" ]; then
-               aul_test term_pid $PID
+               KIL=`kill -9 $PID 2>&1 > /dev/null`
+               KIL_RET=$?
+               if [ $KIL_RET -ne 0 ]; then
+                       echo "Data provider is already stopped ($KIL_RET)"
+               fi
                sleep 1
        fi
 }
index 44dafbc..89684e8 100644 (file)
@@ -1,3 +1,10 @@
+data-provider-master (0.4.0) unstable; urgency=low
+
+  * Git: slp/pkgs/d/data-provider-master
+  * Tag: data-provider-master_0.4.0
+
+ -- Sung-jae Park <nicesj.park@samsung.com>  Sat, 16 Jun 2012 22:37:22 +0900
+
 data-provider-master (0.3.2) unstable; urgency=low
 
   * Git: slp/pkgs/d/data-provider-master
index e0d8eda..071c076 100644 (file)
@@ -1,3 +1,4 @@
-/opt/apps/com.samsung.data-provider-master/*
-/opt/share/applications/*
+#/opt/apps/com.samsung.data-provider-master/*
+#/opt/share/applications/*
+/usr/bin/data-provider-master
 /etc/rc.d/init.d/data-provider-master
index 2a86c7d..a3695c1 100755 (executable)
@@ -4,11 +4,11 @@ mkdir -p /opt/share/live_magazine/log
 chown 5000:5000 /opt/share/live_magazine
 chown 5000:5000 /opt/share/live_magazine/log
 
-if [ -f "/etc/rc.d/rc3.d/S41data-provider-master" ]; then
-       rm -f /etc/rc.d/rc3.d/S41data-provider-master
-fi
+#if [ -f "/etc/rc.d/rc3.d/S41data-provider-master" ]; then
+#      rm -f /etc/rc.d/rc3.d/S41data-provider-master
+#fi
 
-ln -sf /etc/rc.d/init.d/data-provider-master /etc/rc.d/rc3.d/S41data-provider-master
+ln -sf /etc/rc.d/init.d/data-provider-master /etc/rc.d/rc3.d/S99data-provider-master
 
 TMP=`which ps`
 if [ $? -ne 0 ]; then
@@ -22,12 +22,12 @@ if [ $? -ne 0 ]; then
        exit 0
 fi
 
-PID=`ps ax | grep 'data-provider-master' | grep -v 'grep' | grep -v 'dpkg' | grep -v 'dlogutil' | awk '{print $1}'`
-if [ x"$PID" != x"" ]; then
-       aul_test term_pid $PID
-       sleep 1
-fi
+#PID=`ps ax | grep 'data-provider-master' | grep -v 'grep' | grep -v 'rpm' | grep -v 'dpkg' | grep -v 'dlogutil' | awk '{print $1}'`
+#if [ x"$PID" != x"" ]; then
+#      aul_test term_pid $PID
+#      sleep 1
+#fi
 
-aul_test launch com.samsung.data-provider-master
+#aul_test launch com.samsung.data-provider-master
 
 # End of a file
similarity index 100%
rename from src/dbus.c
rename to deprecated/comm/dbus.c
similarity index 100%
rename from include/dbus.h
rename to deprecated/comm/dbus.h
index 48b56c2..1d42448 100644 (file)
@@ -22,20 +22,20 @@ extern int client_destroy(struct client_node *client);
  */
 extern struct client_node *client_ref(struct client_node *client);
 extern struct client_node *client_unref(struct client_node *client);
-extern int client_refcnt(struct client_node *client);
+extern const int const client_refcnt(const struct client_node *client);
 
 /*!
  * \note
  * Information of client PID
  */
-extern pid_t client_pid(struct client_node *client);
+extern const pid_t const client_pid(const struct client_node *client);
 extern struct client_node *client_find_by_pid(pid_t pid);
 
 /*!
  * \note
  * Statistics for state of client
  */
-extern int const client_count_paused(void);
+extern const int const client_count_paused(void);
 extern int client_is_all_paused(void);
 extern int client_count(void);
 
@@ -46,9 +46,9 @@ extern int client_count(void);
 extern int client_deactivated_by_fault(struct client_node *client);
 extern int client_fault(struct client_node *client);
 extern void client_reset_fault(struct client_node *client);
-extern int client_is_faulted(struct client_node *client);
+extern const int const client_is_faulted(const struct client_node *client);
 
-extern int client_is_activated(struct client_node *client);
+extern const int const client_is_activated(const struct client_node *client);
 
 /*!
  * \note
index 348280f..cae33b3 100644 (file)
@@ -1,20 +1,14 @@
 /*!
  */
-extern int client_rpc_async_request(struct client_node *client, const char *funcname, GVariant *param);
-extern int client_rpc_sync_request(struct client_node *client, const char *funcname, GVariant *param);
-extern int client_rpc_broadcast(const char *funcname, GVariant *param);
+extern int client_rpc_async_request(struct client_node *client, struct packet *packet);
+extern int client_rpc_broadcast(struct packet *packet);
 
 /*!
  */
-extern int client_rpc_update_proxy(struct client_node *client, GDBusProxy *proxy);
-extern int client_rpc_reset_proxy(struct client_node *client);
+extern struct client_node *client_rpc_find_by_handle(int handle);
 
 /*!
  */
-extern struct client_node *client_rpc_find_by_proxy(GDBusProxy *proxy);
-
-/*!
- */
-extern int client_rpc_initialize(struct client_node *client);
+extern int client_rpc_initialize(struct client_node *client, int handle);
 
 /* End of a file */
diff --git a/include/connector.h b/include/connector.h
new file mode 100644 (file)
index 0000000..1fbc8fb
--- /dev/null
@@ -0,0 +1,14 @@
+enum connector_event_type {
+       CONNECTOR_CONNECTED,
+       CONNECTOR_DISCONNECTED,
+};
+
+extern int connector_server_create(const char *addr, int is_sync, int (*service_cb)(int fd, int readsize, void *data), void *data);
+extern int connector_client_create(const char *addr, int is_sync, int (*service_cb)(int fd, int readsize, void *data), void *data);
+extern int connector_server_destroy(int handle);
+extern int connector_client_destroy(int handle);
+
+extern int connector_add_event_callback(enum connector_event_type type, int (*service_cb)(int handle, void *data), void *data);
+extern void *connector_del_event_callback(enum connector_event_type type, int (*service_cb)(int handle, void *data), void *data);
+
+/* End of a file */
diff --git a/include/connector_packet.h b/include/connector_packet.h
new file mode 100644 (file)
index 0000000..12b4c49
--- /dev/null
@@ -0,0 +1,15 @@
+struct method {
+       const char *cmd;
+       struct packet *(*handler)(pid_t pid, int handle, struct packet *packet);
+};
+
+extern int connector_packet_async_send(int handle, struct packet *packet, int (*recv_cb)(pid_t, int handle, const struct packet *packet, void *data), void *data);
+extern int connector_packet_send_only(int handle, struct packet *packet);
+extern struct packet *connector_packet_oneshot_send(const char *addr, struct packet *packet);
+
+extern int connector_packet_client_init(const char *addr, int is_sync, struct method *table);
+extern int connector_packet_client_fini(int handle);
+extern int connector_packet_server_init(const char *addr, struct method *table);
+extern int connector_packet_server_fini(int handle);
+
+/* End of a file */
index 597acf6..340ac37 100644 (file)
@@ -1,10 +1,10 @@
 #if !defined(FLOG)
-#define DbgPrint(format, arg...)       LOGD("[\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
-#define ErrPrint(format, arg...)       LOGE("[\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
+#define DbgPrint(format, arg...)       LOGD("[\e[32m%s/%s\e[0m:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg)
+#define ErrPrint(format, arg...)       LOGE("[\e[32m%s/%s\e[0m:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg)
 #else
 extern FILE *__file_log_fp;
-#define DbgPrint(format, arg...) do { fprintf(__file_log_fp, "[LOG] [\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0)
+#define DbgPrint(format, arg...) do { fprintf(__file_log_fp, "[LOG] [\e[32m%s/%s\e[0m:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0)
 
-#define ErrPrint(format, arg...) do { fprintf(__file_log_fp, "[ERR] [\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0)
+#define ErrPrint(format, arg...) do { fprintf(__file_log_fp, "[ERR] [\e[32m%s/%s\e[0m:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0)
 #endif
 /* End of a file */
diff --git a/include/dlist.h b/include/dlist.h
new file mode 100644 (file)
index 0000000..5c583e6
--- /dev/null
@@ -0,0 +1,27 @@
+#define dlist_remove_data(list, data) do { \
+       struct dlist *l; \
+       l = dlist_find_data(list, data); \
+       list = dlist_remove(list, l); \
+} while (0)
+
+#define dlist_foreach(list, l, data) \
+       for ((l) = (list); (l) && ((data) = dlist_data(l)); (l) = dlist_next(l))
+
+#define dlist_foreach_safe(list, l, n, data) \
+       for ((l) = (list), (n) = dlist_next(l); \
+               (l) && ((data) = dlist_data(l)); \
+               (l) = (n), (n) = dlist_next(l))
+
+struct dlist;
+
+extern struct dlist *dlist_append(struct dlist *list, void *data);
+extern struct dlist *dlist_prepend(struct dlist *list, void *data);
+extern struct dlist *dlist_remove(struct dlist *list, struct dlist *l);
+extern struct dlist *dlist_find_data(struct dlist *list, void *data);
+extern void *dlist_data(struct dlist *l);
+extern struct dlist *dlist_next(struct dlist *l);
+extern struct dlist *dlist_prev(struct dlist *l);
+extern int dlist_count(struct dlist *l);
+extern struct dlist *dlist_nth(struct dlist *l, int nth);
+
+/* End of a file */
index fb646f3..4680e3b 100644 (file)
@@ -104,6 +104,7 @@ extern int instance_deactivate(struct inst_info *inst);
 extern int instance_reactivate(struct inst_info *inst);
 extern int instance_activate(struct inst_info *inst);
 extern void instance_recover_state(struct inst_info *inst);
+extern int instance_need_slave(struct inst_info *inst);
 extern void instance_faulted(struct inst_info *inst);
 
 extern void instance_set_lb_info(struct inst_info *inst, int w, int h, double priority);
@@ -125,23 +126,23 @@ extern int instance_change_group(struct inst_info *inst, const char *cluster, co
  * \note
  * getter
  */
-extern double const instance_timestamp(struct inst_info *inst);
-extern struct pkg_info * const instance_package(struct inst_info *inst);
-extern struct script_info * const instance_lb_handle(struct inst_info *inst);
-extern struct script_info * const instance_pd_handle(struct inst_info *inst);
-extern char * const instance_id(struct inst_info *inst);
-extern char * const instance_content(struct inst_info *inst);
-extern char * const instance_category(struct inst_info *inst);
-extern char * const instance_cluster(struct inst_info *inst);
-extern int const instance_auto_launch(struct inst_info *inst);
-extern int const instance_priority(struct inst_info *inst);
-extern struct client_node * const instance_client(struct inst_info *inst);
-extern double const instance_period(struct inst_info *inst);
-extern int const instance_lb_width(struct inst_info *inst);
-extern int const instance_lb_height(struct inst_info *inst);
-extern int const instance_pd_width(struct inst_info *inst);
-extern int const instance_pd_height(struct inst_info *inst);
-extern enum instance_state const instance_state(struct inst_info *inst);
+extern const double const instance_timestamp(const struct inst_info *inst);
+extern const struct pkg_info * const instance_package(const struct inst_info *inst);
+extern struct script_info * const instance_lb_handle(const struct inst_info *inst);
+extern struct script_info * const instance_pd_handle(const struct inst_info *inst);
+extern const char * const instance_id(const struct inst_info *inst);
+extern const char * const instance_content(const struct inst_info *inst);
+extern const char * const instance_category(const struct inst_info *inst);
+extern const char * const instance_cluster(const struct inst_info *inst);
+extern const int const instance_auto_launch(const struct inst_info *inst);
+extern const int const instance_priority(const struct inst_info *inst);
+extern const struct client_node * const instance_client(const struct inst_info *inst);
+extern const double const instance_period(const struct inst_info *inst);
+extern const int const instance_lb_width(const struct inst_info *inst);
+extern const int const instance_lb_height(const struct inst_info *inst);
+extern const int const instance_pd_width(const struct inst_info *inst);
+extern const int const instance_pd_height(const struct inst_info *inst);
+extern const enum instance_state const instance_state(const struct inst_info *inst);
 
 /*!
  * event
index a8b7f2c..bf5e8a1 100644 (file)
@@ -32,23 +32,23 @@ extern int package_get_fault_info(struct pkg_info *info, double *timestmap, cons
  * \brief
  * Readonly functions
  */
-extern int const package_is_fault(struct pkg_info *info);
-extern struct slave_node * const package_slave(struct pkg_info *info);
-extern int const package_timeout(struct pkg_info *info);
-extern double const package_period(struct pkg_info *info);
-extern int const package_secured(struct pkg_info *info);
-extern const char * const package_script(struct pkg_info *info);
-extern const char * const package_abi(struct pkg_info *info);
-extern const char * const package_lb_path(struct pkg_info *info);
-extern const char * const package_lb_group(struct pkg_info *info);
-extern const char * const package_pd_path(struct pkg_info *info);
-extern const char * const package_pd_group(struct pkg_info *info);
-extern int const package_pinup(struct pkg_info *info);
-extern int const package_auto_launch(struct pkg_info *info);
-extern unsigned int const package_size_list(struct pkg_info *info);
-extern int const package_pd_width(struct pkg_info *info);
-extern int const package_pd_height(struct pkg_info *info);
-extern const char * const package_name(struct pkg_info *info);
+extern const int const package_is_fault(const struct pkg_info *info);
+extern struct slave_node * const package_slave(const struct pkg_info *info);
+extern const int const package_timeout(const struct pkg_info *info);
+extern const double const package_period(const struct pkg_info *info);
+extern const int const package_secured(const struct pkg_info *info);
+extern const char * const package_script(const struct pkg_info *info);
+extern const char * const package_abi(const struct pkg_info *info);
+extern const char * const package_lb_path(const struct pkg_info *info);
+extern const char * const package_lb_group(const struct pkg_info *info);
+extern const char * const package_pd_path(const struct pkg_info *info);
+extern const char * const package_pd_group(const struct pkg_info *info);
+extern const int const package_pinup(const struct pkg_info *info);
+extern const int const package_auto_launch(const struct pkg_info *info);
+extern const unsigned int const package_size_list(const struct pkg_info *info);
+extern const int const package_pd_width(const struct pkg_info *info);
+extern const int const package_pd_height(const struct pkg_info *info);
+extern const char * const package_name(const struct pkg_info *info);
 
 /*!
  * \brief
@@ -56,10 +56,10 @@ extern const char * const package_name(struct pkg_info *info);
  */
 extern struct pkg_info * const package_ref(struct pkg_info *info);
 extern struct pkg_info * const package_unref(struct pkg_info *info);
-extern int const package_refcnt(struct pkg_info *info);
+extern const int const package_refcnt(const struct pkg_info *info);
 
-extern enum pd_type package_pd_type(struct pkg_info *info);
-extern enum lb_type package_lb_type(struct pkg_info *info);
+extern const enum pd_type const package_pd_type(const struct pkg_info *info);
+extern const enum lb_type const package_lb_type(const struct pkg_info *info);
 
 extern int package_add_instance(struct pkg_info *info, struct inst_info *inst);
 extern int package_del_instance(struct pkg_info *info, struct inst_info *inst);
diff --git a/include/packet.h b/include/packet.h
new file mode 100644 (file)
index 0000000..475c4be
--- /dev/null
@@ -0,0 +1,32 @@
+
+struct packet;
+
+enum packet_type {
+       PACKET_REQ,
+       PACKET_ACK,
+       PACKET_REQ_NOACK,
+};
+
+#define PACKET_VERSION 1
+#define PACKET_MAX_CMD 24
+
+extern struct packet *packet_create(const char *command, const char *fmt, ...);
+extern struct packet *packet_create_noack(const char *command, const char *fmt, ...);
+extern struct packet *packet_create_reply(struct packet *packet, const char *fmt, ...);
+extern int packet_get(const struct packet *packet, const char *fmt, ...);
+extern int packet_destroy(struct packet *packet);
+extern struct packet *packet_ref(struct packet *packet);
+extern struct packet *packet_unref(struct packet *packet);
+
+extern const void * const packet_data(const struct packet *packet);
+extern const unsigned long const packet_seq(const struct packet *packet);
+extern const enum packet_type const packet_type(const struct packet *packet);
+extern const int const packet_version(const struct packet *packet);
+extern const int const packet_payload_size(const struct packet *packet);
+extern const char * const packet_command(const const struct packet *packet);
+extern const int const packet_header_size(void);
+extern const int const packet_size(const struct packet *packet);
+
+extern struct packet *packet_build(struct packet *packet, int offset, void *data, int size);
+
+/* End of a file */
diff --git a/include/secom_socket.h b/include/secom_socket.h
new file mode 100644 (file)
index 0000000..cf994de
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * com.samsung.live-magazine
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sung-jae Park <nicesj.park@samsung.com>, Youngjoo Park <yjoo93.park@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+/*
+ * Create client connection
+ */
+extern int secom_create_client(const char *peer);
+
+/*
+ * Create server connection
+ */
+extern int secom_create_server(const char *peer);
+
+/*
+ * Get the raw handle to use it for non-blocking mode.
+ */
+extern int secom_get_connection_handle(int server_handle);
+extern int secom_put_connection_handle(int conn_handle);
+
+/*
+ * Send data to the connected peer.
+ */
+extern int secom_send(int conn, const char *buffer, int size);
+
+/*
+ * Recv data from the connected peer. and its PID value
+ */
+extern int secom_recv(int conn, char *buffer, int size, int *sender_pid);
+
+/*
+ * Destroy a connection
+ */
+extern int secom_destroy(int conn);
+
+/* End of a file */
diff --git a/include/server.h b/include/server.h
new file mode 100644 (file)
index 0000000..d58e848
--- /dev/null
@@ -0,0 +1,4 @@
+extern int server_init(void);
+extern int server_fini(void);
+
+/* End of a file */
index b407432..0e9c004 100644 (file)
@@ -14,7 +14,7 @@ enum slave_event {
 
 extern struct slave_node *slave_ref(struct slave_node *slave);
 extern struct slave_node *slave_unref(struct slave_node *slave);
-extern int const slave_refcnt(struct slave_node *slave);
+extern const int const slave_refcnt(struct slave_node *slave);
 
 /*!
  * Create a new slave object or destroy it
@@ -31,7 +31,7 @@ extern int slave_deactivate(struct slave_node *slave);
 /*!
  * To check the slave's activation state
  */
-extern int slave_is_activated(struct slave_node *slave);
+extern const int const slave_is_activated(struct slave_node *slave);
 extern int slave_activated(struct slave_node *slave);
 
 /*!
@@ -48,16 +48,16 @@ extern void *slave_data(struct slave_node *slave, const char *tag);
 
 extern void slave_faulted(struct slave_node *slave);
 extern void slave_reset_fault(struct slave_node *slave);
-extern int const slave_is_faulted(struct slave_node *slave);
+extern const int const slave_is_faulted(const struct slave_node *slave);
 
 extern struct slave_node *slave_find_by_pid(pid_t pid);
 extern struct slave_node *slave_find_by_name(const char *name);
 
 extern void slave_dead_handler(struct slave_node *slave);
 extern void slave_check_pause_or_resume(void);
-extern int const slave_is_secured(struct slave_node *slave);
-extern const char * const slave_name(struct slave_node *slave);
-extern pid_t const slave_pid(struct slave_node *slave);
+extern const int const slave_is_secured(const struct slave_node *slave);
+extern const char * const slave_name(const struct slave_node *slave);
+extern const pid_t const slave_pid(const struct slave_node *slave);
 
 /*!
  * \note
index 0366d4e..fbd1a34 100644 (file)
@@ -1,19 +1,12 @@
-extern int slave_rpc_async_request(struct slave_node *slave,
-                       const char *pkgname, const char *filename,
-                       const char *cmd, GVariant *param, void (*ret_cb)(struct slave_node *slave, const char *func, GVariant *result, void *data),
-                       void *data);
-
-extern int slave_rpc_sync_request(struct slave_node *slave,
-                       const char *pkgname, const char *filename,
-                       const char *cmd, GVariant *param);
+extern int slave_rpc_async_request(struct slave_node *slave, const char *pkgname, struct packet *packet, void (*ret_cb)(struct slave_node *slave, const struct packet *packet, void *data), void *data);
 
+extern int slave_rpc_update_handle(struct slave_node *slave, int handle);
 extern int slave_rpc_pause_all(void);
 extern int slave_rpc_resume_all(void);
 extern int slave_rpc_ping(struct slave_node *slave);
-extern int slave_rpc_update_proxy(struct slave_node *slave, GDBusProxy *proxy);
-extern int slave_rpc_reset_proxy(struct slave_node *slave);
 extern void slave_rpc_clear_request_by_slave(struct slave_node *slave);
 extern void slave_rpc_request_update(const char *pkgname, const char *cluster, const char *category);
+extern struct slave_node *slave_rpc_find_by_handle(int handle);
 
 extern int slave_rpc_initialize(struct slave_node *slave);
 
index 8c38c1a..389195a 100644 (file)
@@ -4,5 +4,6 @@ extern int util_check_ext(const char *filename, const char *check_ptr);
 extern int util_validate_livebox_package(const char *pkgname);
 extern int util_unlink(const char *filename);
 extern char *util_slavename(void);
+extern const char *util_basename(const char *name);
 
 /* End of a file */
index 002e12a..22c64bf 100644 (file)
@@ -1,6 +1,6 @@
 Name: com.samsung.data-provider-master
 Summary: Master data provider
-Version: 0.3.2
+Version: 0.4.0
 Release: 1
 Group: main/app
 License: Samsung Proprietary License
@@ -45,7 +45,7 @@ chown 5000:5000 /opt/share/live_magazine/log
 #      rm -f /etc/rc.d/rc3.d/S41data-provider-master
 #fi
 
-#ln -sf /etc/rc.d/init.d/data-provider-master /etc/rc.d/rc3.d/S41data-provider-master
+ln -sf /etc/rc.d/init.d/data-provider-master /etc/rc.d/rc3.d/S99data-provider-master
 
 TMP=`which ps`
 if [ $? -ne 0 ]; then
@@ -80,6 +80,7 @@ done
 %files -n com.samsung.data-provider-master
 #%manifest com.samsung.data-provider-master.manifest
 %defattr(-,root,root,-)
-/opt/apps/com.samsung.data-provider-master/bin/data-provider-master
-/opt/share/applications/com.samsung.data-provider-master.desktop
+#/opt/apps/com.samsung.data-provider-master/bin/data-provider-master
+#/opt/share/applications/com.samsung.data-provider-master.desktop
 /etc/rc.d/init.d/data-provider-master
+/usr/bin/data-provider-master
index 874b448..787eea9 100644 (file)
@@ -1,15 +1,15 @@
 #include <stdio.h>
-#include <libgen.h>
 #include <errno.h>
 
 #include <Eina.h>
 
 #include <dlog.h>
-#include <gio/gio.h>
 
+#include "packet.h"
 #include "client_life.h"
 #include "client_rpc.h"
 #include "debug.h"
+#include "util.h"
 
 int errno;
 
@@ -133,6 +133,7 @@ static inline struct client_node *create_client_data(pid_t pid)
        }
 
        client->pid = pid;
+       client->refcnt = 1;
 
        s_info.client_list = eina_list_append(s_info.client_list, client);
        return client;
@@ -154,9 +155,6 @@ struct client_node *client_create(pid_t pid)
                return NULL;
        }
 
-       client_ref(client);
-       client_rpc_initialize(client);
-
        invoke_global_create_cb(client);
        return client;
 }
@@ -195,12 +193,12 @@ struct client_node *client_unref(struct client_node *client)
        return client;
 }
 
-int client_refcnt(struct client_node *client)
+const int const client_refcnt(const struct client_node *client)
 {
        return client->refcnt;
 }
 
-pid_t client_pid(struct client_node *client)
+const pid_t const client_pid(const struct client_node *client)
 {
        return client ? client->pid : (pid_t)-1;
 }
@@ -218,7 +216,7 @@ struct client_node *client_find_by_pid(pid_t pid)
        return NULL;
 }
 
-int const client_count_paused(void)
+const int const client_count_paused(void)
 {
        return s_info.nr_of_paused_clients;
 }
@@ -260,7 +258,6 @@ int client_deactivated_by_fault(struct client_node *client)
        client->faulted = 1;
 
        client->pid = (pid_t)-1;
-       client_rpc_reset_proxy(client);
 
        invoke_deactivated_cb(client);
        client_destroy(client);
@@ -276,7 +273,6 @@ int client_fault(struct client_node *client)
        client->faulted = 1;
 
        client->pid = (pid_t)-1;
-       client_rpc_reset_proxy(client);
 
        invoke_deactivated_cb(client);
        client_destroy(client);
@@ -290,7 +286,7 @@ int client_fault(struct client_node *client)
        return 0;
 }
 
-int client_is_faulted(struct client_node *client)
+const int const client_is_faulted(const struct client_node *client)
 {
        /*!
         * \note
@@ -459,7 +455,7 @@ int client_fini(void)
        return 0;
 }
 
-int client_is_activated(struct client_node *client)
+const int const client_is_activated(const struct client_node *client)
 {
        return client ? (client->pid != (pid_t)-1) : 1;
 }
index 5b605f0..eb19900 100644 (file)
 #include <stdio.h>
-#include <libgen.h>
 #include <errno.h>
 
 #include <Eina.h>
 #include <Ecore.h>
 
-#include <gio/gio.h>
 #include <dlog.h>
 
+#include "connector_packet.h"
+#include "packet.h"
 #include "client_life.h"
 #include "client_rpc.h"
 #include "debug.h"
 #include "conf.h"
+#include "util.h"
 
 /*!
  * \note
  * Static component information structure.
  */
 static struct info {
-       Eina_List *packet_list; /*!< Packet Q: Before sending the request, all request packets will stay here */
-       Ecore_Timer *packet_consumer; /*!< This timer will consuming the packet Q. sending them to the specified client */
+       Eina_List *command_list; /*!< Packet Q: Before sending the request, all request commands will stay here */
+       Ecore_Timer *command_consumer; /*!< This timer will consuming the command Q. sending them to the specified client */
        Eina_List *rpc_list; /*!< Create RPC object list, to find a client using given RPC info (such as GDBusConnection*, GDBusProxy*) */
 } s_info = {
-       .packet_list = NULL,
-       .packet_consumer = NULL,
+       .command_list = NULL,
+       .command_consumer = NULL,
        .rpc_list = NULL,
 };
 
 struct client_rpc {
-       GDBusProxy *proxy; /*!< Proxy object for this client */
-       Eina_List *pending_request_list; /*!< Before making connection, this Q will be used for keeping the request packets */
+       int handle; /*!< Handler for communication with client */
        struct client_node *client; /*!< client_life object */
 };
 
-struct packet {
-       char *funcname; /*!< Method name which is supported by the livebox-viewer/dbus.c */
-       GVariant *param; /*!< Parameter object */
-       struct client_node *client; /*!< Target client. who should receive this packet */
+struct command {
+       struct packet *packet;
+       struct client_node *client; /*!< Target client. who should receive this command */
 };
 
 /*!
  * \brief
- * Creating or Destroying packet object
+ * Creating or Destroying command object
  */
-static inline struct packet *create_packet(struct client_node *client, const char *func, GVariant *param)
+static inline struct command *create_command(struct client_node *client, struct packet *packet)
 {
-       struct packet *packet;
+       struct command *command;
 
-       packet = calloc(1, sizeof(*packet));
-       if (!packet) {
+       command = calloc(1, sizeof(*command));
+       if (!command) {
                ErrPrint("Heap: %s\n", strerror(errno));
                return NULL;
        }
 
-       packet->funcname = strdup(func);
-       if (!packet->funcname) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               free(packet);
-               return NULL;
-       }
+       command->packet = packet_ref(packet);
+       command->client = client_ref(client);
 
-       packet->param = g_variant_ref(param);
-       packet->client = client_ref(client);
-
-       return packet;
+       return command;
 }
 
-static inline void destroy_packet(struct packet *packet)
+static inline void destroy_command(struct command *command)
 {
-       client_unref(packet->client);
-       free(packet->funcname);
-       g_variant_unref(packet->param);
-       free(packet);
+       client_unref(command->client);
+       packet_unref(command->packet);
+       free(command);
 }
 
-static inline int count_packet(void)
+static inline int count_command(void)
 {
-       return eina_list_count(s_info.packet_list);
+       return eina_list_count(s_info.command_list);
 }
 
-/*!
- */
-static void client_cmd_done(GDBusProxy *proxy, GAsyncResult *res, void *item)
+static int recv_cb(pid_t pid, int handle, const struct packet *packet, void *data)
 {
-       GVariant *result;
-       GError *err = NULL;
-       struct packet *packet = item;
-
-       result = g_dbus_proxy_call_finish(proxy, res, &err);
-       if (result) {
-               int ret;
+       struct command *command = data;
 
-               g_variant_get(result, "(i)", &ret);
-               g_variant_unref(result);
+       if (!packet) {
+               DbgPrint("Client fault?\n");
+               client_fault(command->client);
        } else {
-               if (err) {
-                       ErrPrint("Error: %s\n", err->message);
-                       g_error_free(err);
-               }
+               int ret;
 
-               client_fault(packet->client);
+               packet_get(packet, "i", &ret);
+               DbgPrint("returns %d\n", ret);
        }
 
-       destroy_packet(packet);
+       destroy_command(command);
+       return 0;
 }
 
-static inline struct packet *pop_packet(void)
+static inline struct command *pop_command(void)
 {
-       struct packet *packet;
+       struct command *command;
 
-       packet = eina_list_nth(s_info.packet_list, 0);
-       if (!packet)
+       command = eina_list_nth(s_info.command_list, 0);
+       if (!command)
                return NULL;
 
-       s_info.packet_list = eina_list_remove(s_info.packet_list, packet);
-       return packet;
+       s_info.command_list = eina_list_remove(s_info.command_list, command);
+       return command;
 }
 
-static Eina_Bool packet_consumer_cb(void *data)
+static Eina_Bool command_consumer_cb(void *data)
 {
-       struct packet *packet;
+       struct command *command;
        struct client_rpc *rpc;
 
-       packet = pop_packet();
-       if (!packet) {
-               s_info.packet_consumer = NULL;
+       command = pop_command();
+       if (!command) {
+               s_info.command_consumer = NULL;
                return ECORE_CALLBACK_CANCEL;
        }
 
-       if (!client_is_activated(packet->client)) {
-               ErrPrint("Client is not activated, destroy this packet\n");
-               destroy_packet(packet);
+       if (!client_is_activated(command->client)) {
+               ErrPrint("Client is not activated, destroy this command\n");
+               destroy_command(command);
                return ECORE_CALLBACK_RENEW;
        }
 
-       if (client_is_faulted(packet->client)) {
-               ErrPrint("Client is faulted, discard packet\n");
-               destroy_packet(packet);
+       if (client_is_faulted(command->client)) {
+               ErrPrint("Client is faulted, discard command\n");
+               destroy_command(command);
                return ECORE_CALLBACK_RENEW;
        }
 
-       rpc = client_data(packet->client, "rpc");
+       rpc = client_data(command->client, "rpc");
        if (!rpc) {
-               ErrPrint("Invalid packet\n");
-               destroy_packet(packet);
+               ErrPrint("Invalid command\n");
+               destroy_command(command);
                return ECORE_CALLBACK_RENEW;
        }
 
-       g_dbus_proxy_call(rpc->proxy,
-               packet->funcname, packet->param,
-               G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL,
-               (GAsyncReadyCallback)client_cmd_done, packet);
+       DbgPrint("Send a packet to client [%s]\n", packet_command(command->packet));
+       if (connector_packet_async_send(rpc->handle, command->packet, recv_cb, command) < 0)
+               destroy_command(command);
 
        return ECORE_CALLBACK_RENEW;
 }
 
-static inline void push_packet(struct packet *packet)
+static inline void push_command(struct command *command)
 {
-       s_info.packet_list = eina_list_append(s_info.packet_list, packet);
+       s_info.command_list = eina_list_append(s_info.command_list, command);
 
-       if (s_info.packet_consumer)
+       if (s_info.command_consumer)
                return;
 
-       s_info.packet_consumer = ecore_timer_add(PACKET_TIME, packet_consumer_cb, NULL);
-       if (!s_info.packet_consumer) {
-               ErrPrint("Failed to add packet consumer\n");
-               s_info.packet_list = eina_list_remove(s_info.packet_list, packet);
-               destroy_packet(packet);
+       s_info.command_consumer = ecore_timer_add(PACKET_TIME, command_consumer_cb, NULL);
+       if (!s_info.command_consumer) {
+               ErrPrint("Failed to add command consumer\n");
+               s_info.command_list = eina_list_remove(s_info.command_list, command);
+               destroy_command(command);
        }
 }
 
-int client_rpc_async_request(struct client_node *client, const char *funcname, GVariant *param)
+int client_rpc_async_request(struct client_node *client, struct packet *packet)
 {
-       struct packet *packet;
+       struct command *command;
        struct client_rpc *rpc;
 
        if (client_is_faulted(client)) {
                ErrPrint("Client is faulted\n");
-               g_variant_unref(param);
+               packet_unref(packet);
                return -EFAULT;
        }
 
        rpc = client_data(client, "rpc");
        if (!rpc) {
-               ErrPrint("Client rpc data is not valid (%s)\n", funcname);
-               g_variant_unref(param);
+               ErrPrint("Client rpc data is not valid (%s)\n", packet_command(packet));
+               packet_unref(packet);
                return -EINVAL;
        }
 
-       packet = create_packet(client, funcname, param);
-       if (!packet) {
-               g_variant_unref(param);
+       command = create_command(client, packet);
+       if (!command) {
+               packet_unref(packet);
                return -ENOMEM;
        }
 
-       if (!rpc->proxy)
-               rpc->pending_request_list = eina_list_append(rpc->pending_request_list, packet);
-       else
-               push_packet(packet);
-
+       push_command(command);
+       packet_unref(packet);
        return 0;
 }
 
-int client_rpc_broadcast(const char *funcname, GVariant *param)
+int client_rpc_broadcast(struct packet *packet)
 {
        Eina_List *l;
        struct client_rpc *rpc;
 
        EINA_LIST_FOREACH(s_info.rpc_list, l, rpc) {
-               (void)client_rpc_async_request(rpc->client, funcname, g_variant_ref(param));
-       }
-
-       g_variant_unref(param);
-       return 0;
-}
-
-int client_rpc_sync_request(struct client_node *client, const char *funcname, GVariant *param)
-{
-       struct client_rpc *rpc;
-       GError *err;
-       GVariant *result;
-       int ret;
-
-       if (!client_is_activated(client)) {
-               ErrPrint("Client is not activated (%s)\n", funcname);
-               g_variant_unref(param);
-               return -EINVAL;
-       }
-
-       if (client_is_faulted(client)) {
-               ErrPrint("Client is faulted\n");
-               g_variant_unref(param);
-               return -EFAULT;
-       }
-
-       rpc = client_data(client, "rpc");
-       if (!rpc) {
-               ErrPrint("Client has no \"rpc\" info (%s)\n", funcname);
-               g_variant_unref(param);
-               return -EINVAL;
-       }
-
-       if (!rpc->proxy) {
-               ErrPrint("Client is not ready to communicate (%s)\n", funcname);
-               g_variant_unref(param);
-               return -EINVAL;
-       }
-
-       err = NULL;
-       result = g_dbus_proxy_call_sync(rpc->proxy, funcname, param,
-                               G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &err);
-
-       if (!result) {
-               if (err) {
-                       ErrPrint("(%s) Error: %s\n", funcname, err->message);
-                       g_error_free(err);
-               }
-
-               client_fault(client);
-               return -EIO;
-       }
-
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
-       return ret;
-}
-
-int client_rpc_reset_proxy(struct client_node *client)
-{
-       struct client_rpc *rpc;
-
-       rpc = client_data(client, "rpc");
-       if (!rpc) {
-               ErrPrint("Client has no rpc info\n");
-               return -EINVAL;
-       }
-
-       rpc->proxy = NULL;
-       return 0;
-}
-
-int client_rpc_update_proxy(struct client_node *client, GDBusProxy *proxy)
-{
-       struct client_rpc *rpc;
-       struct packet *packet;
-
-       rpc = client_data(client, "rpc");
-       if (!rpc) {
-               ErrPrint("Client has no rpc info\n");
-               return -EINVAL;
-       }
-
-       if (rpc->proxy)
-               DbgPrint("Proxy is overwritten\n");
-
-       rpc->proxy = proxy;
-
-       EINA_LIST_FREE(rpc->pending_request_list, packet) {
-               push_packet(packet);
+               (void)client_rpc_async_request(rpc->client, packet_ref(packet));
        }
 
+       packet_unref(packet);
        return 0;
 }
 
 static int deactivated_cb(struct client_node *client, void *data)
 {
        struct client_rpc *rpc;
-       struct packet *packet;
+       struct command *command;
 
        rpc = client_data(client, "rpc");
        if (!rpc) {
@@ -314,16 +205,8 @@ static int deactivated_cb(struct client_node *client, void *data)
                return 0;
        }
 
-       if (!rpc->proxy) {
-               ErrPrint("RPC has no proxy\n");
-               return 0;
-       }
-
-       g_object_unref(rpc->proxy);
-       rpc->proxy = NULL;
-
-       while ((packet = pop_packet()))
-               destroy_packet(packet);
+       while ((command = pop_command()))
+               destroy_command(command);
 
        return 0;
 }
@@ -331,7 +214,6 @@ static int deactivated_cb(struct client_node *client, void *data)
 static int del_cb(struct client_node *client, void *data)
 {
        struct client_rpc *rpc;
-       struct packet *packet;
 
        rpc = client_del_data(client, "rpc");
        if (!rpc) {
@@ -340,21 +222,13 @@ static int del_cb(struct client_node *client, void *data)
        }
 
        s_info.rpc_list = eina_list_remove(s_info.rpc_list, rpc);
-
-       EINA_LIST_FREE(rpc->pending_request_list, packet) {
-               destroy_packet(packet);
-       }
-
-       if (rpc->proxy)
-               g_object_unref(rpc->proxy);
-
        free(rpc);
 
        client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, deactivated_cb, NULL);
        return -1; /* Return <0, Delete this callback */
 }
 
-int client_rpc_initialize(struct client_node *client)
+int client_rpc_initialize(struct client_node *client, int handle)
 {
        struct client_rpc *rpc;
        int ret;
@@ -372,6 +246,8 @@ int client_rpc_initialize(struct client_node *client)
                return ret;
        }
 
+       rpc->handle = handle;
+
        client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, deactivated_cb, NULL);
        client_event_callback_add(client, CLIENT_EVENT_DESTROY, del_cb, NULL);
        rpc->client = client;
@@ -380,13 +256,13 @@ int client_rpc_initialize(struct client_node *client)
        return 0;
 }
 
-struct client_node *client_rpc_find_by_proxy(GDBusProxy *proxy)
+struct client_node *client_rpc_find_by_handle(int handle)
 {
        Eina_List *l;
        struct client_rpc *rpc;
 
        EINA_LIST_FOREACH(s_info.rpc_list, l, rpc) {
-               if (rpc->proxy != proxy)
+               if (rpc->handle != handle)
                        continue;
 
                return rpc->client;
diff --git a/src/connector.c b/src/connector.c
new file mode 100644 (file)
index 0000000..9b592c4
--- /dev/null
@@ -0,0 +1,316 @@
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+
+#include <glib.h>
+
+#include <dlog.h>
+
+#include "dlist.h"
+#include "secom_socket.h"
+#include "packet.h"
+#include "debug.h"
+#include "connector.h"
+#include "util.h"
+
+static struct {
+       struct dlist *conn_cb_list;
+       struct dlist *disconn_cb_list;
+} s_info = {
+       .conn_cb_list = NULL,
+       .disconn_cb_list = NULL,
+};
+
+struct cbdata {
+       int (*service_cb)(int fd, int readsize, void *data);
+       void *data;
+};
+
+struct evtdata {
+       int (*evt_cb)(int fd, void *data);
+       void *data;
+};
+
+static inline void invoke_con_cb_list(int handle)
+{
+       struct dlist *l;
+       struct dlist *n;
+       struct evtdata *cbdata;
+
+       dlist_foreach_safe(s_info.conn_cb_list, l, n, cbdata) {
+               if (cbdata->evt_cb(handle, cbdata->data) < 0) {
+                       s_info.conn_cb_list = dlist_remove(s_info.conn_cb_list, l);
+                       free(cbdata);
+               }
+       }
+}
+
+static inline void invoke_disconn_cb_list(int handle)
+{
+       struct dlist *l;
+       struct dlist *n;
+       struct evtdata *cbdata;
+
+       dlist_foreach_safe(s_info.disconn_cb_list, l, n, cbdata) {
+               if (cbdata->evt_cb(handle, cbdata->data) < 0) {
+                       s_info.disconn_cb_list = dlist_remove(s_info.disconn_cb_list, l);
+                       free(cbdata);
+               }
+       }
+}
+
+static gboolean client_cb(GIOChannel *src, GIOCondition cond, gpointer data)
+{
+       int client_fd;
+       struct cbdata *cbdata = data;
+       int ret;
+       int readsize;
+
+       client_fd = g_io_channel_unix_get_fd(src);
+
+       if (!(cond & G_IO_IN)) {
+               DbgPrint("Client is disconencted\n");
+               invoke_disconn_cb_list(client_fd);
+               secom_put_connection_handle(client_fd);
+               return FALSE;
+       }
+
+       if (ioctl(client_fd, FIONREAD, &readsize) < 0 || readsize == 0) {
+               DbgPrint("Client is disconencted (readsize: %d)\n", readsize);
+               invoke_disconn_cb_list(client_fd);
+               secom_put_connection_handle(client_fd);
+               return FALSE;
+       }
+
+       ret = cbdata->service_cb(client_fd, readsize, cbdata->data);
+       if (ret < 0) {
+               DbgPrint("service callback returns < 0\n");
+               invoke_disconn_cb_list(client_fd);
+               secom_put_connection_handle(client_fd);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+static gboolean accept_cb(GIOChannel *src, GIOCondition cond, gpointer data)
+{
+       int socket_fd;
+       int client_fd;
+       GIOChannel *gio;
+       guint id;
+
+       socket_fd = g_io_channel_unix_get_fd(src);
+       if (!(cond & G_IO_IN)) {
+               ErrPrint("Accept socket closed\n");
+               free(data);
+               return FALSE;
+       }
+
+       client_fd = secom_get_connection_handle(socket_fd);
+       if (client_fd < 0) {
+               free(data);
+               return FALSE;
+       }
+
+       if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0)
+               ErrPrint("Error: %s\n", strerror(errno));
+
+       if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0)
+               ErrPrint("Error: %s\n", strerror(errno));
+
+       gio = g_io_channel_unix_new(client_fd);
+       if (!gio) {
+               ErrPrint("Failed to get gio\n");
+               secom_put_connection_handle(client_fd);
+               free(data);
+               return FALSE;
+       }
+
+       id = g_io_add_watch(gio, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, client_cb, data);
+       if (id < 0) {
+               GError *err = NULL;
+               g_io_channel_unref(gio);
+               g_io_channel_shutdown(gio, TRUE, &err);
+               secom_put_connection_handle(client_fd);
+               free(data);
+               return FALSE;
+       }
+
+       g_io_channel_unref(gio);
+
+       invoke_con_cb_list(client_fd);
+       DbgPrint("New client is connected with %d\n", client_fd);
+       return TRUE;
+}
+
+int connector_server_create(const char *addr, int is_sync, int (*service_cb)(int fd, int readsize, void *data), void *data)
+{
+       GIOChannel *gio;
+       guint id;
+       int fd;
+       struct cbdata *cbdata;
+
+       cbdata = malloc(sizeof(*cbdata));
+       if (!cbdata) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return -ENOMEM;
+       }
+
+       cbdata->service_cb = service_cb;
+       cbdata->data = data;
+
+       fd = secom_create_server(addr);
+       if (fd < 0) {
+               free(cbdata);
+               return fd;
+       }
+
+       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+               ErrPrint("fcntl: %s\n", strerror(errno));
+
+       if (!is_sync) {
+               if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+                       ErrPrint("fcntl: %s\n", strerror(errno));
+       }
+
+       gio = g_io_channel_unix_new(fd);
+       if (!gio) {
+               free(cbdata);
+               close(fd);
+               return -EIO;
+       }
+
+       id = g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, (GIOFunc)accept_cb, cbdata);
+       if (id < 0) {
+               GError *err = NULL;
+               free(cbdata);
+               g_io_channel_unref(gio);
+               g_io_channel_shutdown(gio, TRUE, &err);
+               close(fd);
+               return -EIO;
+       }
+
+       g_io_channel_unref(gio);
+       return fd;
+}
+
+int connector_client_create(const char *addr, int is_sync, int (*service_cb)(int fd, int readsize, void *data), void *data)
+{
+       GIOChannel *gio;
+       guint id;
+       int client_fd;
+       struct cbdata *cbdata;
+
+       cbdata = malloc(sizeof(*cbdata));
+       if (!cbdata) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return -ENOMEM;
+       }
+
+       cbdata->service_cb = service_cb;
+       cbdata->data = data;
+
+       client_fd = secom_create_client(addr);
+       if (client_fd < 0) {
+               free(cbdata);
+               return client_fd;
+       }
+
+       if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0)
+               ErrPrint("Error: %s\n", strerror(errno));
+
+       if (!is_sync) {
+               if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0)
+                       ErrPrint("Error: %s\n", strerror(errno));
+       }
+
+       gio = g_io_channel_unix_new(client_fd);
+       if (!gio) {
+               free(cbdata);
+               close(client_fd);
+               return -EIO;
+       }
+
+       id = g_io_add_watch(gio, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, (GIOFunc)client_cb, cbdata);
+       if (id < 0) {
+               GError *err = NULL;
+               free(cbdata);
+               g_io_channel_unref(gio);
+               g_io_channel_shutdown(gio, TRUE, &err);
+               close(client_fd);
+               return -EIO;
+       }
+
+       g_io_channel_unref(gio);
+       invoke_con_cb_list(client_fd);
+       return client_fd;
+}
+
+int connector_add_event_callback(enum connector_event_type type, int (*evt_cb)(int handle, void *data), void *data)
+{
+       struct evtdata *cbdata;
+       cbdata = malloc(sizeof(*cbdata));
+       if (!cbdata) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return -ENOMEM;
+       }
+
+       cbdata->evt_cb = evt_cb;
+       cbdata->data = data;
+
+       if (type == CONNECTOR_CONNECTED)
+               s_info.conn_cb_list = dlist_append(s_info.conn_cb_list, cbdata);
+       else
+               s_info.disconn_cb_list = dlist_append(s_info.disconn_cb_list, cbdata);
+       return 0;
+}
+
+void *connector_del_event_callback(enum connector_event_type type, int (*cb)(int handle, void *data), void *data)
+{
+       struct dlist *l;
+       struct dlist *n;
+       struct evtdata *cbdata;
+
+       if (type == CONNECTOR_CONNECTED) {
+               dlist_foreach_safe(s_info.conn_cb_list, l, n, cbdata) {
+                       if (cbdata->evt_cb == cb && cbdata->data == data) {
+                               void *data;
+                               data = cbdata->data;
+                               dlist_remove_data(s_info.conn_cb_list, cbdata);
+                               free(cbdata);
+                               return data;
+                       }
+               }
+       } else {
+               dlist_foreach_safe(s_info.disconn_cb_list, l, n, cbdata) {
+                       if (cbdata->evt_cb == cb && cbdata->data == data) {
+                               void *data;
+                               data = cbdata->data;
+                               dlist_remove_data(s_info.disconn_cb_list, cbdata);
+                               free(cbdata);
+                               return data;
+                       }
+               }
+       }
+
+       return NULL;
+}
+
+int connector_server_destroy(int handle)
+{
+       close(handle);
+       return 0;
+}
+
+int connector_client_destroy(int handle)
+{
+       close(handle);
+       return 0;
+}
+
+/* End of a file */
diff --git a/src/connector_packet.c b/src/connector_packet.c
new file mode 100644 (file)
index 0000000..ff45f37
--- /dev/null
@@ -0,0 +1,486 @@
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+#include <dlog.h>
+
+#include "debug.h"
+#include "connector.h"
+#include "packet.h"
+#include "secom_socket.h"
+#include "dlist.h"
+#include "connector_packet.h"
+#include "util.h"
+
+static struct info {
+       struct dlist *recv_list;
+       struct dlist *request_list;
+       char *addr;
+} s_info = {
+       .recv_list = NULL,
+       .request_list = NULL,
+       .addr = NULL,
+};
+
+struct request_ctx {
+       pid_t pid;
+       int handle;
+
+       struct packet *packet;
+       int (*recv_cb)(pid_t pid, int handle, const struct packet *packet, void *data);
+       void *data;
+};
+
+struct recv_ctx {
+       enum {
+               RECV_STATE_INIT,
+               RECV_STATE_HEADER,
+               RECV_STATE_BODY,
+               RECV_STATE_READY,
+       } state;
+       int handle;
+       int offset;
+       pid_t pid;
+       struct packet *packet;
+};
+
+static inline struct request_ctx *find_request_ctx(int handle, unsigned long seq)
+{
+       struct request_ctx *ctx;
+       struct dlist *l;
+
+       dlist_foreach(s_info.request_list, l, ctx) {
+               if (ctx->handle == handle && packet_seq(ctx->packet) == seq) {
+                       return ctx;
+               }
+       }
+
+       return NULL;
+}
+
+static inline void destroy_request_ctx(struct request_ctx *ctx)
+{
+       packet_unref(ctx->packet);
+       dlist_remove_data(s_info.request_list, ctx);
+       free(ctx);
+}
+
+static inline struct request_ctx *create_request_ctx(int handle)
+{
+       struct request_ctx *ctx;
+
+       ctx = malloc(sizeof(*ctx));
+       if (!ctx) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       ctx->handle = handle;
+       ctx->pid = (pid_t)-1;
+       ctx->packet = NULL;
+       ctx->recv_cb = NULL;
+       ctx->data = NULL;
+
+       s_info.request_list = dlist_append(s_info.request_list, ctx);
+       return ctx;
+}
+
+static inline struct recv_ctx *find_recv_ctx(int handle)
+{
+       struct recv_ctx *ctx;
+       struct dlist *l;
+
+       dlist_foreach(s_info.recv_list, l, ctx) {
+               if (ctx->handle == handle)
+                       return ctx;
+       }
+
+       return NULL;
+}
+
+static inline void destroy_recv_ctx(struct recv_ctx *ctx)
+{
+       dlist_remove_data(s_info.recv_list, ctx);
+       packet_destroy(ctx->packet);
+       free(ctx);
+}
+
+static inline struct recv_ctx *create_recv_ctx(int handle)
+{
+       struct recv_ctx *ctx;
+
+       ctx = malloc(sizeof(*ctx));
+       if (!ctx) {
+               ErrPrint("heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       ctx->state = RECV_STATE_INIT,
+       ctx->offset = 0;
+       ctx->packet = NULL;
+       ctx->handle = handle;
+       ctx->pid = (pid_t)-1;
+
+       s_info.recv_list = dlist_append(s_info.recv_list, ctx);
+       return ctx;
+}
+
+static inline void packet_ready(int handle, const struct recv_ctx *receive, struct method *table)
+{
+       struct request_ctx *request;
+       unsigned long sequence;
+       struct packet *result;
+       register int i;
+
+       /*!
+        * \note
+        * Is this ack packet?
+        */
+       switch (packet_type(receive->packet)) {
+       case PACKET_ACK:
+               sequence = packet_seq(receive->packet);
+               request = find_request_ctx(handle, sequence);
+               if (!request) {
+                       ErrPrint("This is not requested packet (%s)\n", packet_command(receive->packet));
+                       break;
+               }
+
+               if (request->recv_cb)
+                       request->recv_cb(receive->pid, handle, receive->packet, request->data);
+
+               destroy_request_ctx(request);
+               break;
+       case PACKET_REQ:
+               for (i = 0; table[i].cmd; i++) {
+                       if (strcmp(table[i].cmd, packet_command(receive->packet)))
+                               continue;
+
+                       result = table[i].handler(receive->pid, handle, receive->packet);
+                       if (result) {
+                               int ret;
+                               ret = secom_send(handle, (void *)packet_data(result), packet_size(result));
+                               if (ret < 0)
+                                       ErrPrint("Failed to send an ack packet\n");
+                               packet_destroy(result);
+                       }
+                       break;
+               }
+
+               break;
+       case PACKET_REQ_NOACK:
+               for (i = 0; table[i].cmd; i++) {
+                       if (strcmp(table[i].cmd, packet_command(receive->packet)))
+                               continue;
+
+                       result = table[i].handler(receive->pid, handle, receive->packet);
+                       if (result)
+                               packet_destroy(result);
+               }
+               break;
+       default:
+               break;
+       }
+
+       return;
+}
+
+static int client_disconnected_cb(int handle, void *data)
+{
+       struct recv_ctx *receive;
+       struct request_ctx *request;
+       struct dlist *l;
+       struct dlist *n;
+       pid_t pid = (pid_t)-1;
+
+       DbgPrint("Clean up all requests and a receive context\n");
+
+       receive = find_recv_ctx(handle);
+       if (receive) {
+               pid = receive->pid;
+               destroy_recv_ctx(receive);
+       }
+
+       dlist_foreach_safe(s_info.request_list, l, n, request) {
+               if (request->handle == handle) {
+                       if (request->recv_cb)
+                               request->recv_cb(pid, handle, NULL, request->data);
+
+                       destroy_request_ctx(request);
+               }
+       }
+
+       return 0;
+}
+
+static int service_cb(int handle, int readsize, void *data)
+{
+       struct recv_ctx *receive;
+       pid_t pid;
+       int ret;
+       int size;
+       char *ptr;
+
+       receive = find_recv_ctx(handle);
+       if (!receive)
+               receive = create_recv_ctx(handle);
+
+       if (!receive) {
+               ErrPrint("Couldn't find or create a receive context\n");
+               return -EIO;
+       }
+
+       while (readsize > 0) {
+               switch (receive->state) {
+               case RECV_STATE_INIT:
+                       receive->state = RECV_STATE_HEADER;
+                       receive->offset = 0;
+               case RECV_STATE_HEADER:
+                       size = packet_header_size() - receive->offset;
+                       /*!
+                        * \note
+                        * Getting header
+                        */
+                       ptr = malloc(size);
+                       if (!ptr) {
+                               ErrPrint("Heap: %s\n", strerror(errno));
+                               destroy_recv_ctx(receive);
+                               return -ENOMEM;
+                       }
+
+                       ret = secom_recv(handle, ptr, size, &pid);
+                       if (ret < 0 || (receive->pid != -1 && receive->pid != pid)) {
+                               ErrPrint("Recv[%d], pid[%d :: %d]\n", ret, receive->pid, pid);
+                               free(ptr);
+                               destroy_recv_ctx(receive);
+                               return -EIO;
+                       }
+
+                       receive->pid = pid;
+                       receive->packet = packet_build(receive->packet, receive->offset, ptr, ret);
+                       free(ptr);
+
+                       if (!receive->packet) {
+                               ErrPrint("Built packet is not valid\n");
+                               destroy_recv_ctx(receive);
+                               return -EFAULT;
+                       }
+
+                       receive->offset += ret;
+                       readsize -= ret;
+                       if (receive->offset == packet_header_size()) {
+                               if (packet_size(receive->packet) == receive->offset)
+                                       receive->state = RECV_STATE_READY;
+                               else
+                                       receive->state = RECV_STATE_BODY;
+                       }
+                       break;
+               case RECV_STATE_BODY:
+                       size = packet_size(receive->packet) - receive->offset;
+                       if (size == 0) {
+                               receive->state = RECV_STATE_READY;
+                               break;
+                       }
+                       /*!
+                        * \note
+                        * Getting body
+                        */
+                       ptr = malloc(size);
+                       if (!ptr) {
+                               ErrPrint("Heap: %s\n", strerror(errno));
+                               destroy_recv_ctx(receive);
+                               return -ENOMEM;
+                       }
+
+                       ret = secom_recv(handle, ptr, size, &pid);
+                       if (ret < 0 || receive->pid != pid) {
+                               ErrPrint("Recv[%d], pid[%d :: %d]\n", ret, receive->pid, pid);
+                               free(ptr);
+                               destroy_recv_ctx(receive);
+                               return -EIO;
+                       }
+
+                       receive->packet = packet_build(receive->packet, receive->offset, ptr, ret);
+                       free(ptr);
+
+                       if (!receive->packet) {
+                               destroy_recv_ctx(receive);
+                               return -EFAULT;
+                       }
+
+                       receive->offset += ret;
+                       readsize -= ret;
+                       if (receive->offset == packet_size(receive->packet))
+                               receive->state = RECV_STATE_READY;
+                       break;
+               case RECV_STATE_READY:
+               default:
+                       break;
+               }
+
+               if (receive->state == RECV_STATE_READY) {
+                       packet_ready(handle, receive, data);
+                       destroy_recv_ctx(receive);
+                       /*!
+                        * \note
+                        * Just quit from this function
+                        * Even if we have read size
+                        * Next time is comming soon ;)
+                        */
+                       break;
+               }
+       }
+
+       return 0;
+}
+
+int connector_packet_async_send(int handle, struct packet *packet, int (*recv_cb)(pid_t pid, int handle, const struct packet *packet, void *data), void *data)
+{
+       int ret;
+       struct request_ctx *ctx;
+
+       ctx = create_request_ctx(handle);
+       if (!ctx)
+               return -ENOMEM;
+
+       ctx->recv_cb = recv_cb;
+       ctx->data = data;
+       ctx->packet = packet_ref(packet);
+
+       ret = secom_send(handle, (void *)packet_data(packet), packet_size(packet));
+       if (ret != packet_size(packet)) {
+               ErrPrint("Send failed. %d <> %d (handle: %d)\n", ret, packet_size(packet), handle);
+               destroy_request_ctx(ctx);
+               return -EIO;
+       }
+
+       return 0;
+}
+
+int connector_packet_send_only(int handle, struct packet *packet)
+{
+       int ret;
+
+       ret = secom_send(handle, (void *)packet_data(packet), packet_size(packet));
+       if (ret != packet_size(packet))
+               return -EIO;
+
+       return 0;
+}
+
+struct packet *connector_packet_oneshot_send(const char *addr, struct packet *packet)
+{
+       int ret;
+       int fd;
+       pid_t pid;
+       int offset;
+       struct packet *result = NULL;
+       void *ptr;
+
+       fd = secom_create_client(addr);
+       if (fd < 0)
+               return NULL;
+
+       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+               ErrPrint("fcntl: %s\n", strerror(errno));
+
+       ret = secom_send(fd, (void *)packet_data(packet), packet_size(packet));
+       if (ret != packet_size(packet)) {
+               secom_destroy(fd);
+               return NULL;
+       }
+
+       offset = 0;
+       ptr = malloc(packet_header_size());
+       if (!ptr) {
+               secom_destroy(fd);
+               return NULL;
+       }
+
+       ret = secom_recv(fd, ptr, packet_header_size(), &pid);
+       if (ret < 0) {
+               free(ptr);
+               secom_destroy(fd);
+               return NULL;
+       }
+       result = packet_build(result, offset, ptr, ret);
+       offset += ret;
+       free(ptr);
+
+       ptr = malloc(packet_payload_size(result));
+       if (!ptr) {
+               secom_destroy(fd);
+               return NULL;
+       }
+
+       ret = secom_recv(fd, ptr, packet_payload_size(result), &pid);
+       if (ret < 0) {
+               free(ptr);
+               secom_destroy(fd);
+               return NULL;
+       }
+       result = packet_build(result, offset, ptr, ret);
+       offset += ret;
+       free(ptr);
+       secom_destroy(fd);
+       return result;
+}
+
+static inline int connector_packet_init(void)
+{
+       return connector_add_event_callback(CONNECTOR_DISCONNECTED, client_disconnected_cb, NULL);
+}
+
+static inline int connector_packet_fini(void)
+{
+       connector_del_event_callback(CONNECTOR_DISCONNECTED, client_disconnected_cb, NULL);
+       return 0;
+}
+
+int connector_packet_client_init(const char *addr, int is_sync, struct method *table)
+{
+       int ret;
+
+       ret = connector_packet_init();
+       if (ret < 0)
+               return ret;
+
+       ret = connector_client_create(addr, 0, service_cb, table);
+       if (ret < 0)
+               connector_packet_fini();
+
+       return ret;
+}
+
+int connector_packet_client_fini(int handle)
+{
+       connector_client_destroy(handle);
+       connector_packet_fini();
+       return 0;
+}
+
+int connector_packet_server_init(const char *addr, struct method *table)
+{
+       int ret;
+
+       ret = connector_packet_init();
+       if (ret < 0)
+               return ret;
+
+       ret = connector_server_create(addr, 0, service_cb, table);
+       if (ret < 0)
+               connector_packet_fini();
+
+       return ret;
+}
+
+int connector_packet_server_fini(int handle)
+{
+       connector_server_destroy(handle);
+       connector_packet_fini();
+       return 0;
+}
+
+/* End of a file */
index 5239854..d5371f0 100644 (file)
@@ -1,6 +1,5 @@
 #include <stdio.h>
 #include <stdbool.h>
-#include <libgen.h>
 #include <unistd.h>
 
 #include <Ecore.h>
@@ -11,6 +10,7 @@
 #include <context_subscribe.h>
 
 #include "debug.h"
+#include "packet.h"
 #include "slave_life.h"
 #include "slave_rpc.h"
 #include "client_life.h"
index 98d4b9b..576cb0c 100644 (file)
@@ -1,17 +1,21 @@
 #include <stdio.h>
 #include <unistd.h>
-#include <libgen.h>
 
-#include <aul.h>
 #include <dlog.h>
 
 #include <gio/gio.h>
 
+#include "packet.h"
+#include "connector.h"
 #include "slave_life.h"
+#include "slave_rpc.h"
 #include "client_life.h"
+#include "client_rpc.h"
 #include "fault_manager.h"
+#include "util.h"
 #include "debug.h"
 
+#if 0
 int aul_listen_app_dead_signal(int (*)(int, void *), void *);
 
 static int dead_cb(int pid, void *cb_data)
@@ -38,15 +42,39 @@ static int dead_cb(int pid, void *cb_data)
 
        return 0;
 }
+#endif
+static int evt_cb(int handle, void *data)
+{
+       struct slave_node *slave;
+       struct client_node *client;
+
+       slave = slave_rpc_find_by_handle(handle);
+       if (slave) {
+               DbgPrint("Slave is disconnected\n");
+               slave_deactivated_by_fault(slave);
+               return 0;
+       }
+
+       client = client_rpc_find_by_handle(handle);
+       if (client) {
+               DbgPrint("Client is disconnected\n");
+               client_deactivated_by_fault(client);
+               return 0;
+       }
+
+       return 0;
+}
 
 int dead_init(void)
 {
-       aul_listen_app_dead_signal(dead_cb, NULL);
+       connector_add_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL);
+//     aul_listen_app_dead_signal(dead_cb, NULL);
        return 0;
 }
 
 int dead_fini(void)
 {
+       connector_del_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL);
        return 0;
 }
 
diff --git a/src/dlist.c b/src/dlist.c
new file mode 100644 (file)
index 0000000..5576b1b
--- /dev/null
@@ -0,0 +1,164 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "dlist.h"
+
+/*!
+ * \brief
+ * This dlist is called Modified Doubly Linked List.
+ *
+ * Noramlly, The dobule linked list contains address of previous and next element.
+ * This dlist also contains them, but the tail element only contains prev address.
+ *
+ * The head element's prev pointer indicates the last element.
+ * But the last element's next pointer indicates NIL.
+ *
+ * So we can find the last element while crawling this DList
+ * But we have to remember the address of the head element.
+ */
+
+struct dlist {
+       struct dlist *next;
+       struct dlist *prev;
+       void *data;
+};
+
+struct dlist *dlist_append(struct dlist *list, void *data)
+{
+       struct dlist *item;
+
+       item = malloc(sizeof(*item));
+       if (!item)
+               return NULL;
+
+       item->next = NULL;
+       item->data = data;
+
+       if (!list) {
+               item->prev = item;
+
+               list = item;
+       } else {
+               item->prev = list->prev;
+               item->prev->next = item;
+               list->prev = item;
+       }
+
+       assert(!list->prev->next && "item NEXT");
+
+       return list;
+}
+
+struct dlist *dlist_prepend(struct dlist *list, void *data)
+{
+       struct dlist *item;
+
+       item = malloc(sizeof(*item));
+       if (!item)
+               return NULL;
+
+       item->data = data;
+
+       if (!list) {
+               item->prev = item;
+               item->next = NULL;
+       } else {
+               if (list->prev->next)
+                       list->prev->next = item;
+
+               item->prev = list->prev;
+               item->next = list;
+
+               list->prev = item;
+
+       }
+
+       return item;
+}
+
+struct dlist *dlist_remove(struct dlist *list, struct dlist *l)
+{
+       if (!list || !l)
+               return NULL;
+
+       if (l == list)
+               list = l->next;
+       else
+               l->prev->next = l->next;
+
+       if (l->next)
+               l->next->prev = l->prev;
+       /*!
+        * \note
+        * If the removed entry 'l' has no next element, it is the last element.
+        * In this case, check the existence of the list first,
+        * and if the list is not empty, update the 'prev' of the list (which is a head element of the list) 
+        *
+        * If we didn't care about this, the head element(list) can indicates the invalid element.
+        */
+       else if (list)
+               list->prev = l->prev;
+
+       free(l);
+       return list;
+}
+
+struct dlist *dlist_find_data(struct dlist *list, void *data)
+{
+       struct dlist *l;
+       void *_data;
+
+       dlist_foreach(list, l, _data) {
+               if (data == _data)
+                       return l;
+       }
+
+       return NULL;
+}
+
+void *dlist_data(struct dlist *l)
+{
+       return l ? l->data : NULL;
+}
+
+struct dlist *dlist_next(struct dlist *l)
+{
+       return l ? l->next : NULL;
+}
+
+struct dlist *dlist_prev(struct dlist *l)
+{
+       return l ? l->prev : NULL;
+}
+
+int dlist_count(struct dlist *l)
+{
+       register int i;
+       struct dlist *n;
+       void *data;
+
+       i = 0;
+       dlist_foreach(l, n, data) {
+               i++;
+       }
+
+       return i;
+}
+
+struct dlist *dlist_nth(struct dlist *l, int nth)
+{
+       register int i;
+       struct dlist *n;
+
+       i = 0;
+       for (n = l; n; n = n->next) {
+               if (i == nth)
+                       return n;
+               i++;
+       }
+
+       return NULL;
+}
+
+/* End of a file */
index 1f2ab5e..6d51eca 100644 (file)
@@ -1,17 +1,17 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h> /* free */
-#include <libgen.h> /* basename */
 
 #include <gio/gio.h>
 
 #include <dlog.h>
 #include <Eina.h>
 
+#include "util.h"
 #include "debug.h"
+#include "packet.h"
 #include "slave_life.h"
 #include "slave_rpc.h"
-#include "util.h"
 #include "client_life.h"
 #include "client_rpc.h"
 #include "package.h"
@@ -90,27 +90,27 @@ static char *check_log_file(struct slave_node *slave)
 
 void fault_unicast_info(struct client_node *client, const char *pkgname, const char *filename, const char *func)
 {
-       GVariant *param;
+       struct packet *packet;
 
-       param = g_variant_new("(sss)", pkgname, filename, func);
-       if (!param)
+       packet = packet_create("fault_packet", "sss", pkgname, filename, func);
+       if (!packet)
                return;
 
-       client_rpc_async_request(client, "fault_package", param);
+       client_rpc_async_request(client, packet);
        DbgPrint("Fault package: %s\n", pkgname);
 }
 
 void fault_broadcast_info(const char *pkgname, const char *filename, const char *func)
 {
-       GVariant *param;
+       struct packet *packet;
 
-       param = g_variant_new("(sss)", pkgname, filename, func);
-       if (!param) {
+       packet = packet_create("fault_packet", "sss", pkgname, filename, func);
+       if (!packet) {
                ErrPrint("Failed to create a param\n");
                return;
        }
 
-       client_rpc_broadcast("fault_package", param);
+       client_rpc_broadcast(packet);
        DbgPrint("Fault package: %s\n", pkgname);
 }
 
index 79cfbab..9c5f631 100644 (file)
--- a/src/fb.c
+++ b/src/fb.c
@@ -1,5 +1,4 @@
 #include <stdio.h>
-#include <libgen.h> /* basename */
 #include <unistd.h> /* access */
 #include <sys/mman.h>
 #include <errno.h>
index 1f18ade..9b70596 100644 (file)
@@ -1,5 +1,4 @@
 #include <stdio.h>
-#include <libgen.h>
 #include <ctype.h>
 #include <stdlib.h> /* malloc */
 #include <errno.h>
@@ -8,6 +7,7 @@
 #include <dlog.h>
 #include <Eina.h>
 
+#include "util.h"
 #include "debug.h"
 #include "group.h"
 
index 62f0a62..0bc0877 100644 (file)
@@ -1,7 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <libgen.h>
 
 #include <dlog.h>
 #include <Ecore_Evas.h>
@@ -11,6 +10,7 @@
 #include "conf.h"
 #include "util.h"
 #include "debug.h"
+#include "packet.h"
 #include "slave_life.h"
 #include "slave_rpc.h"
 #include "client_life.h"
@@ -19,6 +19,7 @@
 #include "instance.h"
 #include "fb.h"
 #include "script_handler.h"
+#include "connector_packet.h"
 
 int errno;
 
@@ -70,6 +71,7 @@ struct inst_info {
                int width;
                int height;
                struct script_info *handle;
+               int is_opened_for_reactivate;
        } pd;
 
        int timeout;
@@ -81,12 +83,12 @@ struct inst_info {
 
 int instance_unicast_created_event(struct inst_info *inst, struct client_node *client)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (!inst->client && !client)
                return 0;
 
-       param = g_variant_new("(dsssiiiissssidiiiiid)", 
+       packet = packet_create("created", "dsssiiiissssidiiiiid", 
                        inst->timestamp,
                        package_name(inst->info), inst->id, inst->content,
                        inst->lb.width, inst->lb.height,
@@ -102,8 +104,7 @@ int instance_unicast_created_event(struct inst_info *inst, struct client_node *c
                        package_lb_type(inst->info) == LB_TYPE_TEXT,
                        package_pd_type(inst->info) == PD_TYPE_TEXT,
                        inst->period);
-
-       if (!param) {
+       if (!packet) {
                ErrPrint("Failed to create a param\n");
                return -EFAULT;
        }
@@ -111,14 +112,14 @@ int instance_unicast_created_event(struct inst_info *inst, struct client_node *c
        if (!client)
                client = inst->client;
 
-       return client_rpc_async_request(client, "created", param);
+       return client_rpc_async_request(client, packet);
 }
 
 int instance_broadcast_created_event(struct inst_info *inst)
 {
-       GVariant *param;
+       struct packet *packet;
 
-       param = g_variant_new("(dsssiiiissssidiiiiid)", 
+       packet = packet_create("created", "dsssiiiissssidiiiiid", 
                        inst->timestamp,
                        package_name(inst->info), inst->id, inst->content,
                        inst->lb.width, inst->lb.height,
@@ -135,69 +136,50 @@ int instance_broadcast_created_event(struct inst_info *inst)
                        package_pd_type(inst->info) == PD_TYPE_TEXT,
                        inst->period);
 
-       if (!param)
+       if (!packet)
                return -EFAULT;
 
-       return client_rpc_broadcast("created", param);
+       return client_rpc_broadcast(packet);
 }
 
 int instance_unicast_deleted_event(struct inst_info *inst)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (!inst->client)
                return -EINVAL;
 
-       param = g_variant_new("(ssd)", package_name(inst->info), inst->id, inst->timestamp);
-       if (!param) {
+       packet = packet_create("deleted", "ssd", package_name(inst->info), inst->id, inst->timestamp);
+       if (!packet) {
                ErrPrint("Failed to create a param\n");
                return -EFAULT;
        }
                
-       return client_rpc_async_request(inst->client, "deleted", param);
+       return client_rpc_async_request(inst->client, packet);
 }
 
 int instance_broadcast_deleted_event(struct inst_info *inst)
 {
-       GVariant *param;
+       struct packet *packet;
 
-       param = g_variant_new("(ssd)", package_name(inst->info), inst->id, inst->timestamp);
-       if (!param) {
+       packet = packet_create("deleted", "ssd", package_name(inst->info), inst->id, inst->timestamp);
+       if (!packet) {
                ErrPrint("Failed to create a param\n");
                return -EFAULT;
        }
                
-       return client_rpc_broadcast("deleted", param);
+       return client_rpc_broadcast(packet);
 }
 
 static int client_deactivated_cb(struct client_node *client, void *data)
 {
        struct inst_info *inst = data;
-
-       switch (inst->state) {
-       case INST_ACTIVATED:
-       case INST_DEACTIVATED:
-               DbgPrint("Destroy\n");
-               instance_destroy(inst);
-               break;
-       case INST_REQUEST_TO_ACTIVATE:
-       case INST_REQUEST_TO_DEACTIVATE:
-       case INST_REQUEST_TO_REACTIVATE:
-       case INST_REQUEST_TO_DESTROY:
-               DbgPrint("Requested state is changed to INST_DESTROYED\n");
-               inst->requested_state = INST_DESTROYED;
-               break;
-       default:
-               break;
-       }
-
+       instance_destroy(inst);
        return 0;
 }
 
 static inline void destroy_instance(struct inst_info *inst)
 {
-       DbgPrint("%s\n", package_name(inst->info));
-
        if (inst->lb.handle) {
                script_handler_unload(inst->lb.handle, 0);
                script_handler_destroy(inst->lb.handle);
@@ -323,7 +305,7 @@ struct inst_info * instance_ref(struct inst_info *inst)
        return inst;
 }
 
-struct inst_info * instance_unref(struct inst_info *inst)
+struct inst_info *instance_unref(struct inst_info *inst)
 {
        if (!inst)
                return NULL;
@@ -342,13 +324,13 @@ struct inst_info * instance_unref(struct inst_info *inst)
        return inst;
 }
 
-static void deactivate_cb(struct slave_node *slave, const char *funcname, GVariant *result, void *data)
+static void deactivate_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        struct inst_info *inst = data;
        int ret;
 
-       if (!result) {
-               ErrPrint("Failed to deactivate an instance: %s\n", inst->id);
+       if (!packet) {
+               DbgPrint("Consuming a request of a dead process\n");
                /*!
                 * \note
                 * The instance_reload will care this.
@@ -358,8 +340,11 @@ static void deactivate_cb(struct slave_node *slave, const char *funcname, GVaria
                return;
        }
 
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
+       if (packet_get(packet, "i", &ret) != 1) {
+               ErrPrint("Invalid argument\n");
+               instance_unref(inst);
+               return;
+       }
 
        if (inst->state == INST_DESTROYED) {
                /*!
@@ -426,7 +411,7 @@ static void deactivate_cb(struct slave_node *slave, const char *funcname, GVaria
                 * This is not possible, slave will always return -ENOENT, -EINVAL, or 0.
                 * but care this exceptional case.
                 */
-               ErrPrint("Destroy function returns invalid value: %d\n", ret);
+               DbgPrint("[%s] instance destroying ret(%d)\n", package_name(inst->info), ret);
                slave_unload_instance(package_slave(inst->info));
                instance_broadcast_deleted_event(inst);
                instance_deactivated(inst);
@@ -437,13 +422,13 @@ static void deactivate_cb(struct slave_node *slave, const char *funcname, GVaria
        instance_unref(inst);
 }
 
-static void reactivate_cb(struct slave_node *slave, const char *funcname, GVariant *result, void *data)
+static void reactivate_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        struct inst_info *inst = data;
        int ret;
 
-       if (!result) {
-               ErrPrint("Failed to activate an instance: %s\n", inst->id);
+       if (!packet) {
+               DbgPrint("Consuming a request of a dead process\n");
                /*!
                 * \note
                 * instance_reload function will care this.
@@ -453,8 +438,11 @@ static void reactivate_cb(struct slave_node *slave, const char *funcname, GVaria
                return;
        }
 
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
+       if (packet_get(packet, "i", &ret) != 1) {
+               ErrPrint("Invalid parameter\n");
+               instance_unref(inst);
+               return;
+       }
 
        if (inst->state == INST_DESTROYED) {
                /*!
@@ -477,12 +465,17 @@ static void reactivate_cb(struct slave_node *slave, const char *funcname, GVaria
                        instance_destroy(inst);
                        break;
                case INST_ACTIVATED:
+                       if (inst->lb.handle)
+                               script_handler_load(inst->lb.handle, 0);
+
+                       if (inst->pd.handle && inst->pd.is_opened_for_reactivate)
+                               script_handler_load(inst->pd.handle, 1);
                default:
                        break;
                }
                break;
        default:
-               DbgPrint("Failed to activate an instance: %d\n", ret);
+               DbgPrint("[%s] instance destroying ret(%d)\n", package_name(inst->info), ret);
                slave_unload_instance(package_slave(inst->info));
                instance_broadcast_deleted_event(inst);
                instance_deactivated(inst);
@@ -493,7 +486,7 @@ static void reactivate_cb(struct slave_node *slave, const char *funcname, GVaria
        instance_unref(inst);
 }
 
-static void activate_cb(struct slave_node *slave, const char *funcname, GVariant *result, void *data)
+static void activate_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        struct inst_info *inst = data;
        struct inst_info *new_inst;
@@ -502,8 +495,8 @@ static void activate_cb(struct slave_node *slave, const char *funcname, GVariant
        int h;
        double priority;
 
-       if (!result) {
-               ErrPrint("Failed to activate an instance: %s\n", inst->id);
+       if (!packet) {
+               DbgPrint("Consuming a request of a dead process\n");
                /*!
                 * \note
                 * instance_reload will care this
@@ -513,8 +506,11 @@ static void activate_cb(struct slave_node *slave, const char *funcname, GVariant
                return;
        }
 
-       g_variant_get(result, "(iiid)", &ret, &w, &h, &priority);
-       g_variant_unref(result);
+       if (packet_get(packet, "iiid", &ret, &w, &h, &priority) != 4) {
+               ErrPrint("Invalid parameter\n");
+               instance_unref(inst);
+               return;
+       }
 
        if (inst->state == INST_DESTROYED) {
                /*!
@@ -589,7 +585,7 @@ static void activate_cb(struct slave_node *slave, const char *funcname, GVariant
                }
                break;
        default:
-               DbgPrint("Failed to activate an instance: %d\n", ret);
+               DbgPrint("[%s] instance destroying ret(%d)\n", package_name(inst->info), ret);
                instance_unicast_deleted_event(inst);
                instance_deactivated(inst);
                instance_destroy(inst);
@@ -639,7 +635,7 @@ int instance_destroyed(struct inst_info *inst)
 
 int instance_destroy(struct inst_info *inst)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (!inst) {
                ErrPrint("Invalid instance handle\n");
@@ -663,19 +659,15 @@ int instance_destroy(struct inst_info *inst)
                break;
        }
 
-       param = g_variant_new("(ss)", package_name(inst->info), inst->id);
-       if (!param) {
+       packet = packet_create("delete", "ss", package_name(inst->info), inst->id);
+       if (!packet) {
                ErrPrint("Failed to build a delete param\n");
                return -EFAULT;
        }
 
        inst->requested_state = INST_DESTROYED;
        inst->state = INST_REQUEST_TO_DESTROY;
-       return slave_rpc_async_request(package_slave(inst->info),
-                       package_name(inst->info), inst->id,
-                       "delete", param,
-                       deactivate_cb, instance_ref(inst));
-       return 0;
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, deactivate_cb, instance_ref(inst));
 }
 
 int instance_deactivated(struct inst_info *inst)
@@ -691,8 +683,10 @@ int instance_deactivated(struct inst_info *inst)
        if (inst->lb.handle)
                script_handler_unload(inst->lb.handle, 0);
 
-       if (inst->pd.handle)
+       if (inst->pd.handle) {
+               inst->pd.is_opened_for_reactivate = inst->pd.handle ? script_handler_is_loaded(inst->pd.handle) : 0;
                script_handler_unload(inst->pd.handle, 1);
+       }
 
        inst->state = INST_DEACTIVATED;
        inst->requested_state = INST_DEACTIVATED;
@@ -701,7 +695,7 @@ int instance_deactivated(struct inst_info *inst)
 
 int instance_deactivate(struct inst_info *inst)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (!inst) {
                ErrPrint("Invalid instance handle\n");
@@ -722,21 +716,18 @@ int instance_deactivate(struct inst_info *inst)
                break;
        }
 
-       param = g_variant_new("(ss)", package_name(inst->info), inst->id);
-       if (!param)
+       packet = packet_create("delete", "ss", package_name(inst->info), inst->id);
+       if (!packet)
                return -EFAULT;
 
        inst->requested_state = INST_DEACTIVATED;
        inst->state = INST_REQUEST_TO_DEACTIVATE;
-       return slave_rpc_async_request(package_slave(inst->info),
-                       package_name(inst->info), inst->id,
-                       "delete", param,
-                       deactivate_cb, instance_ref(inst));
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, deactivate_cb, instance_ref(inst));
 }
 
 int instance_reactivate(struct inst_info *inst)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (!inst) {
                ErrPrint("Invalid instance handle\n");
@@ -762,7 +753,7 @@ int instance_reactivate(struct inst_info *inst)
                break;
        }
 
-       param = g_variant_new("(sssiidssiiis)",
+       packet = packet_create("renew", "sssiidssiiis",
                        package_name(inst->info),
                        inst->id,
                        inst->content,
@@ -774,7 +765,7 @@ int instance_reactivate(struct inst_info *inst)
                        inst->lb.is_pinned_up,
                        inst->lb.width, inst->lb.height,
                        package_abi(inst->info));
-       if (!param) {
+       if (!packet) {
                ErrPrint("Failed to create a param\n");
                return -EFAULT;
        }
@@ -783,15 +774,12 @@ int instance_reactivate(struct inst_info *inst)
        inst->state = INST_REQUEST_TO_REACTIVATE;
 
        slave_activate(package_slave(inst->info));
-       return slave_rpc_async_request(package_slave(inst->info),
-                       package_name(inst->info), inst->id,
-                       "renew", param,
-                       reactivate_cb, instance_ref(inst));
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, reactivate_cb, instance_ref(inst));
 }
 
 int instance_activate(struct inst_info *inst)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (!inst) {
                ErrPrint("Invalid instance handle\n");
@@ -817,7 +805,7 @@ int instance_activate(struct inst_info *inst)
                break;
        }
 
-       param = g_variant_new("(sssiidssiis)",
+       packet = packet_create("new", "sssiidssiis",
                        package_name(inst->info),
                        inst->id,
                        inst->content,
@@ -829,7 +817,7 @@ int instance_activate(struct inst_info *inst)
                        inst->lb.is_pinned_up,
                        !!inst->client,
                        package_abi(inst->info));
-       if (!param) {
+       if (!packet) {
                ErrPrint("Failed to create a param\n");
                return -EFAULT;
        }
@@ -842,10 +830,7 @@ int instance_activate(struct inst_info *inst)
         * Try to activate a slave if it is not activated
         */
        slave_activate(package_slave(inst->info));
-       return slave_rpc_async_request(package_slave(inst->info),
-                               package_name(inst->info), inst->id,
-                               "new", param,
-                               activate_cb, instance_ref(inst));
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, activate_cb, instance_ref(inst));
 }
 
 void instance_lb_updated(const char *pkgname, const char *id)
@@ -861,33 +846,31 @@ void instance_lb_updated(const char *pkgname, const char *id)
 
 void instance_lb_updated_by_instance(struct inst_info *inst)
 {
-       GVariant *param;
+       struct packet *packet;
 
-       param = g_variant_new("(ssiid)", package_name(inst->info), inst->id,
-                               inst->lb.width, inst->lb.height, inst->lb.priority);
-       if (!param) {
+       packet = packet_create("lb_updated", "ssiid", package_name(inst->info), inst->id, inst->lb.width, inst->lb.height, inst->lb.priority);
+       if (!packet) {
                ErrPrint("Failed to create param (%s - %s)\n", package_name(inst->info), inst->id);
                return;
        }
 
-       client_rpc_broadcast("lb_updated", param);
+       client_rpc_broadcast(packet);
 }
 
 void instance_pd_updated_by_instance(struct inst_info *inst, const char *descfile)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (!descfile)
                descfile = inst->id;
 
-       param = g_variant_new("(sssii)", package_name(inst->info), inst->id, descfile,
-                                               inst->pd.width, inst->pd.height);
-       if (!param) {
+       packet = packet_create("pd_updated", "sssii", package_name(inst->info), inst->id, descfile, inst->pd.width, inst->pd.height);
+       if (!packet) {
                ErrPrint("Failed to create param (%s - %s)\n", package_name(inst->info), inst->id);
                return;
        }
 
-       client_rpc_broadcast("pd_updated", param);
+       client_rpc_broadcast(packet);
 }
 
 void instance_pd_updated(const char *pkgname, const char *id, const char *descfile)
@@ -916,19 +899,22 @@ void instance_set_pd_info(struct inst_info *inst, int w, int h)
        inst->pd.height = h;
 }
 
-static void pinup_cb(struct slave_node *slave, const char *funcnane, GVariant *result, void *data)
+static void pinup_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        struct set_pinup_cbdata *cbdata = data;
        int ret;
 
-       if (!result) {
+       if (!packet) {
                instance_unref(cbdata->inst);
                free(cbdata);
                return;
        }
 
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
+       if (packet_get(packet, "i", &ret) != 1) {
+               instance_unref(cbdata->inst);
+               free(cbdata);
+               return;
+       }
 
        if (ret == 0)
                cbdata->inst->lb.is_pinned_up = cbdata->pinup;
@@ -940,7 +926,7 @@ static void pinup_cb(struct slave_node *slave, const char *funcnane, GVariant *r
 int instance_set_pinup(struct inst_info *inst, int pinup)
 {
        struct set_pinup_cbdata *cbdata;
-       GVariant *param;
+       struct packet *packet;
 
        if (package_is_fault(inst->info))
                return -EFAULT;
@@ -958,33 +944,33 @@ int instance_set_pinup(struct inst_info *inst, int pinup)
        cbdata->inst = instance_ref(inst);
        cbdata->pinup = pinup;
 
-       param = g_variant_new("(ssi)", package_name(inst->info), inst->id, pinup);
-       if (!param) {
+       packet = packet_create("pinup", "ssi", package_name(inst->info), inst->id, pinup);
+       if (!packet) {
                ErrPrint("Failed to create a param\n");
                instance_unref(cbdata->inst);
                free(cbdata);
                return -EFAULT;
        }
 
-       return slave_rpc_async_request(package_slave(inst->info),
-                                       package_name(inst->info), inst->id,
-                                       "pinup", param,
-                                       pinup_cb, cbdata);
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, pinup_cb, cbdata);
 }
 
-static void resize_cb(struct slave_node *slave, const char *funcname, GVariant *result, void *data)
+static void resize_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        struct resize_cbdata *cbdata = data;
        int ret;
 
-       if (!result) {
+       if (!packet) {
                instance_unref(cbdata->inst);
                free(cbdata);
                return;
        }
 
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
+       if (packet_get(packet, "i", &ret) != 1) {
+               ErrPrint("Invalid parameter\n");
+               free(cbdata);
+               return;
+       }
 
        if (ret == 0) {
                cbdata->inst->lb.width = cbdata->w;
@@ -1000,11 +986,13 @@ static void resize_cb(struct slave_node *slave, const char *funcname, GVariant *
 int instance_resize(struct inst_info *inst, int w, int h)
 {
        struct resize_cbdata *cbdata;
-       GVariant *param;
+       struct packet *packet;
        int ret;
 
-       if (package_is_fault(inst->info))
+       if (package_is_fault(inst->info)) {
+               ErrPrint("Fault package: %s\n", package_name(inst->info));
                return -EFAULT;
+       }
 
        cbdata = malloc(sizeof(*cbdata));
        if (!cbdata) {
@@ -1017,35 +1005,35 @@ int instance_resize(struct inst_info *inst, int w, int h)
        cbdata->h = h;
 
        /* NOTE: param is resued from here */
-       param = g_variant_new("(ssii)", package_name(inst->info), inst->id, w, h);
-       if (!param) {
+       packet = packet_create("resize", "ssii", package_name(inst->info), inst->id, w, h);
+       if (!packet) {
+               DbgPrint("Failed to build a packet for %s\n", package_name(inst->info));
                ret = -EFAULT;
                instance_unref(cbdata->inst);
                free(cbdata);
        } else {
-               ret = slave_rpc_async_request(
-                               package_slave(inst->info),
-                               package_name(inst->info), inst->id,
-                               "resize", param,
-                               resize_cb, cbdata);
+               ret = slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, resize_cb, cbdata);
        }
 
        return ret;
 }
 
-static void set_period_cb(struct slave_node *slave, const char *funcname, GVariant *result, void *data)
+static void set_period_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        int ret;
        struct period_cbdata *cbdata = data;
 
-       if (!result) {
+       if (!packet) {
                instance_unref(cbdata->inst);
                free(cbdata);
                return;
        }
 
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
+       if (packet_get(packet, "i", &ret) != 1) {
+               instance_unref(cbdata->inst);
+               free(cbdata);
+               return;
+       }
 
        if (ret == 0)
                cbdata->inst->period = cbdata->period;
@@ -1059,7 +1047,7 @@ static void set_period_cb(struct slave_node *slave, const char *funcname, GVaria
 
 int instance_set_period(struct inst_info *inst, double period)
 {
-       GVariant *param;
+       struct packet *packet;
        struct period_cbdata *cbdata;
 
        if (package_is_fault(inst->info))
@@ -1080,60 +1068,51 @@ int instance_set_period(struct inst_info *inst, double period)
        cbdata->period = period;
        cbdata->inst = instance_ref(inst);
 
-       param = g_variant_new("(ssd)", package_name(inst->info), inst->id, period);
-       if (!param) {
+       packet = packet_create("set_period", "ssd", package_name(inst->info), inst->id, period);
+       if (!packet) {
                instance_unref(cbdata->inst);
                free(cbdata);
                return -EFAULT;
        }
 
-       return slave_rpc_async_request(package_slave(inst->info),
-                                       package_name(inst->info), inst->id,
-                                       "set_period", param,
-                                       set_period_cb, cbdata);
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, set_period_cb, cbdata);
 }
 
 int instance_clicked(struct inst_info *inst, const char *event, double timestamp, double x, double y)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (package_is_fault(inst->info))
                return -EFAULT;
 
        /* NOTE: param is resued from here */
-       param = g_variant_new("(sssddd)", package_name(inst->info), inst->id, event, timestamp, x, y);
-       if (!param)
+       packet = packet_create("clicked", "sssddd", package_name(inst->info), inst->id, event, timestamp, x, y);
+       if (!packet)
                return -EFAULT;
 
-       return slave_rpc_async_request(package_slave(inst->info),
-                                       package_name(inst->info), inst->id,
-                                       "clicked", param,
-                                       NULL, NULL);
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, NULL, NULL);
 }
 
 int instance_text_signal_emit(struct inst_info *inst, const char *emission, const char *source, double sx, double sy, double ex, double ey)
 {
-       GVariant *param;
+       struct packet *packet;
 
        if (package_is_fault(inst->info))
                return -EFAULT;
 
-       param = g_variant_new("(ssssdddd)", package_name(inst->info), inst->id, emission, source, sx, sy, ex, ey);
-       if (!param)
+       packet = packet_create("text_signal", "ssssdddd", package_name(inst->info), inst->id, emission, source, sx, sy, ex, ey);
+       if (!packet)
                return -EFAULT;
 
-       return slave_rpc_async_request(package_slave(inst->info),
-                               package_name(inst->info), inst->id,
-                               "text_signal", param,
-                               NULL, NULL);
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, NULL, NULL);
 }
 
-static void change_group_cb(struct slave_node *slave, const char *funcname, GVariant *result, void *data)
+static void change_group_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        struct change_group_cbdata *cbdata = data;
        int ret;
 
-       if (!result) {
+       if (!packet) {
                instance_unref(cbdata->inst);
                free(cbdata->cluster);
                free(cbdata->category);
@@ -1141,8 +1120,13 @@ static void change_group_cb(struct slave_node *slave, const char *funcname, GVar
                return;
        }
 
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
+       if (packet_get(packet, "i", &ret) != 1) {
+               instance_unref(cbdata->inst);
+               free(cbdata->cluster);
+               free(cbdata->category);
+               free(cbdata);
+               return;
+       }
 
        if (ret == 0) {
                free(cbdata->inst->cluster);
@@ -1161,7 +1145,7 @@ static void change_group_cb(struct slave_node *slave, const char *funcname, GVar
 
 int instance_change_group(struct inst_info *inst, const char *cluster, const char *category)
 {
-       GVariant *param;
+       struct packet *packet;
        struct change_group_cbdata *cbdata;
 
        if (package_is_fault(inst->info))
@@ -1190,8 +1174,8 @@ int instance_change_group(struct inst_info *inst, const char *cluster, const cha
 
        cbdata->inst = instance_ref(inst);
 
-       param = g_variant_new("(ssss)", package_name(inst->info), inst->id, cluster, category);
-       if (!param) {
+       packet = packet_create("change_group","ssss", package_name(inst->info), inst->id, cluster, category);
+       if (!packet) {
                instance_unref(cbdata->inst);
                free(cbdata->category);
                free(cbdata->cluster);
@@ -1199,103 +1183,100 @@ int instance_change_group(struct inst_info *inst, const char *cluster, const cha
                return -EFAULT;
        }
 
-       return slave_rpc_async_request(package_slave(inst->info),
-                                       package_name(inst->info), inst->id,
-                                       "change_group", param,
-                                       change_group_cb, cbdata);
+       return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, change_group_cb, cbdata);
 }
 
-int const instance_auto_launch(struct inst_info *inst)
+const int const instance_auto_launch(const struct inst_info *inst)
 {
        return inst->lb.auto_launch;
 }
 
-int const instance_priority(struct inst_info *inst)
+const int const instance_priority(const struct inst_info *inst)
 {
        return inst->lb.priority;
 }
 
-struct client_node *const instance_client(struct inst_info *inst)
+const struct client_node *const instance_client(const struct inst_info *inst)
 {
        return inst->client;
 }
 
-double const instance_period(struct inst_info *inst)
+const double const instance_period(const struct inst_info *inst)
 {
        return inst->period;
 }
 
-int const instance_lb_width(struct inst_info *inst)
+const int const instance_lb_width(const struct inst_info *inst)
 {
        return inst->lb.width;
 }
 
-int const instance_lb_height(struct inst_info *inst)
+const int const instance_lb_height(const struct inst_info *inst)
 {
        return inst->lb.height;
 }
 
-int const instance_pd_width(struct inst_info *inst)
+const int const instance_pd_width(const struct inst_info *inst)
 {
        return inst->pd.width;
 }
 
-int const instance_pd_height(struct inst_info *inst)
+const int const instance_pd_height(const struct inst_info *inst)
 {
        return inst->pd.height;
 }
 
-struct pkg_info *const instance_package(struct inst_info *inst)
+const struct pkg_info *const instance_package(const struct inst_info *inst)
 {
        return inst->info;
 }
 
-struct script_info *const instance_lb_handle(struct inst_info *inst)
+struct script_info *const instance_lb_handle(const struct inst_info *inst)
 {
        return inst->lb.handle;
 }
 
-struct script_info * const instance_pd_handle(struct inst_info *inst)
+struct script_info * const instance_pd_handle(const struct inst_info *inst)
 {
        return inst->pd.handle;
 }
 
-char *const instance_id(struct inst_info *inst)
+const char *const instance_id(const struct inst_info *inst)
 {
        return inst->id;
 }
 
-char *const instance_content(struct inst_info *inst)
+const char *const instance_content(const struct inst_info *inst)
 {
        return inst->content;
 }
 
-char *const instance_category(struct inst_info *inst)
+const char *const instance_category(const struct inst_info *inst)
 {
        return inst->category;
 }
 
-char *const instance_cluster(struct inst_info *inst)
+const char *const instance_cluster(const struct inst_info *inst)
 {
        return inst->cluster;
 }
 
-double const instance_timestamp(struct inst_info *inst)
+const double const instance_timestamp(const struct inst_info *inst)
 {
        return inst->timestamp;
 }
 
-enum instance_state const instance_state(struct inst_info *inst)
+const enum instance_state const instance_state(const struct inst_info *inst)
 {
        return inst->state;
 }
 
 void instance_faulted(struct inst_info *inst)
 {
+       DbgPrint("Fault. DESTROYING (%s)\n", package_name(inst->info));
+
        switch (inst->state) {
        case INST_REQUEST_TO_ACTIVATE:
-               DbgPrint("Deactivated instance of %s is destroyed\n",
-                                               package_name(instance_package(inst)));
                instance_unicast_deleted_event(inst);
                instance_deactivated(inst);
                instance_destroy(inst);
@@ -1304,8 +1285,6 @@ void instance_faulted(struct inst_info *inst)
        case INST_REQUEST_TO_REACTIVATE:
        case INST_REQUEST_TO_DESTROY:
        case INST_ACTIVATED:
-               DbgPrint("Activated instance of %s is destroyed\n",
-                                               package_name(instance_package(inst)));
                slave_unload_instance(package_slave(inst->info));
                instance_deactivated(inst);
                instance_broadcast_deleted_event(inst);
@@ -1314,8 +1293,6 @@ void instance_faulted(struct inst_info *inst)
                break;
        case INST_DESTROYED:
        default:
-               DbgPrint("Package is already destroyed: %s\n",
-                                       package_name(instance_package(inst)));
                break;
        }
 }
@@ -1329,14 +1306,17 @@ void instance_recover_state(struct inst_info *inst)
        case INST_REQUEST_TO_DESTROY:
                switch (inst->requested_state) {
                case INST_ACTIVATED:
+                       DbgPrint("Req. to RE-ACTIVATED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
                        instance_reactivate(inst);
                        break;
                case INST_DEACTIVATED:
+                       DbgPrint("Req. to DEACTIVATED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
                        slave_unload_instance(package_slave(inst->info));
                        break;
                case INST_DESTROYED:
+                       DbgPrint("Req. to DESTROYED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
                        slave_unload_instance(package_slave(inst->info));
                        instance_destroy(inst);
@@ -1348,13 +1328,16 @@ void instance_recover_state(struct inst_info *inst)
        case INST_REQUEST_TO_ACTIVATE:
                switch (inst->requested_state) {
                case INST_ACTIVATED:
+                       DbgPrint("Req. to ACTIVATED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
                        instance_activate(inst);
                        break;
                case INST_DEACTIVATED:
+                       DbgPrint("Req. to DEACTIVATED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
                        break;
                case INST_DESTROYED:
+                       DbgPrint("Req. to DESTROYED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
                        instance_destroy(inst);
                        break;
@@ -1365,13 +1348,17 @@ void instance_recover_state(struct inst_info *inst)
        case INST_DEACTIVATED:
                switch (inst->requested_state) {
                case INST_ACTIVATED:
+                       DbgPrint("Req. to ACTIVATED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
                        instance_activate(inst);
                        break;
                case INST_DEACTIVATED:
+                       DbgPrint("(DEACTIVATED) AUTO Req. to ACTIVATED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
+                       instance_activate(inst);
                        break;
                case INST_DESTROYED:
+                       DbgPrint("Req. to DESTROYED (%s)\n", package_name(inst->info));
                        instance_deactivated(inst);
                        instance_destroy(inst);
                        break;
@@ -1385,4 +1372,75 @@ void instance_recover_state(struct inst_info *inst)
        }
 }
 
+int instance_need_slave(struct inst_info *inst)
+{
+       int ret = 0;
+       switch (inst->state) {
+       case INST_ACTIVATED:
+       case INST_REQUEST_TO_DEACTIVATE:
+       case INST_REQUEST_TO_REACTIVATE:
+       case INST_REQUEST_TO_DESTROY:
+               switch (inst->requested_state) {
+               case INST_ACTIVATED:
+                       DbgPrint("Req. to ACTIVATED (%s)\n", package_name(inst->info));
+                       ret = 1;
+                       break;
+               case INST_DEACTIVATED:
+                       DbgPrint("Req. to DEACTIVATED (%s)\n", package_name(inst->info));
+                       instance_deactivated(inst);
+                       slave_unload_instance(package_slave(inst->info));
+                       break;
+               case INST_DESTROYED:
+                       DbgPrint("Req. to DESTROYED (%s)\n", package_name(inst->info));
+                       instance_deactivated(inst);
+                       slave_unload_instance(package_slave(inst->info));
+                       instance_destroy(inst);
+                       break;
+               default:
+                       break;
+               }
+               break;
+       case INST_REQUEST_TO_ACTIVATE:
+               switch (inst->requested_state) {
+               case INST_ACTIVATED:
+                       DbgPrint("Req. to ACTIVATED (%s)\n", package_name(inst->info));
+                       ret = 1;
+                       break;
+               case INST_DEACTIVATED:
+                       DbgPrint("Req. to DEACTIVATED (%s)\n", package_name(inst->info));
+                       instance_deactivated(inst);
+                       break;
+               case INST_DESTROYED:
+                       DbgPrint("Req. to DESTROYED (%s)\n", package_name(inst->info));
+                       instance_deactivated(inst);
+                       instance_destroy(inst);
+                       break;
+               default:
+                       break;
+               }
+               break;
+       case INST_DEACTIVATED:
+               switch (inst->requested_state) {
+               case INST_ACTIVATED:
+                       DbgPrint("Req. to ACTIVATED (%s)\n", package_name(inst->info));
+                       ret = 1;
+                       break;
+               case INST_DESTROYED:
+                       DbgPrint("Req. to DESTROYED (%s)\n", package_name(inst->info));
+                       instance_deactivated(inst);
+                       instance_destroy(inst);
+                       break;
+               case INST_DEACTIVATED:
+               default:
+                       break;
+               }
+               break;
+       case INST_DESTROYED:
+       default:
+               break;
+       }
+
+       return ret;
+}
+
 /* End of a file */
index 4b19e97..d52645a 100644 (file)
--- a/src/io.c
+++ b/src/io.c
@@ -2,7 +2,6 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <dirent.h>
-#include <libgen.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
index 646492d..9a56043 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <libgen.h>
+#include <unistd.h>
 
 #include <Ecore.h>
 #include <Ecore_X.h>
@@ -8,13 +8,11 @@
 #include <Ecore_Evas.h>
 #include <glib.h>
 #include <glib-object.h>
-#include <gio/gio.h>
 #include <aul.h>
 
 #include <dlog.h>
 
-#include "debug.h"
-#include "dbus.h"
+#include "packet.h"
 #include "slave_life.h"
 #include "slave_rpc.h"
 #include "client_life.h"
 #include "io.h"
 #include "xmonitor.h"
 #include "setting.h"
+#include "server.h"
+#include "util.h"
+#include "debug.h"
 
 #if defined(FLOG)
 FILE *__file_log_fp;
 #endif
 
-static void do_more_init()
+static Eina_Bool lazy_init_cb(void *data)
 {
        int ret;
 
-       ret = client_init();
-       DbgPrint("Client initialized: %d\n", ret);
-
-       ret = package_init();
-       DbgPrint("pkgmgr initialized: %d\n", ret);
+       ret = dead_init();
+       DbgPrint("Dead callback is registered: %d\n", ret);
 
        ret = group_init();
        DbgPrint("group init: %d\n", ret);
@@ -49,14 +47,13 @@ static void do_more_init()
        ret = io_init();
        DbgPrint("Init I/O: %d\n", ret);
 
-       ret = xmonitor_init();
-       DbgPrint("XMonitor init is done: %d\n", ret);
-
-       ret = setting_init();
-       DbgPrint("Setting initialized: %d\n", ret);
+       ret = package_init();
+       DbgPrint("pkgmgr initialized: %d\n", ret);
 
        ret = ctx_client_init();
        DbgPrint("Context engine is initialized: %d\n", ret);
+
+       return ECORE_CALLBACK_CANCEL;
 }
 
 static inline int app_create(void *data)
@@ -71,6 +68,10 @@ static inline int app_create(void *data)
 
        conf_update_size();
 
+       if (access(g_conf.path.slave_log, R_OK|W_OK) != 0) {
+               mkdir(g_conf.path.slave_log, 755);
+       }
+
        /*!
         * \note
         * Dead signal handler has to be initialized before
@@ -84,14 +85,20 @@ static inline int app_create(void *data)
         * To enable the dead signal handler,
         * dead_init should be done before other components are initiated.
         */
-       ret = dead_init();
-       DbgPrint("Dead callback is registered: %d\n", ret);
+       ret = server_init();
+       DbgPrint("Server initialized: %d\n", ret);
 
-       ret = dbus_init(do_more_init);
+       ret = xmonitor_init();
+       DbgPrint("XMonitor init is done: %d\n", ret);
 
-       if (access(g_conf.path.slave_log, R_OK|W_OK) != 0) {
-               mkdir(g_conf.path.slave_log, 755);
-       }
+       ret = setting_init();
+       DbgPrint("Setting initialized: %d\n", ret);
+
+       ret = client_init();
+       DbgPrint("Client initialized: %d\n", ret);
+
+       if (!ecore_timer_add(0.1f, lazy_init_cb, NULL))
+               lazy_init_cb(NULL);
 
        DbgPrint("dbus initialized: %d\n", ret);
        initialized = 1;
@@ -114,7 +121,10 @@ static inline int app_terminate(void *data)
        ret = package_fini();
        DbgPrint("Finalize package info: %d\n", ret);
 
-       ret = dbus_fini();
+       ret = client_fini();
+       DbgPrint("Finalize client connections : %d\n", ret);
+
+       ret = server_fini();
        DbgPrint("Finalize dbus: %d\n", ret);
 
        ret = dead_fini();
@@ -126,13 +136,11 @@ static inline int app_terminate(void *data)
        ret = group_fini();
        DbgPrint("Group finalized: %d\n", ret);
 
-       ret = client_fini();
-       DbgPrint("Finalize client connections : %d\n", ret);
-
        DbgPrint("Terminated\n");
        return 0;
 }
 
+/*
 static int aul_handler_cb(aul_type type, bundle *kb, void *data)
 {
        int ret;
@@ -154,6 +162,7 @@ static int aul_handler_cb(aul_type type, bundle *kb, void *data)
 
        return ret;
 }
+*/
 
 int main(int argc, char *argv[])
 {
@@ -181,10 +190,12 @@ int main(int argc, char *argv[])
 
        script_init();
 
-       aul_launch_init(aul_handler_cb, NULL);
-       aul_launch_argv_handler(argc, argv);
+//     aul_launch_init(aul_handler_cb, NULL);
+//     aul_launch_argv_handler(argc, argv);
 
+       app_create(NULL);
        ecore_main_loop_begin();
+       app_terminate(NULL);
 
        script_fini();
 
index 9282edf..8d22f6c 100644 (file)
@@ -2,7 +2,6 @@
 #include <errno.h>
 #include <string.h> /* strcmp */
 #include <stdlib.h> /* free */
-#include <libgen.h> /* basename */
 
 #include <dlog.h>
 #include <Eina.h>
 #include "util.h"
 #include "parser.h"
 #include "conf.h"
+#include "packet.h"
 #include "slave_life.h"
+#include "slave_rpc.h"
 #include "client_life.h"
-#include "fault_manager.h"
 #include "package.h"
+#include "fault_manager.h"
 #include "instance.h"
 #include "fb.h"
 #include "script_handler.h"
@@ -134,6 +135,7 @@ static int slave_deactivated_cb(struct slave_node *slave, void *data)
                }
        } else {
                EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) {
+                       cnt += instance_need_slave(inst);
                        /*!
                         * instance_deactivated will call the slave_unload_instance.
                         * if the loaded instance counter meets 0,
@@ -143,7 +145,6 @@ static int slave_deactivated_cb(struct slave_node *slave, void *data)
                         *
                         * activate slave when the slave is reactivated
                         */
-                       cnt++;
                }
        }
 
@@ -373,6 +374,7 @@ struct pkg_info *package_create(const char *pkgname)
 
                DbgPrint("New slave name is %s assigned for %s\n", slavename, pkgname);
                info->slave = slave_create(slavename, info->secured);
+               slave_rpc_initialize(info->slave);
                free(slavename);
                /*!
                 * \note
@@ -413,6 +415,9 @@ struct pkg_info *package_find(const char *pkgname)
        Eina_List *l;
        struct pkg_info *info;
 
+       if (!pkgname)
+               return NULL;
+
        EINA_LIST_FOREACH(s_info.pkg_list, l, info) {
                if (!strcmp(info->pkgname, pkgname))
                        return info;
@@ -536,42 +541,42 @@ int package_clear_fault(struct pkg_info *info)
        return 0;
 }
 
-int const package_is_fault(struct pkg_info *info)
+const int const package_is_fault(const struct pkg_info *info)
 {
        return !!info->fault_info;
 }
 
-struct slave_node * const package_slave(struct pkg_info *info)
+struct slave_node * const package_slave(const struct pkg_info *info)
 {
        return info->slave;
 }
 
-int const package_timeout(struct pkg_info *info)
+const int const package_timeout(const struct pkg_info *info)
 {
        return info->timeout;
 }
 
-double const package_period(struct pkg_info *info)
+const double const package_period(const struct pkg_info *info)
 {
        return info->period;
 }
 
-int const package_secured(struct pkg_info *info)
+const int const package_secured(const struct pkg_info *info)
 {
        return info->secured;
 }
 
-const char * const package_script(struct pkg_info *info)
+const char * const package_script(const struct pkg_info *info)
 {
        return info->script;
 }
 
-const char * const package_abi(struct pkg_info *info)
+const char * const package_abi(const struct pkg_info *info)
 {
        return info->abi;
 }
 
-const char * const package_lb_path(struct pkg_info *info)
+const char * const package_lb_path(const struct pkg_info *info)
 {
        if (info->lb.type != LB_TYPE_SCRIPT)
                return NULL;
@@ -579,7 +584,7 @@ const char * const package_lb_path(struct pkg_info *info)
        return info->lb.info.script.path;
 }
 
-const char * const package_lb_group(struct pkg_info *info)
+const char * const package_lb_group(const struct pkg_info *info)
 {
        if (info->lb.type != LB_TYPE_SCRIPT)
                return NULL;
@@ -587,7 +592,7 @@ const char * const package_lb_group(struct pkg_info *info)
        return info->lb.info.script.group;
 }
 
-const char * const package_pd_path(struct pkg_info *info)
+const char * const package_pd_path(const struct pkg_info *info)
 {
        if (info->pd.type != PD_TYPE_SCRIPT)
                return NULL;
@@ -595,7 +600,7 @@ const char * const package_pd_path(struct pkg_info *info)
        return info->pd.info.script.path;
 }
 
-const char * const package_pd_group(struct pkg_info *info)
+const char * const package_pd_group(const struct pkg_info *info)
 {
        if (info->pd.type != PD_TYPE_SCRIPT)
                return NULL;
@@ -603,27 +608,27 @@ const char * const package_pd_group(struct pkg_info *info)
        return info->pd.info.script.group;
 }
 
-int const package_pinup(struct pkg_info *info)
+const int const package_pinup(const struct pkg_info *info)
 {
        return info->lb.pinup;
 }
 
-int const package_auto_launch(struct pkg_info *info)
+const int const package_auto_launch(const struct pkg_info *info)
 {
        return info->lb.auto_launch;
 }
 
-unsigned int const package_size_list(struct pkg_info *info)
+const unsigned int const package_size_list(const struct pkg_info *info)
 {
        return info->lb.size_list;
 }
 
-int const package_pd_width(struct pkg_info *info)
+const int const package_pd_width(const struct pkg_info *info)
 {
        return info->pd.width;
 }
 
-int const package_pd_height(struct pkg_info *info)
+const int const package_pd_height(const struct pkg_info *info)
 {
        return info->pd.height;
 }
@@ -650,17 +655,17 @@ struct pkg_info * const package_unref(struct pkg_info *info)
        return info;
 }
 
-int const package_refcnt(struct pkg_info *info)
+const int const package_refcnt(const struct pkg_info *info)
 {
        return info->refcnt;
 }
 
-enum lb_type package_lb_type(struct pkg_info *info)
+const enum lb_type package_lb_type(const struct pkg_info *info)
 {
        return info->lb.type;
 }
 
-enum pd_type package_pd_type(struct pkg_info *info)
+const enum pd_type const package_pd_type(const struct pkg_info *info)
 {
        return info->pd.type;
 }
@@ -746,7 +751,7 @@ const char *package_find_by_secured_slave(struct slave_node *slave)
        return NULL;
 }
 
-const char * const package_name(struct pkg_info *info)
+const char * const package_name(const struct pkg_info *info)
 {
        return info->pkgname;
 }
diff --git a/src/packet.c b/src/packet.c
new file mode 100644 (file)
index 0000000..7cc160a
--- /dev/null
@@ -0,0 +1,401 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include <dlog.h>
+
+#include "debug.h"
+#include "packet.h"
+#include "util.h"
+
+int errno;
+
+struct {
+       unsigned long seq;
+} s_info = {
+       .seq = 0lu,
+};
+
+struct data {
+       struct {
+               int version;
+               int payload_size;
+               char command[PACKET_MAX_CMD];
+               enum packet_type type;
+               unsigned long seq;
+       } head;
+
+       char payload[];
+};
+
+struct packet {
+       int refcnt;
+       struct data *data;
+};
+
+const enum packet_type const packet_type(const struct packet *packet)
+{
+       return packet->data->head.type;
+}
+
+const int const packet_version(const struct packet *packet)
+{
+       return packet->data->head.version;
+}
+
+const int const packet_header_size(void)
+{
+       struct data packet; /* Only for getting the size of header of packet */
+
+       return sizeof(packet.head);
+}
+
+const int const packet_size(const struct packet *packet)
+{
+       return sizeof(*packet->data) + packet->data->head.payload_size;
+}
+
+const unsigned long const packet_seq(const struct packet *packet)
+{
+       return packet->data->head.seq;
+}
+
+const int const packet_payload_size(const struct packet *packet)
+{
+       return packet->data->head.payload_size;
+}
+
+const char * const packet_command(const struct packet *packet)
+{
+       return packet->data->head.command;
+}
+
+const void * const packet_data(const struct packet *packet)
+{
+       return packet->data;
+}
+
+static inline struct data *check_and_expand_packet(struct data *packet, int *payload_size)
+{
+       struct data *new_packet;
+
+       if (packet->head.payload_size < *payload_size)
+               return packet;
+
+       new_packet = realloc(packet, sizeof(*packet) + *payload_size + BUFSIZ); /*!< Expanding to +BUFSIZ */
+       if (!new_packet) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               free(packet);
+               return NULL;
+       }
+
+       *payload_size += BUFSIZ;
+       return new_packet;
+}
+
+static inline struct packet *packet_body_filler(struct packet *packet, int payload_size, const char *ptr, va_list va)
+{
+       char *payload;
+       char *str;
+
+       while (*ptr) {
+               payload = packet->data->payload + packet->data->head.payload_size;
+
+               switch (*ptr) {
+               case 'i':
+               case 'I':
+                       packet->data->head.payload_size += sizeof(int);
+                       packet->data = check_and_expand_packet(packet->data, &payload_size);
+                       if (!packet->data) {
+                               free(packet);
+                               packet = NULL;
+                               goto out;
+                       }
+
+                       *((int *)payload) = (int)va_arg(va, int);
+                       break;
+               case 's':
+               case 'S':
+                       str = (char *)va_arg(va, char *);
+
+                       packet->data->head.payload_size += strlen(str) + 1; /*!< Including NIL */
+                       packet->data = check_and_expand_packet(packet->data, &payload_size);
+                       if (!packet->data) {
+                               free(packet);
+                               packet = NULL;
+                               goto out;
+                       }
+
+                       strcpy(payload, str); /*!< Including NIL */
+                       break;
+               case 'd':
+               case 'D':
+                       packet->data->head.payload_size += sizeof(double);
+                       packet->data = check_and_expand_packet(packet->data, &payload_size);
+                       if (!packet->data) {
+                               free(packet);
+                               packet = NULL;
+                               goto out;
+                       }
+
+                       *((double *)payload) = (double)va_arg(va, double);
+                       break;
+               default:
+                       ErrPrint("Invalid type [%c]\n", *ptr);
+                       free(packet->data);
+                       free(packet);
+                       packet = NULL;
+                       goto out;
+               }
+
+               ptr++;
+       }
+
+out:
+       return packet;
+}
+
+struct packet *packet_create_reply(struct packet *packet, const char *fmt, ...)
+{
+       int payload_size;
+       struct packet *result;
+       va_list va;
+
+       result = malloc(sizeof(*result));
+       if (!result) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       payload_size = sizeof(*result) + BUFSIZ;
+       result->refcnt = 0;
+       result->data = malloc(payload_size);
+       if (!packet->data) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       result->data->head.seq = packet->data->head.seq;
+       result->data->head.type = PACKET_ACK;
+       result->data->head.version = packet->data->head.version;
+       strcpy(result->data->head.command, packet->data->head.command);
+       result->data->head.payload_size = 0;
+       payload_size -= sizeof(*result->data);
+
+       va_start(va, fmt);
+       result = packet_body_filler(result, payload_size, fmt, va);
+       va_end(va);
+
+       return packet_ref(result);
+}
+
+struct packet *packet_create(const char *cmd, const char *fmt, ...)
+{
+       struct packet *packet;
+       int payload_size;
+       va_list va;
+
+       if (strlen(cmd) >= PACKET_MAX_CMD) {
+               ErrPrint("Command is too long\n");
+               return NULL;
+       }
+
+       packet = malloc(sizeof(*packet));
+       if (!packet) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       payload_size = sizeof(*packet) + BUFSIZ;
+       packet->refcnt = 0;
+       packet->data = malloc(payload_size);
+       if (!packet->data) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               free(packet);
+               return NULL;
+       }
+
+       packet->data->head.seq = s_info.seq++;
+       packet->data->head.type = PACKET_REQ;
+       packet->data->head.version = PACKET_VERSION;
+       strcpy(packet->data->head.command, cmd);
+       packet->data->head.payload_size = 0;
+       payload_size -= sizeof(*packet->data); /*!< Usable payload size (except head size) */
+
+       va_start(va, fmt);
+       packet = packet_body_filler(packet, payload_size, fmt, va);
+       va_end(va);
+
+       return packet_ref(packet);
+}
+
+struct packet *packet_create_noack(const char *cmd, const char *fmt, ...)
+{
+       int payload_size;
+       struct packet *result;
+       va_list va;
+
+       if (strlen(cmd) >= PACKET_MAX_CMD) {
+               ErrPrint("Command is too long\n");
+               return NULL;
+       }
+
+       result = malloc(sizeof(*result));
+       if (!result) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       payload_size = sizeof(*result) + BUFSIZ;
+       result->refcnt = 0;
+       result->data = malloc(payload_size);
+       if (!result->data) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               free(result);
+               return NULL;
+       }
+
+       result->data->head.seq = s_info.seq++;
+       result->data->head.type = PACKET_REQ_NOACK;
+       result->data->head.version = PACKET_VERSION;
+       strcpy(result->data->head.command, cmd);
+       result->data->head.payload_size = 0;
+       payload_size -= sizeof(*result->data);
+
+       va_start(va, fmt);
+       result = packet_body_filler(result, payload_size, fmt, va);
+       va_end(va);
+
+       return packet_ref(result);
+}
+
+int packet_get(const struct packet *packet, const char *fmt, ...)
+{
+       const char *ptr;
+       va_list va;
+       int ret = 0;
+       char *payload;
+       int offset = 0;
+       int *int_ptr;
+       double *double_ptr;
+       char **str_ptr;
+
+       va_start(va, fmt);
+
+       ptr = fmt;
+       while (*ptr) {
+               payload = packet->data->payload + offset;
+               switch (*ptr) {
+               case 'i':
+               case 'I':
+                       int_ptr = (int *)va_arg(va, int *);
+                       *int_ptr = *((int *)payload);
+                       offset += sizeof(int);
+                       ret++;
+                       break;
+               case 'd':
+               case 'D':
+                       double_ptr = (double *)va_arg(va, double *);
+                       *double_ptr = *((double *)payload);
+                       offset += sizeof(double);
+                       ret++;
+                       break;
+               case 's':
+               case 'S':
+                       str_ptr = (char **)va_arg(va, char **);
+                       *str_ptr = payload;
+                       offset += (strlen(*str_ptr) + 1); /*!< Including NIL */
+                       ret++;
+                       break;
+               default:
+                       ret = -EINVAL;
+                       goto out;
+               }
+               ptr++;
+       }
+
+out:
+       va_end(va);
+       return ret;
+}
+
+struct packet *packet_ref(struct packet *packet)
+{
+       if (!packet)
+               return NULL;
+
+       packet->refcnt++;
+       return packet;
+}
+
+struct packet *packet_unref(struct packet *packet)
+{
+       if (!packet)
+               return NULL;
+
+       packet->refcnt--;
+       if (packet->refcnt < 0) {
+               ErrPrint("Invalid refcnt\n");
+               return NULL;
+       }
+
+       if (packet->refcnt == 0) {
+               free(packet->data);
+               free(packet);
+               return NULL;
+       }
+
+       return packet;
+}
+
+int packet_destroy(struct packet *packet)
+{
+       packet_unref(packet);
+       return 0;
+}
+
+struct packet *packet_build(struct packet *packet, int offset, void *data, int size)
+{
+       char *ptr;
+
+       if (packet == NULL) {
+               if (offset) {
+                       ErrPrint("Invalid argument\n");
+                       return NULL;
+               }
+
+               packet = malloc(sizeof(*packet));
+               if (!packet) {
+                       ErrPrint("Heap: %s\n", strerror(errno));
+                       return NULL;
+               }
+
+               packet->refcnt = 1;
+               packet->data = malloc(size);
+               if (!packet->data) {
+                       ErrPrint("Heap: %s\n", strerror(errno));
+                       free(packet);
+                       return NULL;
+               }
+
+               memcpy(packet->data, data, size);
+               return packet;
+       }
+
+       ptr = realloc(packet->data, offset + size);
+       if (!ptr) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               free(packet->data);
+               free(packet);
+               return NULL;
+       }
+
+       packet->data = (struct data *)ptr;
+       memcpy(ptr + offset, data, size);
+
+       return packet;
+}
+
+/* End of a file */
index e24d2da..ea491ef 100644 (file)
 #include <stdio.h>
 #include <stdlib.h> /* strtod */
 #include <errno.h>
-#include <libgen.h> /* basename */
 #include <ctype.h> /* isspace */
 
 #include <Eina.h>
 
 #include <dlog.h>
 
+#include "util.h"
 #include "debug.h"
 #include "conf.h"
 #include "parser.h"
index 4a33d38..44c9930 100644 (file)
@@ -1,5 +1,4 @@
 #include <stdio.h>
-#include <libgen.h> /* basename */
 #include <errno.h>
 #include <stdlib.h> /* free */
 #include <ctype.h>
 #include <Ecore.h>
 #include <Evas.h>
 
-#include <gio/gio.h>
 #include <dlog.h>
 
 #include "slave_life.h"
+#include "packet.h"
 #include "slave_rpc.h"
 #include "client_life.h"
 #include "package.h"
@@ -125,7 +124,7 @@ static void render_post_cb(void *data, Evas *e, void *event_info)
 
        inst = data;
 
-       DbgPrint("Render post invoked (%s)[%s]\n", package_name(instance_package(inst)), basename(instance_id(inst)));
+       DbgPrint("Render post invoked (%s)[%s]\n", package_name(instance_package(inst)), util_basename(instance_id(inst)));
        evas_image_cache_flush(e);
        evas_font_cache_flush(e);
        evas_render_dump(e);
@@ -155,7 +154,7 @@ int script_signal_emit(Evas *e, const char *part, const char *signal, double sx,
        const char *pkgname;
        const char *filename;
        struct slave_node *slave;
-       GVariant *param;
+       struct packet *packet;
        int ret;
 
        ee = ecore_evas_ecore_evas_get(e);
@@ -179,17 +178,17 @@ int script_signal_emit(Evas *e, const char *part, const char *signal, double sx,
        pkgname = package_name(instance_package(info->inst));
        filename = instance_id(info->inst);
        slave = package_slave(instance_package(info->inst));
-       param = g_variant_new("(ssssddddddi)",
+       packet = packet_create("script", "ssssddddddi",
                        pkgname, filename,
                        signal, part,
                        sx, sy, ex, ey,
                        info->x, info->y, info->down);
-       if (!param) {
+       if (!packet) {
                ErrPrint("Failed to create param\n");
                return -EFAULT;
        }
 
-       ret = slave_rpc_async_request(slave, pkgname, filename, "script", param, NULL, NULL); 
+       ret = slave_rpc_async_request(slave, pkgname, packet, NULL, NULL); 
        return ret;
 }
 
@@ -284,7 +283,7 @@ struct script_info *script_handler_create(struct inst_info *inst, const char *fi
        if (!file)
                return NULL;
 
-       fname_len = strlen(g_conf.path.image) + strlen(basename((char*)file)) + 30;
+       fname_len = strlen(g_conf.path.image) + strlen(util_basename(file)) + 30;
 
        filename = malloc(fname_len);
        if (!filename) {
@@ -293,7 +292,7 @@ struct script_info *script_handler_create(struct inst_info *inst, const char *fi
        }
 
        snprintf(filename, fname_len, "%s%s.%lf",
-                       g_conf.path.image, basename((char*)file), util_timestamp());
+                       g_conf.path.image, util_basename(file), util_timestamp());
 
        info = calloc(1, sizeof(*info));
        if (!info) {
@@ -655,7 +654,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                return -EIO;
        }
 
-       DbgPrint("descfile: %s\n", basename((char *)descfile));
+       DbgPrint("descfile: %s\n", util_basename(descfile));
 
        state = UNKNOWN;
        field_idx = 0;
@@ -806,13 +805,14 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
 
                case VALUE_TYPE:
                        if (idx == block->type_len) {
+                               char *tmp;
                                block->type_len += ADDEND;
-                               block->type =
-                                       realloc(block->type, block->type_len);
-                               if (!block->type) {
+                               tmp = realloc(block->type, block->type_len);
+                               if (!tmp) {
                                        ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
+                               block->type = tmp;
                        }
 
                        if (ch == '\n') {
@@ -829,13 +829,14 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
 
                case VALUE_PART:
                        if (idx == block->part_len) {
+                               char *tmp;
                                block->part_len += ADDEND;
-                               block->part =
-                                       realloc(block->part, block->part_len);
-                               if (!block->part) {
+                               tmp = realloc(block->part, block->part_len);
+                               if (!tmp) {
                                        ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
+                               block->part = tmp;
                        }
 
                        if (ch == '\n') {
@@ -852,13 +853,14 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
 
                case VALUE_DATA:
                        if (idx == block->data_len) {
+                               char *tmp;
                                block->data_len += ADDEND;
-                               block->data =
-                                       realloc(block->data, block->data_len);
-                               if (!block->data) {
+                               tmp = realloc(block->data, block->data_len);
+                               if (!tmp) {
                                        ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
+                               block->data = tmp;
                        }
 
                        if (ch == '\n') {
@@ -875,13 +877,14 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
 
                case VALUE_FILE:
                        if (idx == block->file_len) {
+                               char *tmp;
                                block->file_len += ADDEND;
-                               block->file =
-                                       realloc(block->file, block->file_len);
-                               if (!block->file) {
+                               tmp = realloc(block->file, block->file_len);
+                               if (!tmp) {
                                        ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
+                               block->file = tmp;
                        }
 
                        if (ch == '\n') {
@@ -898,13 +901,14 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
 
                case VALUE_GROUP:
                        if (idx == block->group_len) {
+                               char *tmp;
                                block->group_len += ADDEND;
-                               block->group = realloc(block->group,
-                                                       block->group_len);
-                               if (!block->group) {
+                               tmp = realloc(block->group, block->group_len);
+                               if (!tmp) {
                                        ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
+                               block->group = tmp;
                        }
 
                        if (ch == '\n') {
@@ -920,12 +924,14 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                        break;
                case VALUE_ID:
                        if (idx == block->id_len) {
+                               char *tmp;
                                block->id_len += ADDEND;
-                               block->id = realloc(block->id, block->id_len);
-                               if (!block->id) {
+                               tmp = realloc(block->id, block->id_len);
+                               if (!tmp) {
                                        ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
+                               block->id = tmp;
                        }
 
                        if (ch == '\n') {
@@ -1001,7 +1007,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
        return 0;
 
 errout:
-       ErrPrint("Parse error at %d file %s\n", lineno, basename((char *)descfile));
+       ErrPrint("Parse error at %d file %s\n", lineno, util_basename(descfile));
        if (block) {
                free(block->file);
                free(block->type);
diff --git a/src/secom_socket.c b/src/secom_socket.c
new file mode 100644 (file)
index 0000000..0a5727a
--- /dev/null
@@ -0,0 +1,207 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <errno.h>
+
+#include <secom_socket.h>
+#include <dlog.h>
+
+int errno;
+
+static inline int create_socket(const char *peer, struct sockaddr_un *addr)
+{
+       int len;
+       int handle;
+
+       len = sizeof(*addr);
+       bzero(addr, len);
+
+       if (strlen(peer) >= sizeof(addr->sun_path)) {
+               LOGE("peer %s is too long to remember it\\n", peer);
+               return -1;
+       }
+
+       /* We can believe this has no prob, because
+        * we already check the size of add.rsun_path
+        */
+       strcpy(addr->sun_path, peer);
+       addr->sun_family = AF_UNIX;
+
+       handle = socket(PF_UNIX, SOCK_STREAM, 0);
+       if (handle < 0) {
+               LOGE("Failed to create a socket %s\n", strerror(errno));
+               return -1;
+       }
+
+       return handle;
+}
+
+int secom_create_client(const char *peer)
+{
+       struct sockaddr_un addr;
+       int handle;
+       int state;
+       int on = 1;
+
+       handle = create_socket(peer, &addr);
+       if (handle < 0)
+               return handle;
+
+       state = connect(handle, (struct sockaddr *)&addr, sizeof(addr));
+       if (state < 0) {
+               LOGE("Failed to connect to server [%s] %s\n",
+                                                       peer, strerror(errno));
+               if (close(handle) < 0)
+                       LOGE("close a handle: %s\n", strerror(errno));
+
+               return -1;
+       }
+
+       if (setsockopt(handle, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0)
+               LOGE("Failed to change sock opt : %s\n", strerror(errno));
+
+       return handle;
+}
+
+int secom_create_server(const char *peer)
+{
+       int handle;
+       int state;
+       struct sockaddr_un addr;
+
+       handle = create_socket(peer, &addr);
+       if (handle < 0)
+               return handle;
+
+       state = bind(handle, &addr, sizeof(addr));
+       if (state < 0) {
+               LOGE("Failed to bind a socket %s\n", strerror(errno));
+               if (close(handle) < 0)
+                       LOGE("Close a handle : %s\n", strerror(errno));
+
+               return -1;
+       }
+
+       state = listen(handle, 10); /* BACKLOG 10 */
+       if (state < 0) {
+               LOGE("Failed to listen a socket %s\n", strerror(errno));
+
+               if (close(handle) < 0)
+                       LOGE("Close a handle : %s\n", strerror(errno));
+
+               return -1;
+       }
+
+       if (chmod(peer, 0666) < 0)
+               LOGE("Failed to change the permission of a socket (%s)\n",
+                                                       strerror(errno));
+
+       return handle;
+}
+
+int secom_get_connection_handle(int server_handle)
+{
+       struct sockaddr_un addr;
+       int handle;
+       int on = 1;
+       socklen_t size = sizeof(addr);
+
+       handle = accept(server_handle, (struct sockaddr *)&addr, &size);
+       if (handle < 0) {
+               LOGE("Failed to accept a new client %s\n", strerror(errno));
+               return -1;
+       }
+
+       if (setsockopt(handle, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0)
+               LOGE("Failed to change sock opt : %s\n", strerror(errno));
+
+       return handle;
+}
+
+int secom_put_connection_handle(int conn_handle)
+{
+       if (close(conn_handle) < 0) {
+               LOGE("Close a handle: %s\n", strerror(errno));
+               return -1;
+       }
+
+       return 0;
+}
+
+int secom_send(int handle, const char *buffer, int size)
+{
+       struct msghdr msg;
+       struct iovec iov;
+       int ret;
+
+       memset(&msg, 0, sizeof(msg));
+       iov.iov_base = (char *)buffer;
+       iov.iov_len = size;
+       msg.msg_iov = &iov;
+       msg.msg_iovlen = 1;
+
+       ret = sendmsg(handle, &msg, 0);
+       if (ret < 0) {
+               LOGE("Failed to send message [%s]\n", strerror(errno));
+               return -1;
+       }
+
+       return iov.iov_len;
+}
+
+int secom_recv(int handle, char *buffer, int size, int *sender_pid)
+{
+       struct msghdr msg;
+       struct cmsghdr *cmsg;
+       struct iovec iov;
+       char control[1024];
+
+       if (!sender_pid)
+               return -1;
+
+       memset(&msg, 0, sizeof(msg));
+       iov.iov_base = buffer;
+       iov.iov_len = size;
+       msg.msg_iov = &iov;
+       msg.msg_iovlen = 1;
+       msg.msg_control = control;
+       msg.msg_controllen = sizeof(control);
+
+       if (recvmsg(handle, &msg, 0) < 0) {
+               LOGE("Failed to recvmsg [%s]\n", strerror(errno));
+               return -1;
+       }
+
+       cmsg = CMSG_FIRSTHDR(&msg);
+       while (cmsg) {
+               if (cmsg->cmsg_level == SOL_SOCKET
+                       && cmsg->cmsg_type == SCM_CREDENTIALS)  {
+                       struct ucred *cred;
+                       cred = (struct ucred *)CMSG_DATA(cmsg);
+                       *sender_pid = cred->pid;
+               }
+
+               cmsg = CMSG_NXTHDR(&msg, cmsg);
+       }
+
+       return iov.iov_len;
+}
+
+int secom_destroy(int handle)
+{
+       if (close(handle) < 0) {
+               LOGE("Failed to close a handle\n");
+               return -1;
+       }
+       return 0;
+}
+
+#undef _GNU_SOURCE
+/* End of a file */
diff --git a/src/server.c b/src/server.c
new file mode 100644 (file)
index 0000000..7c4dae9
--- /dev/null
@@ -0,0 +1,1428 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <dlog.h>
+#include <Evas.h>
+
+#include "conf.h"
+#include "debug.h"
+#include "server.h"
+#include "packet.h"
+#include "connector_packet.h"
+#include "slave_life.h"
+#include "slave_rpc.h"
+#include "client_life.h"
+#include "client_rpc.h"
+#include "instance.h"
+#include "package.h"
+#include "script_handler.h"
+#include "util.h"
+#include "fault_manager.h"
+
+static struct info {
+       int fd;
+} s_info = {
+       .fd = -1,
+};
+
+static struct packet *client_acquire(pid_t pid, int handle, struct packet *packet) /*!< timestamp, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       double timestamp;
+       int ret;
+
+       client = client_find_by_pid(pid);
+       if (client) {
+               ErrPrint("Client is already exists %d\n", pid);
+               ret = -EEXIST;
+               goto out;
+       }
+
+       packet_get(packet, "d", &timestamp);
+       DbgPrint("Acquired %lf\n", timestamp);
+
+       /*!
+        * \note
+        * client_create will invoke the client created callback
+        */
+       client = client_create(pid);
+       if (!client) {
+               ErrPrint("Failed to create a new client for %d\n", pid);
+               ret = -EFAULT;
+               goto out;
+       }
+
+       client_rpc_initialize(client, handle);
+       ret = 0;
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *cilent_release(pid_t pid, int handle, struct packet *packet) /*!< pid, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       int ret;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       client_destroy(client);
+       ret = 0;
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+/*!< pid, pkgname, filename, event, timestamp, x, y, ret */
+static struct packet *client_clicked(pid_t pid, int handle, struct packet *packet)
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       const char *event;
+       double timestamp;
+       double x;
+       double y;
+       int ret;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "sssddd", &pkgname, &id, &event, &timestamp, &x, &y);
+       if (ret != 6) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EFAULT;
+       else
+               ret = instance_clicked(inst, event, timestamp, x, y);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+/* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
+static struct packet *client_text_signal(pid_t pid, int handle, struct packet *packet)
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       const char *emission;
+       const char *source;
+       double sx;
+       double sy;
+       double ex;
+       double ey;
+       struct inst_info *inst;
+       int ret;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey);
+       if (ret != 8) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EAGAIN;
+       else
+               ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_delete(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       struct inst_info *inst;
+       int ret;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ss", &pkgname, &id);
+       if (ret != 2) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               ret = -EAGAIN;
+       } else {
+               if (instance_state(inst) == INST_DEACTIVATED)
+                       instance_broadcast_deleted_event(inst);
+
+               ret = instance_destroy(inst);
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_resize(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, w, h, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int w;
+       int h;
+       struct inst_info *inst;
+       int ret;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h);
+       if (ret != 4) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EAGAIN;
+       else
+               ret = instance_resize(inst, w, h);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_new(pid_t pid, int handle, struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *content;
+       const char *cluster;
+       const char *category;
+       double period;
+       double timestamp;
+       int ret;
+       struct pkg_info *info;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "dssssd", &timestamp, &pkgname, &content, &cluster, &category, &period);
+       if (ret != 6) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       info = package_find(pkgname);
+       if (!info)
+               info = package_create(pkgname);
+
+       if (!info) {
+               ret = -EFAULT;
+       } else if (package_is_fault(info)) {
+               ret = -EAGAIN;
+       } else {
+               struct inst_info *inst;
+
+               if (period > 0.0f && period < MINIMUM_PERIOD)
+                       period = MINIMUM_PERIOD;
+
+               inst = instance_create(client, timestamp, pkgname, content, cluster, category, period);
+               /*!
+                * \note
+                * Using the "inst" without validate its value is at my disposal. ;)
+                */
+               ret = instance_activate(inst);
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_set_period(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, period, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       double period;
+       int ret;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssd", &pkgname, &id, &period);
+       if (ret != 3) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EFAULT;
+       else
+               ret = instance_set_period(inst, period);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_change_group(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       const char *cluster;
+       const char *category;
+       struct inst_info *inst;
+       int ret;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
+       if (ret != 4) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EAGAIN;
+       else
+               ret = instance_change_group(inst, cluster, category);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_pd_mouse_down(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, id, width, height, timestamp, x, y, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               ret = -EAGAIN;
+       } else {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_pd_handle(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, 1);
+               evas_event_feed_mouse_in(e, timestamp, NULL);
+               evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
+               evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
+               ret = 0;
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_pd_mouse_up(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               ret = -EAGAIN;
+       } else {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_pd_handle(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, 0);
+               evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp, NULL);
+               evas_event_feed_mouse_out(e, timestamp + 0.01f, NULL);
+               ret = 0;
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_pd_mouse_move(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               ret = -EAGAIN;
+       } else {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_pd_handle(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, -1);
+               evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
+               ret = 0;
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_lb_mouse_move(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               ret = -EAGAIN;
+       } else {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_lb_handle(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, -1);
+               evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
+               ret = 0;
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_lb_mouse_down(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               ret = -EAGAIN;
+       } else {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_lb_handle(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, 1);
+               evas_event_feed_mouse_in(e, timestamp, NULL);
+               evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
+               evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
+               ret = 0;
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_lb_mouse_up(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       int w;
+       int h;
+       double timestamp;
+       double x;
+       double y;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
+       if (ret != 7) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               /*!
+                * \note
+                * If the package is registered as fault module,
+                * slave has not load it, so we don't need to do anything at here!
+                */
+               ret = -EAGAIN;
+       } else {
+               struct script_info *script;
+               Evas *e;
+
+               script = instance_lb_handle(inst);
+               if (!script) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               e = script_handler_evas(script);
+               if (!e) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
+               script_handler_update_pointer(script, x, y, 0);
+               evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp, NULL);
+               evas_event_feed_mouse_out(e, timestamp + 0.01f, NULL);
+               ret = 0;
+       }
+
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_pinup_changed(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, pinup, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int pinup;
+       int ret;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
+       if (ret != 3) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EFAULT;
+       else
+               ret = instance_set_pinup(inst, pinup);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_create_pd(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ss", &pkgname, &id);
+       if (ret != 2) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EFAULT;
+       else
+               ret = script_handler_load(instance_pd_handle(inst), 1);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_destroy_pd(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, filename, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       struct inst_info *inst;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ss", &pkgname, &id);
+       if (ret != 2) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EFAULT;
+       else
+               ret = script_handler_unload(instance_pd_handle(inst), 1);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_activate_package(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       int ret;
+       struct pkg_info *info;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "s", &pkgname);
+       if (ret != 1) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       info = package_find(pkgname);
+       if (!info)
+               ret = -ENOENT;
+       else
+               ret = package_clear_fault(info);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *client_livebox_is_exists(pid_t pid, int handle, struct packet *packet) /* pid, pkgname, ret */
+{
+       struct client_node *client;
+       struct packet *result;
+       const char *pkgname;
+       int ret;
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "s", &pkgname);
+       if (ret != 1) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = util_validate_livebox_package(pkgname);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *slave_hello(pid_t pid, int handle, struct packet *packet) /* slave_name, ret */
+{
+       struct slave_node *slave;
+       struct packet *result;
+       const char *slavename;
+       int ret;
+
+       slave = slave_find_by_pid(pid);
+       if (!slave) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "s", &slavename);
+       if (ret != 1) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       /*!
+        * \note
+        * After updating handle,
+        * slave activated callback will be called.
+        */
+       slave_rpc_update_handle(slave, handle);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *slave_ping(pid_t pid, int handle, struct packet *packet) /* slave_name, ret */
+{
+       struct slave_node *slave;
+       struct packet *result;
+       const char *slavename;
+       int ret;
+
+       slave = slave_find_by_pid(pid);
+       if (!slave) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "s", &slavename);
+       if (ret != 1) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       slave_rpc_ping(slave);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *slave_call(pid_t pid, int handle, struct packet *packet) /* slave_name, pkgname, filename, function, ret */
+{
+       struct slave_node *slave;
+       struct packet *result;
+       const char *slavename;
+       const char *pkgname;
+       const char *id;
+       const char *func;
+       int ret;
+
+       slave = slave_find_by_pid(pid);
+       if (!slave) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &func);
+       if (ret != 4) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = fault_func_call(slave, pkgname, id, func);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *slave_ret(pid_t pid, int handle, struct packet *packet) /* slave_name, pkgname, filename, function, ret */
+{
+       struct slave_node *slave;
+       struct packet *result;
+       const char *slavename;
+       const char *pkgname;
+       const char *id;
+       const char *func;
+       int ret;
+
+       slave = slave_find_by_pid(pid);
+       if (!slave) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &func);
+       if (ret != 4) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = fault_func_ret(slave, pkgname, id, func);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *slave_updated(pid_t pid, int handle, struct packet *packet) /* slave_name, pkgname, filename, width, height, priority, ret */
+{
+       struct slave_node *slave;
+       struct packet *result;
+       const char *slavename;
+       const char *pkgname;
+       const char *id;
+       int w;
+       int h;
+       double priority;
+       int ret;
+       struct inst_info *inst;
+
+       slave = slave_find_by_pid(pid);
+       if (!slave) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "sssiid", &slavename, &pkgname, &id, &w, &h, &priority);
+       if (ret != 6) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               ErrPrint("Faulted instance cannot make any event.\n");
+               ret = -EAGAIN;
+       } else if (instance_state(inst) == INST_DESTROYED) {
+               ErrPrint("Instance is already destroyed\n");
+               ret = -EINVAL;
+       } else {
+               instance_set_lb_info(inst, w, h, priority);
+
+               if (package_lb_type(instance_package(inst)) == LB_TYPE_SCRIPT) {
+                       script_handler_resize(instance_lb_handle(inst), w, h);
+                       ret = script_handler_parse_desc(pkgname, id, id, 0);
+               } else {
+                       /*!
+                        * \check
+                        * text format (inst)
+                        */
+                       instance_lb_updated(pkgname, id);
+                       ret = 0;
+               }
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *slave_desc_updated(pid_t pid, int handle, struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
+{
+       struct slave_node *slave;
+       struct packet *result;
+       const char *slavename;
+       const char *pkgname;
+       const char *id;
+       const char *descfile;
+       int ret;
+       struct inst_info *inst;
+
+       slave = slave_find_by_pid(pid);
+       if (!slave) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &descfile);
+       if (ret != 4) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst) {
+               ret = -ENOENT;
+       } else if (package_is_fault(instance_package(inst))) {
+               ErrPrint("Faulted package cannot make event\n");
+               ret = -EAGAIN;
+       } else if (instance_state(inst) == INST_DESTROYED) {
+               ErrPrint("Instance is already destroyed\n");
+               ret = -EINVAL;
+       } else if (package_pd_type(instance_package(inst)) == PD_TYPE_TEXT) {
+               instance_set_pd_info(inst, 0, 0);
+               instance_pd_updated(pkgname, id, descfile);
+               ret = 0;
+       } else if (script_handler_is_loaded(instance_pd_handle(inst))) {
+               ret = script_handler_parse_desc(pkgname, id, descfile, 1);
+       } else {
+               ret = 0;
+       }
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct packet *slave_deleted(pid_t pid, int handle, struct packet *packet) /* slave_name, pkgname, id, ret */
+{
+       struct slave_node *slave;
+       struct packet *result;
+       const char *slavename;
+       const char *pkgname;
+       const char *id;
+       int ret;
+       struct inst_info *inst;
+
+       slave = slave_find_by_pid(pid);
+       if (!slave) {
+               ErrPrint("Client %d is not exists\n", pid);
+               ret = -ENOENT;
+               goto out;
+       }
+
+       ret = packet_get(packet, "sss", &slavename, &pkgname, &id);
+       if (ret != 3) {
+               ErrPrint("Parameter is not matched\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               ret = -ENOENT;
+       else if (package_is_fault(instance_package(inst)))
+               ret = -EAGAIN;
+       else
+               ret = instance_destroyed(inst);
+
+out:
+       result = packet_create_reply(packet, "i", ret);
+       if (!result)
+               ErrPrint("Failed to create a packet\n");
+
+       return result;
+}
+
+static struct method s_table[] = {
+       /*!
+        * \note
+        * service for client
+        */
+       {
+               .cmd = "acquire",
+               .handler = client_acquire, /*!< pid, ret */
+       },
+       {
+               .cmd = "release",
+               .handler = cilent_release, /*!< pid, ret */
+       },
+       {
+               .cmd = "clicked",
+               .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
+       },
+       {
+               .cmd = "text_signal",
+               .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
+       },
+       {
+               .cmd = "delete",
+               .handler = client_delete, /* pid, pkgname, filename, ret */
+       },
+       {
+               .cmd = "resize",
+               .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
+       },
+       {
+               .cmd = "new",
+               .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
+       },
+       {
+               .cmd = "set_period",
+               .handler = client_set_period, /* pid, pkgname, filename, period, ret */
+       },
+       {
+               .cmd = "change_group",
+               .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
+       },
+       {
+               .cmd = "pd_mouse_down",
+               .handler = client_pd_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
+       },
+       {
+               .cmd = "pd_mouse_up",
+               .handler = client_pd_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+       },
+       {
+               .cmd = "pd_mouse_move",
+               .handler = client_pd_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+       },
+       {
+               .cmd = "lb_mouse_move",
+               .handler = client_lb_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+       },
+       {
+               .cmd = "lb_mouse_down",
+               .handler = client_lb_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+       },
+       {
+               .cmd = "lb_mouse_up",
+               .handler = client_lb_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
+       },
+       {
+               .cmd = "pinup_changed",
+               .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
+       },
+       {
+               .cmd = "create_pd",
+               .handler = client_create_pd, /* pid, pkgname, filename, ret */
+       },
+       {
+               .cmd = "destroy_pd",
+               .handler = client_destroy_pd, /* pid, pkgname, filename, ret */
+       },
+       {
+               .cmd = "activate_package",
+               .handler = client_activate_package, /* pid, pkgname, ret */
+       },
+       {
+               .cmd = "livebox_is_exists",
+               .handler = client_livebox_is_exists, /* pid, pkgname, ret */
+       },
+       /*!
+        * \note services for slave
+        */
+       {
+               .cmd = "hello",
+               .handler = slave_hello, /* slave_name, ret */
+       },
+       {
+               .cmd = "ping",
+               .handler = slave_ping, /* slave_name, ret */
+       },
+       {
+               .cmd = "call",
+               .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
+       },
+       {
+               .cmd = "ret",
+               .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
+       },
+       {
+               .cmd = "updated",
+               .handler = slave_updated, /* slave_name, pkgname, filename, width, height, priority, ret */
+       },
+       {
+               .cmd = "desc_updated",
+               .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
+       },
+       {
+               .cmd = "deleted",
+               .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
+       },
+       {
+               .cmd = NULL,
+               .handler = NULL,
+       },
+};
+
+int server_init(void)
+{
+       if (unlink("/tmp/.live.socket") < 0)
+               ErrPrint("unlink: %s\n", strerror(errno));
+
+       s_info.fd = connector_packet_server_init("/tmp/.live.socket", s_table);
+       if (s_info.fd < 0) {
+               ErrPrint("Failed to create a server socket\n");
+               return s_info.fd;
+       }
+
+       chmod("/tmp/.live.socket", 0666);
+       return 0;
+}
+
+int server_fini(void)
+{
+       connector_packet_server_fini(s_info.fd);
+       return 0;
+}
+
+/* End of a file */
index 10fb68e..4b9b9bf 100644 (file)
@@ -1,11 +1,11 @@
 #include <stdio.h>
 #include <unistd.h>
-#include <libgen.h>
 
 #include <vconf.h>
 #include <dlog.h>
 
 #include "setting.h"
+#include "util.h"
 #include "debug.h"
 #include "slave_life.h"
 
index 748e819..af50167 100644 (file)
@@ -3,7 +3,6 @@
 #include <errno.h> /* errno */
 #include <unistd.h> /* pid_t */
 #include <stdlib.h> /* free */
-#include <libgen.h> /* basename */
 #include <pthread.h>
 
 #include <Eina.h>
@@ -15,6 +14,7 @@
 
 #include <gio/gio.h> /* GDBusProxy */
 
+#include "packet.h"
 #include "slave_life.h"
 #include "slave_rpc.h"
 #include "client_life.h"
@@ -221,7 +221,7 @@ struct slave_node *slave_unref(struct slave_node *slave)
        return slave;
 }
 
-int const slave_refcnt(struct slave_node *slave)
+const int const slave_refcnt(struct slave_node *slave)
 {
        return slave->refcnt;
 }
@@ -240,7 +240,6 @@ struct slave_node *slave_create(const char *name, int is_secured)
        slave = create_slave_node(name, is_secured);
        slave_ref(slave);
 
-       slave_rpc_initialize(slave);
        return slave;
 }
 
@@ -272,7 +271,7 @@ static inline void invoke_activate_cb(struct slave_node *slave)
        }
 }
 
-int const slave_is_faulted(struct slave_node *slave)
+const int const slave_is_faulted(const struct slave_node *slave)
 {
        return slave->faulted;
 }
@@ -367,8 +366,6 @@ int slave_deactivate(struct slave_node *slave)
        if (aul_terminate_pid(pid) < 0)
                ErrPrint("Terminate failed. pid %d\n", pid);
 
-       slave_rpc_reset_proxy(slave);
-
        invoke_deactivate_cb(slave);
 
        slave->state = SLAVE_PAUSED;
@@ -393,8 +390,6 @@ void slave_faulted(struct slave_node *slave)
        if (aul_terminate_pid(pid) < 0)
                ErrPrint("Terminate failed, pid %d\n", pid);
 
-       slave_rpc_reset_proxy(slave);
-
        invoke_deactivate_cb(slave);
        slave->state = SLAVE_TERMINATED;
        slave_unref(slave);
@@ -416,14 +411,13 @@ void slave_deactivated_by_fault(struct slave_node *slave)
 
        slave->pid = (pid_t)-1;
        slave->fault_count++;
-       slave_rpc_reset_proxy(slave);
 
        invoke_deactivate_cb(slave);
        slave->state = SLAVE_TERMINATED;
        slave_unref(slave);
 }
 
-int slave_is_activated(struct slave_node *slave)
+const int const slave_is_activated(struct slave_node *slave)
 {
        return slave->pid != (pid_t)-1;
 }
@@ -667,49 +661,54 @@ void slave_check_pause_or_resume(void)
        }
 }
 
-int const slave_is_secured(struct slave_node *slave)
+const int const slave_is_secured(const struct slave_node *slave)
 {
        return slave->secured;
 }
 
-const char * const slave_name(struct slave_node *slave)
+const char * const slave_name(const struct slave_node *slave)
 {
        return slave->name;
 }
 
-pid_t const slave_pid(struct slave_node *slave)
+const pid_t const slave_pid(const struct slave_node *slave)
 {
        return slave->pid;
 }
 
-static void resume_cb(struct slave_node *slave, const char *func, GVariant *result, void *data)
+static void resume_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        int ret;
 
-       if (!result) {
+       if (!packet) {
                ErrPrint("Failed to change the state of the slave\n");
                slave->state = SLAVE_PAUSED;
                return;
        }
 
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
+       if (packet_get(packet, "i", &ret) != 1) {
+               ErrPrint("Invalid parameter\n");
+               return;
+       }
+
        if (ret == 0)
                slave->state = SLAVE_RESUMED;
 }
 
-static void pause_cb(struct slave_node *slave, const char *func, GVariant *result, void *data)
+static void pause_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        int ret;
 
-       if (!result) {
+       if (!packet) {
                ErrPrint("Failed to change the state of the slave\n");
                slave->state = SLAVE_RESUMED;
                return;
        }
 
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
+       if (packet_get(packet, "i", &ret) != 1) {
+               ErrPrint("Invalid parameter\n");
+               return;
+       }
 
        if (ret == 0)
                slave->state = SLAVE_PAUSED;
@@ -718,41 +717,41 @@ static void pause_cb(struct slave_node *slave, const char *func, GVariant *resul
 int slave_resume(struct slave_node *slave)
 {
        double timestamp;
-       GVariant *param;
+       struct packet *packet;
 
        if (slave->state == SLAVE_RESUMED || slave->state == SLAVE_REQUEST_TO_RESUME)
                return 0;
 
        timestamp = util_timestamp();
 
-       param = g_variant_new("(d)", timestamp);
-       if (!param) {
+       packet = packet_create("resume", "d", timestamp);
+       if (!packet) {
                ErrPrint("Failed to prepare param\n");
                return -EFAULT;
        }
 
        slave->state = SLAVE_REQUEST_TO_RESUME;
-       return slave_rpc_async_request(slave, NULL, NULL, "resume", param, resume_cb, NULL);
+       return slave_rpc_async_request(slave, NULL, packet, resume_cb, NULL);
 }
 
 int slave_pause(struct slave_node *slave)
 {
        double timestamp;
-       GVariant *param;
+       struct packet *packet;
 
        if (slave->state == SLAVE_PAUSED || slave->state == SLAVE_REQUEST_TO_PAUSE)
                return 0;
 
        timestamp = util_timestamp();
 
-       param = g_variant_new("(d)", timestamp);
-       if (!param) {
+       packet = packet_create("pause", "d", timestamp);
+       if (!packet) {
                ErrPrint("Failed to prepare param\n");
                return -EFAULT;
        }
 
        slave->state = SLAVE_REQUEST_TO_PAUSE;
-       return slave_rpc_async_request(slave, NULL, NULL, "pause", param, pause_cb, NULL);
+       return slave_rpc_async_request(slave, NULL, packet, pause_cb, NULL);
 }
 
 /* End of a file */
index 5049381..e975145 100644 (file)
@@ -3,16 +3,14 @@
 #include <errno.h> /* errno */
 #include <unistd.h> /* pid_t */
 #include <stdlib.h> /* free */
-#include <libgen.h> /* basename */
 
 #include <Eina.h>
 #include <Ecore.h>
 
 #include <dlog.h>
 
-#include <gio/gio.h> /* GDBusProxy */
-
 #include "debug.h"
+#include "packet.h"
 #include "slave_life.h"
 #include "slave_rpc.h"
 #include "client_life.h"
 #include "fault_manager.h"
 #include "util.h"
 #include "conf.h"
+#include "connector_packet.h"
 
 struct slave_rpc {
        Ecore_Timer *pong_timer;
-       GDBusProxy *proxy;
-
-       Eina_List *pending_request_list;
+       int handle;
 
        unsigned long ping_count;
        unsigned long next_ping_count;
+       Eina_List *pending_list;
+
+       struct slave_node *slave;
 };
 
-struct packet {
-       /* create_packet, destroy_packet will care these varaibles */
+struct command {
+       /* create_command, destroy_command will care these varaibles */
        char *pkgname;
-       char *filename;
-       char *cmd;
-       GVariant *param;
+       struct packet *packet;
        struct slave_node *slave;
 
        /* Don't need to care these data */
-       void (*ret_cb)(struct slave_node *slave, const char *funcname, GVariant *result, void *cbdata);
+       void (*ret_cb)(struct slave_node *slave, const struct packet *packet, void *cbdata);
        void *cbdata;
 };
 
 static struct info {
-       Eina_List *packet_list;
-       Ecore_Timer *packet_consuming_timer;
+       Eina_List *command_list;
+       Eina_List *rpc_list;
+       Ecore_Timer *command_consuming_timer;
 } s_info = {
-       .packet_list = NULL,
-       .packet_consuming_timer = NULL,
+       .command_list = NULL,
+       .command_consuming_timer = NULL,
+       .rpc_list = NULL,
 };
 
-static inline struct packet *create_packet(struct slave_node *slave, const char *pkgname, const char *filename, const char *cmd, GVariant *param)
+static inline struct command *create_command(struct slave_node *slave, const char *pkgname, struct packet *packet)
 {
-       struct packet *packet;
+       struct command *command;
 
-       packet = calloc(1, sizeof(*packet));
-       if (!packet) {
+       command = calloc(1, sizeof(*command));
+       if (!command) {
                ErrPrint("Heap: %s\n", strerror(errno));
                return NULL;
        }
 
        if (pkgname) {
-               packet->pkgname = strdup(pkgname);
-               if (!packet->pkgname) {
-                       ErrPrint("Heap: %s\n", strerror(errno));
-                       free(packet);
-                       return NULL;
-               }
-       }
-
-       if (filename) {
-               packet->filename = strdup(filename);
-               if (!packet->filename) {
-                       ErrPrint("Heap: %s\n", strerror(errno));
-                       free(packet->pkgname);
-                       free(packet);
-                       return NULL;
-               }
-       }
-
-       if (cmd) {
-               packet->cmd = strdup(cmd);
-               if (!packet->cmd) {
+               command->pkgname = strdup(pkgname);
+               if (!command->pkgname) {
                        ErrPrint("Heap: %s\n", strerror(errno));
-                       free(packet->pkgname);
-                       free(packet->filename);
-                       free(packet);
+                       free(command);
                        return NULL;
                }
        }
 
-       packet->slave = slave_ref(slave); /*!< To prevent from destroying of the slave while communicating with the slave */
-       packet->param = g_variant_ref(param);
+       command->slave = slave_ref(slave); /*!< To prevent from destroying of the slave while communicating with the slave */
+       command->packet = packet_ref(packet);
 
-       return packet;
+       return command;
 }
 
-static inline void destroy_packet(struct packet *packet)
+static inline void destroy_command(struct command *command)
 {
-       slave_unref(packet->slave);
-       g_variant_unref(packet->param);
-       free(packet->pkgname);
-       free(packet->filename);
-       free(packet->cmd);
-       free(packet);
+       slave_unref(command->slave);
+       packet_unref(command->packet);
+       free(command->pkgname);
+       free(command);
 }
 
-static inline struct packet *pop_packet(void)
+static inline struct command *pop_command(void)
 {
-       struct packet *packet;
+       struct command *command;
 
-       packet = eina_list_nth(s_info.packet_list, 0);
-       if (!packet)
+       command = eina_list_nth(s_info.command_list, 0);
+       if (!command)
                return NULL;
 
-       s_info.packet_list = eina_list_remove(s_info.packet_list, packet);
-       return packet;
+       s_info.command_list = eina_list_remove(s_info.command_list, command);
+       return command;
 }
 
-static void slave_async_cb(GDBusProxy *proxy, GAsyncResult *result, void *data)
+static int slave_async_cb(pid_t pid, int handle, const struct packet *packet, void *data)
 {
-       struct packet *packet;
-       GError *err;
-       GVariant *param;
-
-       packet = data;
+       struct command *command = data;
 
-       if (!packet) {
+       if (!command) {
                ErrPrint("Packet is NIL\n");
-               return;
+               return 0;
        }
 
        /*!
         * \note
-        * packet->param is not valid from here.
+        * command->packet is not valid from here.
         */
-       if (!slave_is_activated(packet->slave)) {
+       if (!slave_is_activated(command->slave)) {
                ErrPrint("Slave is not activated (accidently dead)\n");
-               if (packet->ret_cb)
-                       packet->ret_cb(packet->slave, packet->cmd, NULL, packet->cbdata);
+               if (command->ret_cb)
+                       command->ret_cb(command->slave, packet, command->cbdata);
+
                goto out;
        }
 
-       err = NULL;
-       param = g_dbus_proxy_call_finish(proxy, result, &err);
-       if (!param) {
-               char *cmd;
-               //struct slave_rpc *rpc;
-
-               cmd = packet->cmd ? packet->cmd : "";
-
-               if (err) {
-                       ErrPrint("package[%s], cmd[%s]: %s\n", packet->pkgname, cmd, err->message);
-                       g_error_free(err);
-               }
-
-               if (packet->ret_cb)
-                       packet->ret_cb(packet->slave, cmd, NULL, packet->cbdata);
-
-               #if 0
-               char *filename;
-               if (!fault_is_occured() && packet->pkgname) {
-                       /*!
-                        * \note
-                        * Recording the fault information.
-                        * slave cannot detect its crash if a livebox
-                        * uses callback, not only update_content but also other functions.
-                        * To fix that case, mark the fault again from here.
-                        */
-                       filename = packet->filename ? packet->filename : "";
-                       fault_func_call(packet->slave, packet->pkgname, filename, cmd);
-               }
-               #endif
-
-               /*!
-                * \note
-                * Something is goging wrong.
-                * Try to deactivate this.
-                * And it will raise up the dead signal.
-                * then the dead signal callback will check the fault package.
-                * So we don't need to check the fault package from here.
-                */
-               //rpc = slave_data(packet->slave, "rpc");
-               //if (rpc && rpc->proxy == proxy)
-               slave_faulted(packet->slave);
+       if (!packet) {
+               if (command->ret_cb)
+                       command->ret_cb(command->slave, packet, command->cbdata);
 
+               slave_faulted(command->slave);
                goto out;
        }
 
-       if (packet->ret_cb)
-               packet->ret_cb(packet->slave, packet->cmd, param, packet->cbdata);
-       else
-               g_variant_unref(param);
+       if (command->ret_cb)
+               command->ret_cb(command->slave, packet, command->cbdata);
 
 out:
-       destroy_packet(packet);
+       destroy_command(command);
+       return 0;
 }
 
-static Eina_Bool packet_consumer_cb(void *data)
+static Eina_Bool command_consumer_cb(void *data)
 {
-       struct packet *packet;
-       struct pkg_info *info = NULL;
+       struct command *command;
+       struct slave_rpc *rpc;
 
-       packet = pop_packet();
-       if (!packet) {
-               s_info.packet_consuming_timer = NULL;
+       command = pop_command();
+       if (!command) {
+               s_info.command_consuming_timer = NULL;
                return ECORE_CALLBACK_CANCEL;
        }
 
-       if (packet->pkgname)
-               info = package_find(packet->pkgname);
+       if (!slave_is_activated(command->slave)) {
+               ErrPrint("Slave is not activated: %s(%d)\n",
+                               slave_name(command->slave), slave_pid(command->slave));
+               goto errout;
+       }
 
-       if ((info && package_is_fault(info)) || !slave_is_activated(packet->slave)) {
-               if (packet->ret_cb)
-                       packet->ret_cb(packet->slave, packet->cmd, NULL, packet->cbdata);
-               destroy_packet(packet);
+       if (!command->pkgname) {
+               /*!
+                * \note
+                * pause or resume command has no package name
+                */
+               DbgPrint("Package name is not specified: command(%s)\n",
+                                               packet_command(command->packet));
        } else {
-               struct slave_rpc *rpc;
-
-               rpc = slave_data(packet->slave, "rpc");
-               if (!rpc) {
-                       ErrPrint("Slave has no rpc info\n");
-                       if (packet->ret_cb)
-                               packet->ret_cb(packet->slave, packet->cmd, NULL, packet->cbdata);
-                       destroy_packet(packet);
-                       return ECORE_CALLBACK_RENEW;
+               struct pkg_info *info;
+
+               info = package_find(command->pkgname);
+               if (info && package_is_fault(info)) {
+                       ErrPrint("info: %p (%s) is fault package\n", info, command->pkgname);
+                       goto errout;
                }
+       }
 
-               g_dbus_proxy_call(rpc->proxy, packet->cmd, packet->param,
-                               G_DBUS_CALL_FLAGS_NO_AUTO_START,
-                               -1, NULL, (GAsyncReadyCallback)slave_async_cb, packet);
+       rpc = slave_data(command->slave, "rpc");
+       if (!rpc) {
+               ErrPrint("Slave has no rpc info\n");
+               goto errout;
        }
 
+       if (connector_packet_async_send(rpc->handle, command->packet, slave_async_cb, command) == 0)
+               return ECORE_CALLBACK_RENEW;
+
+errout:
+       if (command->ret_cb)
+               command->ret_cb(command->slave, NULL, command->cbdata);
+       destroy_command(command);
        return ECORE_CALLBACK_RENEW;
 }
 
-static inline void push_packet(struct packet *packet)
+static inline void push_command(struct command *command)
 {
-       s_info.packet_list = eina_list_append(s_info.packet_list, packet);
+       s_info.command_list = eina_list_append(s_info.command_list, command);
 
-       if (s_info.packet_consuming_timer)
+       if (s_info.command_consuming_timer)
                return;
 
-       s_info.packet_consuming_timer = ecore_timer_add(PACKET_TIME, packet_consumer_cb, NULL);
-       if (!s_info.packet_consuming_timer) {
-               ErrPrint("Failed to add packet consumer\n");
-               s_info.packet_list = eina_list_remove(s_info.packet_list, packet);
-               destroy_packet(packet);
+       s_info.command_consuming_timer = ecore_timer_add(PACKET_TIME, command_consumer_cb, NULL);
+       if (!s_info.command_consuming_timer) {
+               ErrPrint("Failed to add command consumer\n");
+               s_info.command_list = eina_list_remove(s_info.command_list, command);
+               destroy_command(command);
        }
 }
 
 static int slave_deactivate_cb(struct slave_node *slave, void *data)
 {
        struct slave_rpc *rpc;
-       struct packet *packet;
+       struct command *command;
+       Eina_List *l;
+       Eina_List *n;
 
        rpc = slave_data(slave, "rpc");
        if (!rpc) {
@@ -266,27 +215,15 @@ static int slave_deactivate_cb(struct slave_node *slave, void *data)
                return -EINVAL;
        }
 
-       if (rpc->proxy) {
-               Eina_List *l;
-               Eina_List *n;
-
-               g_object_unref(rpc->proxy);
-               rpc->proxy = NULL;
-
-               if (rpc->pong_timer)
-                       ecore_timer_del(rpc->pong_timer);
-               else
-                       ErrPrint("slave has no pong timer\n");
+       if (rpc->pong_timer)
+               ecore_timer_del(rpc->pong_timer);
+       else
+               ErrPrint("slave has no pong timer\n");
 
-               EINA_LIST_FOREACH_SAFE(s_info.packet_list, l, n, packet) {
-                       if (packet->slave == slave) {
-                               s_info.packet_list = eina_list_remove(s_info.packet_list, packet);
-                               destroy_packet(packet);
-                       }
-               }
-       } else {
-               EINA_LIST_FREE(rpc->pending_request_list, packet) {
-                       destroy_packet(packet);
+       EINA_LIST_FOREACH_SAFE(s_info.command_list, l, n, command) {
+               if (command->slave == slave) {
+                       s_info.command_list = eina_list_remove(s_info.command_list, command);
+                       destroy_command(command);
                }
        }
 
@@ -310,20 +247,12 @@ static int slave_del_cb(struct slave_node *slave, void *data)
        if (!rpc)
                return 0;
 
-       if (rpc->proxy) {
-               g_object_unref(rpc->proxy);
-
-               if (rpc->pong_timer)
-                       ecore_timer_del(rpc->pong_timer);
-               else
-                       ErrPrint("Pong timer is not exists\n");
-       } else {
-               struct packet *packet;
-               EINA_LIST_FREE(rpc->pending_request_list, packet) {
-                       destroy_packet(packet);
-               }
-       }
+       if (rpc->pong_timer)
+               ecore_timer_del(rpc->pong_timer);
+       else
+               ErrPrint("Pong timer is not exists\n");
 
+       s_info.rpc_list = eina_list_remove(s_info.rpc_list, rpc);
        free(rpc);
        return 0;
 }
@@ -351,107 +280,63 @@ static Eina_Bool ping_timeout_cb(void *data)
        return ECORE_CALLBACK_CANCEL;
 }
 
-int slave_rpc_async_request(struct slave_node *slave,
-                       const char *pkgname, const char *filename,
-                       const char *cmd, GVariant *param, void (*ret_cb)(struct slave_node *slave, const char *func, GVariant *result, void *data),
-                       void *data)
+static inline int slave_rpc_is_valid(struct slave_rpc *rpc)
 {
-       struct packet *packet;
-       struct slave_rpc *rpc;
-
-       rpc = slave_data(slave, "rpc");
-       if (!rpc) {
-               ErrPrint("RPC info is not valid\n");
-               if (ret_cb)
-                       ret_cb(slave, cmd, NULL, data);
+       return rpc && rpc->handle > 0;
+}
 
-               g_variant_unref(param);
-               return -EINVAL;
-       }
+int slave_rpc_async_request(struct slave_node *slave, const char *pkgname, struct packet *packet, void (*ret_cb)(struct slave_node *slave, const struct packet *packet, void *data), void *data)
+{
+       struct command *command;
+       struct slave_rpc *rpc;
 
-       packet = create_packet(slave, pkgname, filename, cmd, param);
-       if (!packet) {
+       command = create_command(slave, pkgname, packet);
+       if (!command) {
                if (ret_cb)
-                       ret_cb(slave, cmd, NULL, data);
+                       ret_cb(slave, NULL, data);
 
-               g_variant_unref(param);
+               packet_unref(packet);
                return -ENOMEM;
        }
 
-       packet->ret_cb = ret_cb;
-       packet->cbdata = data;
+       command->ret_cb = ret_cb;
+       command->cbdata = data;
 
-       if (!rpc->proxy)
-               rpc->pending_request_list = eina_list_append(rpc->pending_request_list, packet);
-       else
-               push_packet(packet);
+       rpc = slave_data(slave, "rpc");
+       if (!slave_rpc_is_valid(rpc)) {
+               DbgPrint("RPC info is not ready to use, push this to pending list\n");
+               rpc->pending_list = eina_list_append(rpc->pending_list, command);
+               return 0;
+       }
 
+       push_command(command);
        return 0;
 }
 
-int slave_rpc_sync_request(struct slave_node *slave,
-                       const char *pkgname, const char *filename,
-                       const char *cmd, GVariant *param)
+int slave_rpc_update_handle(struct slave_node *slave, int handle)
 {
-       GVariant *result;
-       GError *err = NULL;
        struct slave_rpc *rpc;
-
-       if (!slave_is_activated(slave)) {
-               g_variant_unref(param);
-               return -EINVAL;
-       }
+       struct command *command;
 
        rpc = slave_data(slave, "rpc");
-       if (!rpc) {
-               ErrPrint("Slave has no rpc info\n");
-               g_variant_unref(param);
+       if (!rpc)
                return -EINVAL;
-       }
-
-       if (!rpc->proxy) {
-               ErrPrint("Slave is not ready to talk with master\n");
-               g_variant_unref(param);
-               return -EFAULT;
-       }
 
-       result = g_dbus_proxy_call_sync(rpc->proxy, cmd, param,
-                               G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &err);
-       if (!result) {
-               cmd = cmd ? cmd : "";
+       rpc->handle = handle;
+       if (rpc->pong_timer)
+               ecore_timer_del(rpc->pong_timer);
 
-               if (err) {
-                       ErrPrint("Package[%s], cmd[%s]: %s\n", pkgname, cmd, err->message);
-                       g_error_free(err);
-               }
+       rpc->pong_timer = ecore_timer_add(g_conf.ping_time, ping_timeout_cb, slave);
+       if (!rpc->pong_timer)
+               ErrPrint("Failed to add ping timer\n");
 
-               if (!fault_is_occured() && pkgname) {
-                       /*!
-                        * \note
-                        * Recording the fault information.
-                        * slave cannot detect its crash if a livebox
-                        * uses callback, not only update_content but also other functions.
-                        * To fix that case, mark the fault again from here.
-                        */
-                       filename = filename ? filename : "";
-                       fault_func_call(slave, pkgname, filename, cmd);
-               }
+       slave_activated(slave);
+       slave_reset_fault(slave);
 
-               /*!
-                * \note
-                *
-                * Something is goging wrong.
-                * Try to deactivate this.
-                * And it will raise up the dead signal.
-                * then the dead signal callback will check the fault package.
-                * So we don't need to check the fault package from here.
-                */
-               slave_faulted(slave);
-               ErrPrint("Failed to send sync request: %s\n", cmd);
-               return -EIO;
+       EINA_LIST_FREE(rpc->pending_list, command) {
+               push_command(command);
        }
 
-       g_variant_unref(result);
        return 0;
 }
 
@@ -465,8 +350,6 @@ int slave_rpc_initialize(struct slave_node *slave)
                return -ENOMEM;
        }
 
-       rpc->proxy = NULL;
-
        if (slave_set_data(slave, "rpc", rpc) < 0) {
                free(rpc);
                return -ENOMEM;
@@ -474,6 +357,13 @@ int slave_rpc_initialize(struct slave_node *slave)
 
        slave_event_callback_add(slave, SLAVE_EVENT_DELETE, slave_del_cb, NULL);
        slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_deactivate_cb, NULL);
+
+       rpc->ping_count = 0;
+       rpc->next_ping_count = 1;
+       rpc->handle = -1;
+       rpc->slave = slave;
+
+       s_info.rpc_list = eina_list_append(s_info.rpc_list, rpc);
        return 0;
 }
 
@@ -503,63 +393,11 @@ int slave_rpc_ping(struct slave_node *slave)
        return 0;
 }
 
-int slave_rpc_reset_proxy(struct slave_node *slave)
-{
-       struct slave_rpc *rpc;
-
-       rpc = slave_data(slave, "rpc");
-       if (!rpc) {
-               ErrPrint("Failed to get RPC info\n");
-               return -EINVAL;
-       }
-
-       rpc->proxy = NULL;
-       return 0;
-}
-
-int slave_rpc_update_proxy(struct slave_node *slave, GDBusProxy *proxy)
-{
-       struct slave_rpc *rpc;
-       struct packet *packet;
-
-       rpc = slave_data(slave, "rpc");
-       if (!rpc) {
-               ErrPrint("Failed to get RPC info\n");
-               return -EINVAL;
-       }
-
-       if (rpc->proxy)
-               ErrPrint("proxy %p is already exists (%s %d) (replaced with %p)\n", rpc->proxy, slave_name(slave), slave_pid(slave), proxy);
-       else
-               ErrPrint("proxy %p is updated (%s %d)\n", proxy, slave_name(slave), slave_pid(slave));
-
-       rpc->proxy = proxy;
-
-       EINA_LIST_FREE(rpc->pending_request_list, packet) {
-               push_packet(packet);
-       }
-
-       rpc->ping_count = 0;
-       rpc->next_ping_count = 1;
-
-       if (rpc->pong_timer)
-               ecore_timer_del(rpc->pong_timer);
-
-       rpc->pong_timer = ecore_timer_add(g_conf.ping_time, ping_timeout_cb, slave);
-       if (!rpc->pong_timer)
-               ErrPrint("Failed to add ping timer\n");
-
-       slave_activated(slave);
-
-       slave_reset_fault(slave);
-       return 0;
-}
-
 void slave_rpc_request_update(const char *pkgname, const char *cluster, const char *category)
 {
        struct slave_node *slave;
        struct pkg_info *info;
-       GVariant *param;
+       struct packet *packet;
 
        info = package_find(pkgname);
        if (!info) {
@@ -573,13 +411,26 @@ void slave_rpc_request_update(const char *pkgname, const char *cluster, const ch
                return;
        }
 
-       param = g_variant_new("(sss)", pkgname, cluster, category);
-       if (!param) {
+       packet = packet_create("update_content", "sss", pkgname, cluster, category);
+       if (!packet) {
                ErrPrint("Failed to create a new param\n");
                return;
        }
 
-       (void)slave_rpc_async_request(slave, pkgname, NULL, "update_content", param, NULL, NULL);
+       (void)slave_rpc_async_request(slave, pkgname, packet, NULL, NULL);
+}
+
+struct slave_node *slave_rpc_find_by_handle(int handle)
+{
+       Eina_List *l;
+       struct slave_rpc *rpc;
+
+       EINA_LIST_FOREACH(s_info.rpc_list, l, rpc) {
+               if (rpc->handle == handle)
+                       return rpc->slave;
+       }
+
+       return NULL;
 }
 
 /* End of a file */
index b78f030..6670cd8 100644 (file)
@@ -2,7 +2,6 @@
 #include <sys/time.h>
 #include <string.h>
 #include <errno.h>
-#include <libgen.h>
 #include <unistd.h>
 #include <stdlib.h>
 
@@ -116,4 +115,16 @@ char *util_slavename(void)
        return strdup(slavename);
 }
 
+const char *util_basename(const char *name)
+{
+       int length;
+       length = name ? strlen(name) : 0;
+       if (!length)
+               return ".";
+
+       while (--length > 0 && name[length] != '/');
+
+       return length <= 0 ? name : name + length;
+}
+
 /* End of a file */
index 90f25c4..9834cee 100644 (file)
@@ -20,7 +20,6 @@
  */
 
 #include <stdio.h>
-#include <libgen.h>
 #include <fcntl.h>
 #include <unistd.h>
 
@@ -33,6 +32,7 @@
 #include "virtual_canvas.h"
 #include "debug.h"
 #include "conf.h"
+#include "util.h"
 
 Evas *virtual_canvas_create(int w, int h)
 {
index cf865d5..1058d43 100644 (file)
@@ -24,7 +24,6 @@
 #include <sys/shm.h>
 #include <assert.h>
 #include <errno.h>
-#include <libgen.h>
 
 #include <Evas.h>
 #include <Ecore_X.h>