61ff9746df21026e696f6034238f80cb40973c42
[platform/core/telephony/libtcore.git] / include / core_object.h
1 /*
2  * libtcore
3  *
4  * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
5  * Copyright (c) 2013 Intel Corporation. All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #ifndef __CORE_OBJECT_H__
21 #define __CORE_OBJECT_H__
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #define CORE_OBJECT_TYPE_DEFAULT        0xB0000000
28 #define CORE_OBJECT_TYPE_MODEM  (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_MODEM)
29 #define CORE_OBJECT_TYPE_CALL           (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_CALL)
30 #define CORE_OBJECT_TYPE_SS             (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SS)
31 #define CORE_OBJECT_TYPE_NETWORK        (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_NETWORK)
32 #define CORE_OBJECT_TYPE_PS             (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PS)
33 #define CORE_OBJECT_TYPE_PS_CONTEXT     (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PDP)
34 #define CORE_OBJECT_TYPE_SIM            (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SIM)
35 #define CORE_OBJECT_TYPE_SAT            (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SAT)
36 #define CORE_OBJECT_TYPE_SAP            (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SAP)
37 #define CORE_OBJECT_TYPE_SMS            (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_SMS)
38 #define CORE_OBJECT_TYPE_PHONEBOOK      (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_PHONEBOOK)
39 #define CORE_OBJECT_TYPE_CUSTOM (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_CUSTOM)
40 #define CORE_OBJECT_TYPE_GPS            (CORE_OBJECT_TYPE_DEFAULT | TCORE_TYPE_GPS)
41
42 #define CORE_OBJECT_CHECK(co,t) \
43         if (co == NULL) { warn("core_object is NULL"); return; } \
44         if (tcore_object_get_type(co) != t) { \
45                 warn("type(0x%x != 0x%x) mismatch", tcore_object_get_type(co), t); \
46                 return; \
47         }
48
49 #define CORE_OBJECT_CHECK_RETURN(co,t,r) \
50         if (co == NULL) { warn("core_object is NULL"); return r; } \
51         if (tcore_object_get_type(co) != t) { \
52                 warn("type(0x%x != 0x%x) mismatch", tcore_object_get_type(co), t); \
53                 return r; \
54         }
55
56 #define GET_OBJECT_TYPE(command)        ((command & 0x0FF00000) | CORE_OBJECT_TYPE_DEFAULT)
57
58 typedef struct tcore_object_mapping_tbl TcoreObjectMappingTable;
59
60 typedef void (*TcoreObjectFreeHook)(CoreObject *co);
61 typedef void (*TcoreObjectCloneHook)(CoreObject *src, CoreObject *dest);
62 typedef gboolean (*TcoreObjectCallback)(CoreObject *co,
63         const void *event_info, void *user_data);
64
65 typedef gboolean (*TcoreObjectInit)(TcorePlugin *plugin, CoreObject *co);
66 typedef void (*TcoreObjectDeinit)(TcorePlugin *plugin, CoreObject *co);
67
68 /* Core Object Initializers */
69 typedef struct {
70         TcoreObjectInit modem_init;
71         TcoreObjectInit sim_init;
72         TcoreObjectInit sat_init;
73         TcoreObjectInit sap_init;
74         TcoreObjectInit network_init;
75         TcoreObjectInit ps_init;
76         TcoreObjectInit call_init;
77         TcoreObjectInit ss_init;
78         TcoreObjectInit sms_init;
79         TcoreObjectInit phonebook_init;
80         TcoreObjectInit gps_init;
81         /* To be updated based on New modules */
82 } TcoreObjectInitializer;
83
84 /* Core Object De-initializers */
85 typedef struct {
86         TcoreObjectDeinit modem_deinit;
87         TcoreObjectDeinit sim_deinit;
88         TcoreObjectDeinit sat_deinit;
89         TcoreObjectDeinit sap_deinit;
90         TcoreObjectDeinit network_deinit;
91         TcoreObjectDeinit ps_deinit;
92         TcoreObjectDeinit call_deinit;
93         TcoreObjectDeinit ss_deinit;
94         TcoreObjectDeinit sms_deinit;
95         TcoreObjectDeinit phonebook_deinit;
96         TcoreObjectDeinit gps_deinit;
97         /* To be updated based on New modules */
98 } TcoreObjectDeinitializer;
99
100 CoreObject *tcore_object_new(TcorePlugin *plugin, TcoreHal *hal);
101 void tcore_object_free(CoreObject *co);
102
103 TelReturn tcore_object_set_free_hook(CoreObject *co,
104                 TcoreObjectFreeHook free_hook);
105 TelReturn tcore_object_set_clone_hook(CoreObject *co,
106                 TcoreObjectCloneHook clone_hook);
107
108 CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent);
109 CoreObject *tcore_object_clone_template_object(TcorePlugin *p,
110                 guint co_type);
111
112 TelReturn tcore_object_set_plugin(CoreObject *co, TcorePlugin *plugin);
113 TcorePlugin *tcore_object_ref_plugin(CoreObject *co);
114
115 TelReturn tcore_object_link_object(CoreObject *co, void *object);
116 void *tcore_object_ref_object(CoreObject *co);
117
118 TelReturn tcore_object_set_type(CoreObject *co, guint type);
119 guint tcore_object_get_type(CoreObject *co);
120
121 TelReturn tcore_object_set_hal(CoreObject *co, TcoreHal *hal);
122 TcoreHal *tcore_object_get_hal(CoreObject *co);
123
124 TelReturn tcore_object_link_user_data(CoreObject *co, void *user_data);
125 void *tcore_object_ref_user_data(CoreObject *co);
126
127 TelReturn tcore_object_set_dispatcher(CoreObject *co, TcoreObjectDispatcher func);
128 TelReturn tcore_object_dispatch_request(CoreObject *co,
129                 gboolean exec_hooks, TcoreCommand command,
130                 const void *request, guint request_len,
131                 TcorePluginResponseCallback cb, const void *user_data);
132
133 TelReturn tcore_object_add_callback(CoreObject *co, const gchar *event,
134                 TcoreObjectCallback callback, void *user_data);
135 TelReturn tcore_object_del_callback(CoreObject *co, const gchar *event,
136                 TcoreObjectCallback callback);
137 TelReturn tcore_object_override_callback(CoreObject *co, const gchar *event,
138                 TcoreObjectCallback callback, void *user_data);
139 TelReturn tcore_object_emit_callback(CoreObject *co, const gchar *event,
140                 const void *event_info);
141
142 TelReturn tcore_object_add_request_hook(CoreObject *co,
143                 TcoreCommand command, TcoreRequestHook func, void *user_data);
144 void tcore_object_remove_request_hook(CoreObject *co,
145                 TcoreCommand command, TcoreRequestHook func);
146
147 TelReturn tcore_object_add_response_hook(CoreObject *co,
148                 TcoreCommand command, const void *request,
149                 TcoreResponseHook func, void *user_data);
150 void tcore_object_remove_response_hook(CoreObject *co,
151                 TcoreCommand command, TcoreResponseHook func);
152
153 TelReturn tcore_object_add_notification_hook(CoreObject *co,
154         TcoreNotification command, TcoreNotificationHook func, void *user_data);
155 void tcore_object_remove_notification_hook(CoreObject *co,
156         TcoreNotification command, TcoreNotificationHook func);
157 TelReturn tcore_object_send_notification(CoreObject *co,
158         TcoreNotification command, guint data_len, void *data);
159
160 void *tcore_object_add_mapping_tbl_entry(void *mapping_tbl,
161                 guint object_type, TcoreHal *hal);
162 void tcore_object_remove_mapping_tbl(void *mapping_tbl);
163 void *tcore_object_remove_mapping_tbl_entry(void *mapping_tbl, TcoreHal *hal);
164 void tcore_object_remove_mapping_tbl_entry_by_type(void *mapping_tbl,
165                 guint co_type);
166
167 void tcore_object_print_mapping_tbl(void *mapping_tbl);
168
169 TelReturn tcore_object_init_objects(TcorePlugin *plugin,
170                 TcoreObjectInitializer *initializer_list);
171 void tcore_object_deinit_objects(TcorePlugin *plugin,
172                 TcoreObjectDeinitializer *deinitializer_list);
173
174 #ifdef __cplusplus
175 }
176 #endif
177
178 #endif  /* __CORE_OBJECT_H__ */