Initialize the project.
[apps/livebox/data-provider-master.git] / src / dead_monitor.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <unistd.h>
19
20 #include <gio/gio.h>
21 #include <packet.h>
22 #include <com-core.h>
23 #include <dlog.h>
24
25 #include <Eina.h>
26
27 #include "slave_life.h"
28 #include "client_life.h"
29 #include "instance.h"
30 #include "fault_manager.h"
31 #include "util.h"
32 #include "debug.h"
33 #include "liveinfo.h"
34 #include "conf.h"
35
36 static int evt_cb(int handle, void *data)
37 {
38         struct slave_node *slave;
39         struct client_node *client;
40         struct liveinfo *liveinfo;
41
42         slave = slave_find_by_rpc_handle(handle);
43         if (slave) {
44                 DbgPrint("Slave is disconnected %d\n", handle);
45                 if (slave_pid(slave) != (pid_t)-1) {
46                         if (slave_state(slave) == SLAVE_REQUEST_TO_TERMINATE)
47                                 slave = slave_deactivated(slave);
48                         else if (slave_state(slave) != SLAVE_TERMINATED)
49                                 slave = slave_deactivated_by_fault(slave);
50                 }
51
52                 DbgPrint("Slave pointer: %p (0x0 means deleted)\n", slave);
53                 return 0;
54         }
55
56         client = client_find_by_rpc_handle(handle);
57         if (client) {
58                 DbgPrint("Client is disconnected\n");
59                 if (client_pid(client) != (pid_t)-1)
60                         client_deactivated_by_fault(client);
61
62                 return 0;
63         }
64
65         liveinfo = liveinfo_find_by_handle(handle);
66         if (liveinfo) {
67                 DbgPrint("Utility is disconnected\n");
68                 liveinfo_destroy(liveinfo);
69                 return 0;
70         }
71
72         DbgPrint("This is not my favor: %d\n", handle);
73         return 0;
74 }
75
76 HAPI int dead_init(void)
77 {
78         com_core_add_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL);
79 //      aul_listen_app_dead_signal(dead_cb, NULL);
80         return 0;
81 }
82
83 HAPI int dead_fini(void)
84 {
85         com_core_del_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL);
86         return 0;
87 }
88
89 /* End of a file */