Implement the service thread & Update license
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 19 Apr 2013 11:38:33 +0000 (20:38 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 19 Apr 2013 11:38:33 +0000 (20:38 +0900)
Implement the badge & shortcut & notification service threads.

Change-Id: Idb9393bfd39861da6cd6679e6b370ad6e18d0b55

69 files changed:
CMakeLists.txt
data/data-provider-master
data/data-provider-master.service
include/abi.h
include/badge_service.h [new file with mode: 0644]
include/buffer_handler.h
include/client_life.h
include/client_rpc.h
include/conf.h
include/critical_log.h
include/dead_monitor.h
include/debug.h
include/event.h
include/fault_manager.h
include/fb.h
include/group.h
include/instance.h
include/io.h
include/liveinfo.h
include/main.h
include/notification_service.h [new file with mode: 0644]
include/package.h
include/parser.h
include/pkgmgr.h
include/rpc_to_slave.h
include/script_handler.h
include/server.h
include/service_common.h [new file with mode: 0644]
include/setting.h
include/shortcut_service.h [new file with mode: 0644]
include/slave_life.h
include/slave_rpc.h
include/util.h
include/xmonitor.h
pkgmgr_livebox/include/dlist.h
pkgmgr_livebox/src/dlist.c
pkgmgr_livebox/src/service_register.c
res/edje/master.edc
src/abi.c
src/badge_service.c [new file with mode: 0644]
src/buffer_handler.c
src/client_life.c
src/client_rpc.c
src/conf.c
src/critical_log.c
src/dead_monitor.c
src/event.c
src/fault_manager.c
src/fb.c
src/group.c
src/instance.c
src/io.c
src/liveinfo.c
src/main.c
src/notification_service.c [new file with mode: 0644]
src/package.c
src/parser.c
src/pkgmgr.c
src/script_handler.c
src/server.c
src/service_common.c [new file with mode: 0644]
src/setting.c
src/shortcut_service.c [new file with mode: 0644]
src/slave_life.c
src/slave_rpc.c
src/util.c
src/xmonitor.c
util_liveinfo/include/liveinfo.h
util_liveinfo/src/liveinfo.c

index 507375c..660cb1b 100644 (file)
@@ -77,6 +77,10 @@ ADD_EXECUTABLE(${PROJECT_NAME}
        src/liveinfo.c
        src/pkgmgr.c
        src/event.c
+       src/shortcut_service.c
+       src/badge_service.c
+       src/notification_service.c
+       src/service_common.c
 )
 
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkg_LDFLAGS} "-ldl")
index f2125bb..a68b7d5 100755 (executable)
@@ -6,7 +6,7 @@
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-# http://floralicense.org
+# http://floralicense.org/license/
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
index 6333352..f412797 100644 (file)
@@ -5,7 +5,7 @@
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-# http://floralicense.org
+# http://floralicense.org/license/
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
index 974999d..d1900b3 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/include/badge_service.h b/include/badge_service.h
new file mode 100644 (file)
index 0000000..94fb941
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
index 8a5aea0..21d6707 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 8b76f1a..4871974 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 2cf0242..ccfa129 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index cd410ab..87d1070 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index cd0f769..757ae63 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 1526f89..118c5ac 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 317129f..5058acc 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index fe0d219..4cf46e4 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index e2bb96c..d61e225 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index baf5b4c..066f97a 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 08de02b..161e0a4 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 83f5c88..535defa 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index a857422..6624db5 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 2dd1afd..e86e4a2 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 92efdbb..94fb941 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/include/notification_service.h b/include/notification_service.h
new file mode 100644 (file)
index 0000000..94fb941
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
index 3278c32..9735fa2 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 82c96ef..db828b9 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 2cb4008..e942697 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 725a679..cfc87b9 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 02c6a4f..c676836 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index ac93e32..570eb87 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/include/service_common.h b/include/service_common.h
new file mode 100644 (file)
index 0000000..6b0e4dd
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+enum tcb_type {
+       TCB_CLIENT_TYPE_UNDEFINED = 0x00,
+       TCB_CLIENT_TYPE_APP     = 0x01,
+       TCB_CLIENT_TYPE_SERVICE = 0x02,
+       TCB_CLIENT_TYPE_UNKNOWN = 0xff,
+};
+
+struct tcb;
+struct service_context;
+
+extern int tcb_fd(struct tcb *tcb);
+extern struct service_context *tcb_svc_ctx(struct tcb *tcb);
+extern int tcb_client_type(struct tcb *tcb);
+extern int tcb_client_type_set(struct tcb *tcb, enum tcb_type type);
+
+extern struct service_context *service_common_create(const char *addr, int (*service_thread_main)(struct tcb *tcb, struct packet *packet, void *data), void *data);
+extern int service_common_destroy(struct service_context *svc_ctx);
+
+extern int service_common_multicast_packet(struct tcb *tcb, struct packet *packet, int type);
+extern int service_common_unicast_packet(struct tcb *tcb, struct packet *packet);
+
+/* End of a file */
index 5ec158e..1e4989e 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/include/shortcut_service.h b/include/shortcut_service.h
new file mode 100644 (file)
index 0000000..a7a146d
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* End of a file */
index 256bf59..821b1eb 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index bef921d..cfcbabb 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 11ffe9c..a474c06 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 8024276..55aadeb 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 5cddb58..99e8443 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 7a890c5..cf2cb63 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 9965d8a..6c8536e 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index d50e4da..e64548a 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index b0145cf..d821183 100644 (file)
--- a/src/abi.c
+++ b/src/abi.c
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/badge_service.c b/src/badge_service.c
new file mode 100644 (file)
index 0000000..94fb941
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
index 4ffaba7..1721e86 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index bc75d79..af8302d 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index edf4327..d87659f 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index c880bae..acfdb05 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 9136bf0..38ad835 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 2576baf..91e3a23 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 1bc98b7..818e66f 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 0c44712..837bd17 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 220e8bd..7d21283 100644 (file)
--- a/src/fb.c
+++ b/src/fb.c
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index c18a279..0adae6a 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index a4df9dc..db4ab42 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -690,12 +690,17 @@ static inline int fork_package(struct inst_info *inst, const char *pkgname)
        inst->info = info;
 
        if (package_secured(info)) {
-               DbgPrint("Register the update timer for secured livebox [%s]\n", package_name(info));
-               inst->update_timer = util_timer_add(inst->lb.period, update_timer_cb, inst);
-               if (!inst->update_timer)
-                       ErrPrint("Failed to add an update timer for instance %s\n", inst->id);
-               else
-                       timer_freeze(inst); /* Freeze the update timer as default */
+               if (inst->lb.period > 0.0f) {
+                       DbgPrint("Register the update timer for secured livebox [%s]\n", package_name(info));
+                       inst->update_timer = util_timer_add(inst->lb.period, update_timer_cb, inst);
+                       if (!inst->update_timer)
+                               ErrPrint("Failed to add an update timer for instance %s\n", inst->id);
+                       else
+                               timer_freeze(inst); /* Freeze the update timer as default */
+               } else {
+                       DbgPrint("secured livebox [%s] has no period (%lf)\n", package_name(info), inst->lb.period);
+                       inst->update_timer = NULL;
+               }
        }
 
        return LB_STATUS_SUCCESS;
