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
ADD_EXECUTABLE(${PROJECT_NAME}
src/main.c
- src/dbus.c
src/util.c
src/fault_manager.c
src/parser.c
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)
#!/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
}
+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
-/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
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
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
*/
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);
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
/*!
*/
-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 */
--- /dev/null
+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 */
--- /dev/null
+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 */
#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 */
--- /dev/null
+#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 */
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);
* \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
* \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
*/
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);
--- /dev/null
+
+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 */
--- /dev/null
+/*
+ * 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 */
--- /dev/null
+extern int server_init(void);
+extern int server_fini(void);
+
+/* End of a file */
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
/*!
* 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);
/*!
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
-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);
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 */
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
# 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
%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
#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;
}
client->pid = pid;
+ client->refcnt = 1;
s_info.client_list = eina_list_append(s_info.client_list, client);
return client;
return NULL;
}
- client_ref(client);
- client_rpc_initialize(client);
-
invoke_global_create_cb(client);
return 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;
}
return NULL;
}
-int const client_count_paused(void)
+const int const client_count_paused(void)
{
return s_info.nr_of_paused_clients;
}
client->faulted = 1;
client->pid = (pid_t)-1;
- client_rpc_reset_proxy(client);
invoke_deactivated_cb(client);
client_destroy(client);
client->faulted = 1;
client->pid = (pid_t)-1;
- client_rpc_reset_proxy(client);
invoke_deactivated_cb(client);
client_destroy(client);
return 0;
}
-int client_is_faulted(struct client_node *client)
+const int const client_is_faulted(const struct client_node *client)
{
/*!
* \note
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;
}
#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) {
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;
}
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) {
}
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;
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;
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;
--- /dev/null
+#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 */
--- /dev/null
+#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 */
#include <stdio.h>
#include <stdbool.h>
-#include <libgen.h>
#include <unistd.h>
#include <Ecore.h>
#include <context_subscribe.h>
#include "debug.h"
+#include "packet.h"
#include "slave_life.h"
#include "slave_rpc.h"
#include "client_life.h"
#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)
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;
}
--- /dev/null
+#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 */
#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"
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);
}
#include <stdio.h>
-#include <libgen.h> /* basename */
#include <unistd.h> /* access */
#include <sys/mman.h>
#include <errno.h>
#include <stdio.h>
-#include <libgen.h>
#include <ctype.h>
#include <stdlib.h> /* malloc */
#include <errno.h>
#include <dlog.h>
#include <Eina.h>
+#include "util.h"
#include "debug.h"
#include "group.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
-#include <libgen.h>
#include <dlog.h>
#include <Ecore_Evas.h>
#include "conf.h"
#include "util.h"
#include "debug.h"
+#include "packet.h"
#include "slave_life.h"
#include "slave_rpc.h"
#include "client_life.h"
#include "instance.h"
#include "fb.h"
#include "script_handler.h"
+#include "connector_packet.h"
int errno;
int width;
int height;
struct script_info *handle;
+ int is_opened_for_reactivate;
} pd;
int timeout;
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,
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;
}
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,
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);
return inst;
}
-struct inst_info * instance_unref(struct inst_info *inst)
+struct inst_info *instance_unref(struct inst_info *inst)
{
if (!inst)
return NULL;
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.
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) {
/*!
* 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);
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.
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) {
/*!
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);
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;
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
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) {
/*!
}
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);
int instance_destroy(struct inst_info *inst)
{
- GVariant *param;
+ struct packet *packet;
if (!inst) {
ErrPrint("Invalid instance handle\n");
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)
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;
int instance_deactivate(struct inst_info *inst)
{
- GVariant *param;
+ struct packet *packet;
if (!inst) {
ErrPrint("Invalid instance handle\n");
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");
break;
}
- param = g_variant_new("(sssiidssiiis)",
+ packet = packet_create("renew", "sssiidssiiis",
package_name(inst->info),
inst->id,
inst->content,
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;
}
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");
break;
}
- param = g_variant_new("(sssiidssiis)",
+ packet = packet_create("new", "sssiidssiis",
package_name(inst->info),
inst->id,
inst->content,
inst->lb.is_pinned_up,
!!inst->client,
package_abi(inst->info));
- if (!param) {
+ if (!packet) {
ErrPrint("Failed to create a param\n");
return -EFAULT;
}
* 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)
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)
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;
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;
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;
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) {
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;
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))
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);
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);
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))
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);
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);
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);
break;
case INST_DESTROYED:
default:
- DbgPrint("Package is already destroyed: %s\n",
- package_name(instance_package(inst)));
break;
}
}
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);
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;
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;
}
}
+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 */
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>
-#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
-#include <libgen.h>
+#include <unistd.h>
#include <Ecore.h>
#include <Ecore_X.h>
#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);
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)
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
* 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;
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();
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;
return ret;
}
+*/
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();
#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"
}
} 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,
*
* activate slave when the slave is reactivated
*/
- cnt++;
}
}
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
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;
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;
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;
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;
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;
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;
}
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;
}
return NULL;
}
-const char * const package_name(struct pkg_info *info)
+const char * const package_name(const struct pkg_info *info)
{
return info->pkgname;
}
--- /dev/null
+#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 */
#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"
#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"
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);
const char *pkgname;
const char *filename;
struct slave_node *slave;
- GVariant *param;
+ struct packet *packet;
int ret;
ee = ecore_evas_ecore_evas_get(e);
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;
}
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) {
}
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) {
return -EIO;
}
- DbgPrint("descfile: %s\n", basename((char *)descfile));
+ DbgPrint("descfile: %s\n", util_basename(descfile));
state = UNKNOWN;
field_idx = 0;
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') {
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') {
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') {
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') {
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') {
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') {
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);
--- /dev/null
+#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 */
--- /dev/null
+#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", ×tamp);
+ 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, ×tamp, &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", ×tamp, &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, ×tamp, &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, ×tamp, &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, ×tamp, &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, ×tamp, &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, ×tamp, &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, ×tamp, &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 */
#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"
#include <errno.h> /* errno */
#include <unistd.h> /* pid_t */
#include <stdlib.h> /* free */
-#include <libgen.h> /* basename */
#include <pthread.h>
#include <Eina.h>
#include <gio/gio.h> /* GDBusProxy */
+#include "packet.h"
#include "slave_life.h"
#include "slave_rpc.h"
#include "client_life.h"
return slave;
}
-int const slave_refcnt(struct slave_node *slave)
+const int const slave_refcnt(struct slave_node *slave)
{
return slave->refcnt;
}
slave = create_slave_node(name, is_secured);
slave_ref(slave);
- slave_rpc_initialize(slave);
return slave;
}
}
}
-int const slave_is_faulted(struct slave_node *slave)
+const int const slave_is_faulted(const struct slave_node *slave)
{
return slave->faulted;
}
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;
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);
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;
}
}
}
-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;
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 */
#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) {
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);
}
}
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;
}
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;
}
return -ENOMEM;
}
- rpc->proxy = NULL;
-
if (slave_set_data(slave, "rpc", rpc) < 0) {
free(rpc);
return -ENOMEM;
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;
}
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) {
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 */
#include <sys/time.h>
#include <string.h>
#include <errno.h>
-#include <libgen.h>
#include <unistd.h>
#include <stdlib.h>
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 */
*/
#include <stdio.h>
-#include <libgen.h>
#include <fcntl.h>
#include <unistd.h>
#include "virtual_canvas.h"
#include "debug.h"
#include "conf.h"
+#include "util.h"
Evas *virtual_canvas_create(int w, int h)
{
#include <sys/shm.h>
#include <assert.h>
#include <errno.h>
-#include <libgen.h>
#include <Evas.h>
#include <Ecore_X.h>