index 3bb9f10..8003f30 100644 (file)
--- a/src/io.c
+++ b/src/io.c
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 08257e4..d280fa3 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 9b7ac7b..3421123 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/notification_service.c b/src/notification_service.c
new file mode 100644 (file)
index 0000000..94fb941
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
index 68b2d68..35e4742 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 7efee09..3a4f4c7 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 4b11fd3..2f65c13 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index ea709ed..0b0e789 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 259e08d..27d4bbd 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/service_common.c b/src/service_common.c
new file mode 100644 (file)
index 0000000..15b5cb2
--- /dev/null
@@ -0,0 +1,720 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <pthread.h>
+#include <secure_socket.h>
+#include <packet.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <dlog.h>
+#include <Eina.h>
+
+#include "service_common.h"
+#include "util.h"
+#include "debug.h"
+#include "conf.h"
+
+#define EVT_CH 'e'
+#define EVT_END_CH     'x'
+
+#define CRITICAL_SECTION_BEGIN(handle) \
+do { \
+       int ret; \
+       ret = pthread_mutex_lock(handle); \
+       if (ret != 0) \
+               ErrPrint("Failed to lock: %s\n", strerror(ret)); \
+} while (0)
+
+#define CRITICAL_SECTION_END(handle) \
+do { \
+       int ret; \
+       ret = pthread_mutex_unlock(handle); \
+       if (ret != 0) \
+               ErrPrint("Failed to unlock: %s\n", strerror(ret)); \
+} while (0)
+
+
+int errno;
+
+/*!
+ * \note
+ * Server information and global (only in this file-scope) variables are defined
+ */
+#define EVT_READ 0
+#define EVT_WRITE 1
+#define EVT_MAX 2
+
+struct service_context {
+       pthread_t thid; /*!< Server thread Id */
+       int fd; /*!< Server socket handle */
+
+       pthread_t service_thid;
+
+       Eina_List *tcb_list; /*!< TCB list, list of every thread for client connections */
+       pthread_mutex_t tcb_list_lock; /*!< tcb_list has to be handled safely */
+
+       Eina_List *packet_list;
+       pthread_mutex_t packet_list_lock;
+       int evt_pipe[EVT_MAX];
+
+       int (*service_thread_main)(struct tcb *tcb, struct packet *packet, void *data);
+       void *service_thread_data;
+};
+
+struct packet_info {
+       struct tcb *tcb;
+       struct packet *packet;
+};
+
+/*!
+ * \note
+ * Thread Control Block
+ * - The main server will create a thread for every client connections.
+ *   When a new client is comming to us, this TCB block will be allocated and initialized.
+ */
+struct tcb { /* Thread controll block */
+       struct service_context *svc_ctx;
+       pthread_t thid; /*!< Thread Id */
+       int fd; /*!< Connection handle */
+       enum tcb_type type;
+};
+
+/*!
+ * \note
+ * Called from Client Thread
+ */
+static inline int tcb_destroy(struct service_context *svc_ctx, struct tcb *tcb)
+{
+       void *ret;
+       int status;
+
+       CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock);
+       svc_ctx->tcb_list = eina_list_remove(svc_ctx->tcb_list, tcb);
+       CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock);
+
+       /*!
+        * ASSERT(tcb->fd >= 0);
+        */
+       secure_socket_destroy_handle(tcb->fd);
+
+       status = pthread_join(tcb->thid, &ret);
+       if (status != 0)
+               ErrPrint("Unable to join a thread: %s\n", strerror(status));
+       /*!
+        * \NOTE
+        * Waiting termination client thread
+        */
+       free(tcb);
+
+       return 0;
+}
+
+/*!
+ * Do service for clients
+ * Routing packets to destination processes.
+ */
+static void *client_packet_pump_main(void *data)
+{
+       struct tcb *tcb = data;
+       struct service_context *svc_ctx = tcb->svc_ctx;
+       struct packet *packet;
+       fd_set set;
+       char *ptr;
+       int size;
+       int packet_offset;
+       int recv_offset;
+       int pid;
+       int ret;
+       char evt_ch = EVT_CH;
+       enum {
+               RECV_INIT,
+               RECV_HEADER,
+               RECV_PAYLOAD,
+               RECV_DONE,
+       } recv_state;
+       struct packet_info *packet_info;
+
+       ret = 0;
+       recv_state = RECV_INIT;
+       /*!
+        * \note
+        * To escape from the switch statement, we use this ret value
+        */
+       while (ret == 0) {
+               FD_ZERO(&set);
+               FD_SET(tcb->fd, &set);
+               ret = select(tcb->fd + 1, &set, NULL, NULL, NULL);
+               if (ret < 0) {
+                       ret = -errno;
+                       if (errno == EINTR) {
+                               DbgPrint("INTERRUPTED\n");
+                               ret = 0;
+                               continue;
+                       }
+                       ErrPrint("Error: %s\n",strerror(errno));
+                       break;
+               } else if (ret == 0) {
+                       ErrPrint("Timeout\n");
+                       ret = -ETIMEDOUT;
+                       break;
+               }
+
+               if (FD_ISSET(tcb->fd, &set)) {
+                       ErrPrint("Unexpected handler is toggled\n");
+                       ret = -EINVAL;
+                       break;
+               }
+               
+               /*!
+                * \TODO
+                * Service!!! Receive packet & route packet
+                */
+               switch (recv_state) {
+               case RECV_INIT:
+                       size = packet_header_size();
+                       packet_offset = 0;
+                       recv_offset = 0;
+                       packet = NULL;
+                       ptr = malloc(size);
+                       if (!ptr) {
+                               ErrPrint("Heap: %s\n", strerror(errno));
+                               ret = -ENOMEM;
+                               break;
+                       }
+                       recv_state = RECV_HEADER;
+                       /* Go through, don't break from here */
+               case RECV_HEADER:
+                       ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &pid);
+                       if (ret <= 0) {
+                               if (ret == 0)
+                                       ret = -ECANCELED;
+                               free(ptr);
+                               break;
+                       }
+
+                       recv_offset += ret;
+                       ret = 0;
+
+                       if (recv_offset == size) {
+                               packet = packet_build(packet, packet_offset, ptr, size);
+                               free(ptr);
+                               if (!packet) {
+                                       ret = -EFAULT;
+                                       break;
+                               }
+
+                               packet_offset += recv_offset;
+
+                               recv_state = RECV_PAYLOAD;
+                               recv_offset = 0;
+                               size = packet_payload_size(packet);
+
+                               ptr = malloc(size);
+                               if (!ptr) {
+                                       ErrPrint("Heap: %s\n", strerror(errno));
+                                       ret = -ENOMEM;
+                               }
+                       }
+                       break;
+               case RECV_PAYLOAD:
+                       ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &pid);
+                       if (ret <= 0) {
+                               if (ret == 0)
+                                       ret = -ECANCELED;
+                               free(ptr);
+                               break;
+                       }
+
+                       recv_offset += ret;
+                       ret = 0;
+
+                       if (recv_offset == size) {
+                               packet = packet_build(packet, packet_offset, ptr, size);
+                               free(ptr);
+                               if (!packet) {
+                                       ret = -EFAULT;
+                                       break;
+                               }
+
+                               packet_offset += recv_offset;
+
+                               recv_state = RECV_DONE;
+                               recv_offset = 0;
+                       }
+                       break;
+               case RECV_DONE:
+                       /*!
+                        * Push this packet to the packet list with TCB
+                        * Then the service main function will get this.
+                        */
+                       packet_info = malloc(sizeof(*packet_info));
+                       if (!packet_info) {
+                               ret = -errno;
+                               ErrPrint("Heap: %s\n", strerror(errno));
+                               packet_destroy(packet);
+                               break;
+                       }
+
+                       packet_info->packet = packet;
+                       packet_info->tcb = tcb;
+
+                       CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock);
+                       svc_ctx->packet_list = eina_list_append(svc_ctx->packet_list, packet_info);
+                       CRITICAL_SECTION_END(&svc_ctx->packet_list_lock);
+
+                       if (write(svc_ctx->evt_pipe[EVT_WRITE], &evt_ch, sizeof(evt_ch)) != sizeof(evt_ch)) {
+                               ret = -errno;
+                               ErrPrint("Unable to write a pipe\n");
+                               CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock);
+                               svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info);
+                               CRITICAL_SECTION_END(&svc_ctx->packet_list_lock);
+
+                               packet_destroy(packet);
+                               free(packet_info);
+                               break;
+                       }
+                       DbgPrint("Packet received: %d bytes\n", packet_offset);
+
+                       recv_state = RECV_INIT;
+                       break;
+               default:
+                       /* Dead code */
+                       break;
+               }
+       }
+
+       tcb_destroy(svc_ctx, tcb);
+       return (void *)ret;
+}
+
+/*!
+ * \note
+ * Called from Server Main Thread
+ */
+static inline struct tcb *tcb_create(struct service_context *svc_ctx, int fd)
+{
+       struct tcb *tcb;
+       int status;
+
+       tcb = malloc(sizeof(*tcb));
+       if (!tcb) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       tcb->fd = fd;
+       tcb->svc_ctx = svc_ctx;
+
+       status = pthread_create(&tcb->thid, NULL, client_packet_pump_main, tcb);
+       if (status != 0) {
+               ErrPrint("Unable to create a new thread: %s\n", strerror(status));
+               free(tcb);
+               return NULL;
+       }
+
+       CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock);
+       svc_ctx->tcb_list = eina_list_append(svc_ctx->tcb_list, tcb);
+       CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock);
+
+       return tcb;
+}
+
+/*!
+ * \note
+ * Called from Main Thread
+ */
+static inline void tcb_teminate_all(struct service_context *svc_ctx)
+{
+       struct tcb *tcb;
+       void *ret;
+       int status;
+
+       /*!
+        * We don't need to make critical section on here.
+        * If we call this after terminate the server thread first.
+        * Then there is no other thread to access tcb_list.
+        */
+       CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock);
+       EINA_LIST_FREE(svc_ctx->tcb_list, tcb) {
+               /*!
+                * ASSERT(tcb->fd >= 0);
+                */
+               secure_socket_destroy_handle(tcb->fd);
+
+               status = pthread_join(tcb->thid, &ret);
+               if (status != 0)
+                       ErrPrint("Unable to join a thread: %s\n", strerror(status));
+
+               free(tcb);
+       }
+       CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock);
+}
+
+/*!
+ * \NOTE
+ * Packet consuming thread. service thread.
+ */
+static void *service_main(void *data)
+{
+       struct service_context *svc_ctx = data;
+       fd_set set;
+       int ret;
+       char evt_ch;
+       struct packet_info *packet_info;
+
+       while (1) {
+               FD_ZERO(&set);
+               FD_SET(svc_ctx->evt_pipe[EVT_READ], &set);
+               ret = select(svc_ctx->evt_pipe[EVT_READ] + 1, &set, NULL, NULL, NULL);
+               if (ret < 0) {
+                       ret = -errno;
+                       if (errno == EINTR) {
+                               DbgPrint("INTERRUPTED\n");
+                               continue;
+                       }
+                       ErrPrint("Error: %s\n",strerror(errno));
+                       break;
+               } else if (ret == 0) {
+                       ErrPrint("Timeout\n");
+                       ret = -ETIMEDOUT;
+                       break;
+               }
+
+               if (FD_ISSET(svc_ctx->evt_pipe[EVT_READ], &set)) {
+                       ErrPrint("Unexpected handler is toggled\n");
+                       ret = -EINVAL;
+                       break;
+               }
+
+               if (read(svc_ctx->evt_pipe[EVT_READ], &evt_ch, sizeof(evt_ch)) != sizeof(evt_ch)) {
+                       ErrPrint("Unable to read pipe: %s\n", strerror(errno));
+                       ret = -EIO;
+                       break;
+               }
+
+               if (evt_ch == EVT_END_CH) {
+                       ErrPrint("Thread is terminated\n");
+                       ret = 0;
+                       break;
+               }
+
+               CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock);
+               packet_info = eina_list_nth(svc_ctx->packet_list, 0);
+               svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info);
+               CRITICAL_SECTION_END(&svc_ctx->packet_list_lock);
+
+               ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data);
+               if (ret < 0)
+                       ErrPrint("Service thread returns: %d\n", ret);
+
+               packet_destroy(packet_info->packet);
+               free(packet_info);
+       }
+
+       return (void *)ret;
+}
+
+/*!
+ * Accept new client connections
+ * And create a new thread for service.
+ */
+static void *server_main(void *data)
+{
+       struct service_context *svc_ctx = data;
+       fd_set set;
+       int ret;
+       int client_fd;
+       struct tcb *tcb;
+
+       while (1) {
+               FD_ZERO(&set);
+               FD_SET(svc_ctx->fd, &set);
+               ret = select(svc_ctx->fd + 1, &set, NULL, NULL, NULL);
+               if (ret < 0) {
+                       ret = -errno;
+                       if (errno == EINTR) {
+                               DbgPrint("INTERRUPTED\n");
+                               continue;
+                       }
+                       ErrPrint("Error: %s\n", strerror(errno));
+                       break;
+               } else if (ret == 0) {
+                       ErrPrint("Timeout\n");
+                       ret = -ETIMEDOUT;
+                       break;
+               }
+
+               if (FD_ISSET(svc_ctx->fd, &set)) {
+                       ErrPrint("Unexpected handler is toggled\n");
+                       ret = -EINVAL;
+                       break;
+               }
+
+               client_fd = secure_socket_get_connection_handle(svc_ctx->fd);
+               DbgPrint("New client connection arrived (%d)\n", client_fd);
+               if (client_fd < 0) {
+                       ErrPrint("Failed to establish the client connection\n");
+                       ret = -EFAULT;
+                       break;
+               }
+
+               tcb = tcb_create(svc_ctx, client_fd);
+               if (!tcb)
+                       secure_socket_destroy_handle(client_fd);
+       }
+
+       return (void *)ret;
+}
+
+HAPI struct service_context *service_common_create(const char *addr, int (*service_thread_main)(struct tcb *tcb, struct packet *packet, void *data), void *data)
+{
+       int status;
+       struct service_context *svc_ctx;
+
+       if (!service_thread_main || !addr) {
+               ErrPrint("Invalid argument\n");
+               return NULL;
+       }
+
+       svc_ctx = malloc(sizeof(*svc_ctx));
+       if (!svc_ctx) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       svc_ctx->fd = secure_socket_create_server(addr);
+       if (svc_ctx->fd < 0) {
+               free(svc_ctx);
+               return NULL;
+       }
+
+       svc_ctx->service_thread_main = service_thread_main;
+       svc_ctx->service_thread_data = data;
+
+       if (fcntl(svc_ctx->fd, F_SETFD, FD_CLOEXEC) < 0)
+               ErrPrint("fcntl: %s\n", strerror(errno));
+
+       if (fcntl(svc_ctx->fd, F_SETFL, O_NONBLOCK) < 0)
+               ErrPrint("fcntl: %s\n", strerror(errno));
+
+       if (pipe2(svc_ctx->evt_pipe, O_NONBLOCK | O_CLOEXEC) < 0) {
+               ErrPrint("pipe: %d\n", strerror(errno));
+               secure_socket_destroy_handle(svc_ctx->fd);
+               free(svc_ctx);
+               return NULL;
+       }
+
+       status = pthread_mutex_init(&svc_ctx->packet_list_lock, NULL);
+       if (status != 0) {
+               ErrPrint("Unable to create a mutex: %s\n", strerror(status));
+               status = close(svc_ctx->evt_pipe[EVT_READ]);
+               if (status < 0)
+                       ErrPrint("Error: %s\n", strerror(errno));
+               status = close(svc_ctx->evt_pipe[EVT_WRITE]);
+               if (status < 0)
+                       ErrPrint("Error: %s\n", strerror(errno));
+               secure_socket_destroy_handle(svc_ctx->fd);
+               free(svc_ctx);
+               return NULL;
+       }
+
+       status = pthread_mutex_init(&svc_ctx->tcb_list_lock, NULL);
+       if (status != 0) {
+               ErrPrint("Unable to initiate the mutex: %s\n", strerror(status));
+               status = pthread_mutex_destroy(&svc_ctx->packet_list_lock);
+               if (status != 0)
+                       ErrPrint("Error: %s\n", strerror(status));
+               status = close(svc_ctx->evt_pipe[EVT_READ]);
+               if (status < 0)
+                       ErrPrint("Error: %s\n", strerror(errno));
+               status = close(svc_ctx->evt_pipe[EVT_WRITE]);
+               if (status < 0)
+                       ErrPrint("Error: %s\n", strerror(errno));
+               secure_socket_destroy_handle(svc_ctx->fd);
+               free(svc_ctx);
+               return NULL;
+       }
+
+       status = pthread_create(&svc_ctx->thid, NULL, server_main, svc_ctx);
+       if (status != 0) {
+               ErrPrint("Unable to create a thread for shortcut service: %s\n", strerror(status));
+               status = pthread_mutex_destroy(&svc_ctx->tcb_list_lock);
+               if (status != 0)
+                       ErrPrint("Error: %s\n", strerror(status));
+               status = pthread_mutex_destroy(&svc_ctx->packet_list_lock);
+               if (status != 0)
+                       ErrPrint("Error: %s\n", strerror(status));
+               status = close(svc_ctx->evt_pipe[EVT_READ]);
+               if (status != 0)
+                       ErrPrint("Error: %s\n", strerror(status));
+               status = close(svc_ctx->evt_pipe[EVT_WRITE]);
+               if (status != 0)
+                       ErrPrint("Error: %s\n", strerror(status));
+               secure_socket_destroy_handle(svc_ctx->fd);
+               free(svc_ctx);
+               return NULL;
+       }
+
+       status = pthread_create(&svc_ctx->service_thid, NULL, service_main, svc_ctx);
+       if (status != 0) {
+               void *ret;
+               ErrPrint("Unable to create a thread for shortcut service: %s\n", strerror(status));
+
+               secure_socket_destroy_handle(svc_ctx->fd);
+
+               status = pthread_join(svc_ctx->thid, &ret);
+               if (status != 0)
+                       ErrPrint("Error: %s\n", strerror(status));
+
+               status = pthread_mutex_destroy(&svc_ctx->tcb_list_lock);
+               if (status != 0)
+                       ErrPrint("Error: %s\n", strerror(status));
+               status = pthread_mutex_destroy(&svc_ctx->packet_list_lock);
+               if (status != 0)
+                       ErrPrint("Error: %s\n", strerror(status));
+               status = close(svc_ctx->evt_pipe[EVT_READ]);
+               if (status < 0)
+                       ErrPrint("Error: %s\n", strerror(errno));
+               status = close(svc_ctx->evt_pipe[EVT_WRITE]);
+               if (status < 0)
+                       ErrPrint("Error: %s\n", strerror(errno));
+               secure_socket_destroy_handle(svc_ctx->fd);
+               free(svc_ctx);
+               return NULL;
+       }
+
+       return svc_ctx;
+}
+
+HAPI int service_common_destroy(struct service_context *svc_ctx)
+{
+       int status;
+       void *ret;
+       char evt_ch = EVT_END_CH;
+
+       if (!svc_ctx)
+               return -EINVAL;
+
+       /*!
+        * \note
+        * Terminate server thread
+        */
+       secure_socket_destroy_handle(svc_ctx->fd);
+       status = pthread_join(svc_ctx->thid, &ret);
+       if (status != 0)
+               ErrPrint("Join: %s\n", strerror(status));
+       /*!
+        * \note
+        * Terminate all client threads.
+        */
+       tcb_teminate_all(svc_ctx);
+
+       /* Emit a finish event */
+       if (write(svc_ctx->evt_pipe[EVT_WRITE], &evt_ch, sizeof(evt_ch)) == sizeof(evt_ch))
+               ErrPrint("write: %s\n", strerror(errno));
+
+       /* Waiting */
+       status = pthread_join(svc_ctx->service_thid, &ret);
+       if (status != 0)
+               ErrPrint("Join: %s\n", strerror(status));
+
+       status = pthread_mutex_destroy(&svc_ctx->tcb_list_lock);
+       if (status != 0)
+               ErrPrint("Unable to destroy a mutex: %s\n", strerror(status));
+
+       status = pthread_mutex_destroy(&svc_ctx->packet_list_lock);
+       if (status != 0)
+               ErrPrint("Unable to destroy a mutex: %s\n", strerror(status));
+
+       status = close(svc_ctx->evt_pipe[EVT_WRITE]);
+       status = close(svc_ctx->evt_pipe[EVT_READ]);
+       free(svc_ctx);
+       return 0;
+}
+
+HAPI int tcb_fd(struct tcb *tcb)
+{
+       if (!tcb)
+               return -EINVAL;
+
+       return tcb->fd;
+}
+
+HAPI int tcb_client_type(struct tcb *tcb)
+{
+       if (!tcb)
+               return -EINVAL;
+
+       return tcb->type;
+}
+
+HAPI int tcb_client_type_set(struct tcb *tcb, enum tcb_type type)
+{
+       if (!tcb)
+               return -EINVAL;
+
+       tcb->type = type;
+       return 0;
+}
+
+HAPI struct service_context *tcb_svc_ctx(struct tcb *tcb)
+{
+       if (!tcb)
+               return NULL;
+
+       return tcb->svc_ctx;
+}
+
+HAPI int service_common_unicast_packet(struct tcb *tcb, struct packet *packet)
+{
+       if (!tcb || !packet)
+               return -EINVAL;
+
+       return secure_socket_send(tcb->fd, (void *)packet_data(packet), packet_size(packet));
+}
+
+HAPI int service_common_multicast_packet(struct tcb *tcb, struct packet *packet, int type)
+{
+       Eina_List *l;
+       struct tcb *target;
+       struct service_context *svc_ctx;
+       int ret;
+
+       if (!tcb || !packet)
+               return -EINVAL;
+
+       svc_ctx = tcb->svc_ctx;
+
+       CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock);
+       EINA_LIST_FOREACH(svc_ctx->tcb_list, l, target) {
+               if (target == tcb || target->type != type)
+                       continue;
+
+               ret = secure_socket_send(target->fd, (void *)packet_data(packet), packet_size(packet));
+               if (ret < 0)
+                       ErrPrint("Failed to send packet: %d\n", ret);
+       }
+       CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock);
+
+       return 0;
+}
+
+/* End of a file */
index d0119b1..8eaceca 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/shortcut_service.c b/src/shortcut_service.c
new file mode 100644 (file)
index 0000000..774d814
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+
+#include <Eina.h>
+
+#include <dlog.h>
+#include <livebox-errno.h>
+#include <packet.h>
+
+#include <Eina.h>
+
+#include "service_common.h"
+#include "debug.h"
+#include "util.h"
+
+#define SHORTCUT_ADDR  "/tmp/.shortcut.service"
+
+static struct info {
+       Eina_List *context_list;
+       struct service_context *svc_ctx;
+} s_info = {
+       .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */
+       .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */
+};
+
+struct context {
+       struct tcb *tcb;
+       double seq;
+};
+
+/*!
+ * SERVICE THREAD
+ */
+static inline int put_reply_context(struct tcb *tcb, double seq)
+{
+       struct context *ctx;
+
+       ctx = malloc(sizeof(*ctx));
+       if (!ctx) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return -ENOMEM;
+       }
+
+       ctx->tcb = tcb;
+       ctx->seq = seq; /* Could we this sequence value is uniq? */
+
+       s_info.context_list = eina_list_append(s_info.context_list, ctx);
+       return 0;
+}
+
+/*!
+ * SERVICE THREAD
+ */
+static inline struct tcb *get_reply_context(double seq)
+{
+       Eina_List *l;
+       Eina_List *n;
+       struct context *ctx;
+       struct tcb *tcb;
+
+       tcb = NULL;
+       EINA_LIST_FOREACH_SAFE(s_info.context_list, l, n, ctx) {
+               if (ctx->seq != seq)
+                       continue;
+
+               s_info.context_list = eina_list_remove(s_info.context_list, ctx);
+               tcb = ctx->tcb;
+               free(ctx);
+               break;
+       }
+
+       return tcb;
+}
+
+/*!
+ * SERVICE THREAD
+ */
+static int service_thread_main(struct tcb *tcb, struct packet *packet, void *data)
+{
+       const char *command;
+
+       command = packet_command(packet);
+       if (!command) {
+               ErrPrint("Invalid command\n");
+               return -EINVAL;
+       }
+
+       switch (packet_type(packet)) {
+       case PACKET_REQ:
+               /* Need to send reply packet */
+               DbgPrint("REQ: Command: [%s]\n", command);
+               if (!strcmp(command, "register_service")) {
+                       /*!
+                        * To multicast event packets to the service clients
+                        */
+                       tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE);
+                       break;
+               }
+
+               if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0)
+                       ErrPrint("Unable to send service request packet\n");
+               else
+                       (void)put_reply_context(tcb, packet_seq(packet));
+               break;
+       case PACKET_REQ_NOACK:
+               /* Doesn't need to send reply packet */
+               DbgPrint("REQ_NOACK: Command: [%s]\n", command);
+               if (!strcmp(command, "register_service")) {
+                       tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE);
+                       break;
+               }
+
+               if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0)
+                       ErrPrint("Unable to send service reuqest packet\n");
+               break;
+       case PACKET_ACK:
+               /* Okay, client(or app) send a reply packet to us. */
+               DbgPrint("ACK: Command: [%s]\n", command);
+               tcb = get_reply_context(packet_seq(packet));
+               if (!tcb) {
+                       ErrPrint("There is no proper context\n");
+                       break;
+               }
+
+               if (service_common_unicast_packet(tcb, packet) < 0)
+                       ErrPrint("Unable to send reply packet\n");
+               break;
+       default:
+               ErrPrint("Packet type is not valid[%s]\n", command);
+               return -EINVAL;
+       }
+
+       /*!
+        * return value has no meanning,
+        * it will be printed by dlogutil.
+        */
+       return 0;
+}
+
+
+/*!
+ * MAIN THREAD
+ * Do not try to do anyother operation in these functions
+ */
+
+int service_shortcut_init(void)
+{
+       if (s_info.svc_ctx) {
+               ErrPrint("Already initialized\n");
+               return LB_STATUS_ERROR_ALREADY;
+       }
+
+       s_info.svc_ctx = service_common_create(SHORTCUT_ADDR, service_thread_main, NULL);
+       if (!s_info.svc_ctx)
+               return LB_STATUS_ERROR_FAULT;
+
+       return LB_STATUS_SUCCESS;
+}
+
+int service_shortcut_fini(void)
+{
+       if (!s_info.svc_ctx)
+               return LB_STATUS_ERROR_INVALID;
+
+       service_common_destroy(s_info.svc_ctx);
+       return LB_STATUS_SUCCESS;
+}
+
+/* End of a file */
index 81559a0..eac009d 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 47428bd..570852e 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index da304fc..b029526 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index ee3f578..039973b 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 92efdbb..94fb941 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
index 7278f28..bd2dccf 100644 (file)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://floralicense.org
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,