Use clock_gettime() with CLOCK_MONOTONIC which is not affected by changing system...
[platform/core/multimedia/mmsvc-core.git] / core / include / muse_core_internal.h
1 /*
2  * muse-core
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: YoungHun Kim <yh8004.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __MUSE_CORE_INTERNAL_H__
23 #define __MUSE_CORE_INTERNAL_H__
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #ifndef __USE_GNU
30 #define __USE_GNU
31 #endif
32
33 #ifndef _GNU_SOURCE
34 #define _GNU_SOURCE
35 #endif
36
37 #include "muse_core.h"
38 #include <dlog.h>
39 #include <fcntl.h>
40 #include <glib.h>
41 #include <gmodule.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <sys/un.h>
45 #include <sys/socket.h>
46 #include <sys/stat.h>
47 #include <sys/time.h>
48 #include <unistd.h>
49 #include <iniparser.h>
50 #include <time.h>
51
52 #define CONFFILE                                        SYSCONFDIR"/multimedia/mused.conf"
53 #define MUSE_HOST                                       "muse:hosts"
54 #define INI_PARSER_COMMA                        ","
55 #define MUSE_DATA_ROOT_PATH                     TZ_SYS_DATA_PATH"/mused/"
56 #define MUSE_DEFAULT_PIDFILE            "/tmp/.muse-server.pid"
57 #define MUSE_SOCK_FILE0                         "/tmp/.muse_server_socket"
58 #define MUSE_SOCK_FILE1                         "/tmp/.muse_server_data_socket"
59 #define MUSE_LOG_PATH                           "/var/log/mused"
60 #define MUSE_LOG_FILE                           MUSE_LOG_PATH"/muselog"
61 #define MUSE_USE_LOG                            "yes"
62
63 #define READ                                            0x02
64 #define PERSIST                                         0x10
65
66 #define MUSE_ERR                                        -1
67 #define SEND_FAIL                                       -1
68 #define RECV_FAIL                                       -1
69 #define MUSE_PARAM_MAX                          10
70 #define MUSE_LOG_MSG_NUM                        10
71
72 #define PARSE_ERROR                                     -1
73
74 /* message */
75 #define MUSE_MSG_LEN                            32
76 #define MUSE_MSG_TIME_LEN                       64
77 #define MUSE_MSG_LEN_MAX                        128
78
79 /* dispatcher */
80 #define MUSE_DISPATCHER_MAX                     512
81
82 #define MSG_KEY_API                                     "api"
83 #define MSG_KEY_MODULE_INDEX            "module"
84 #define MSG_KEY_MODULE_ADDR                     "module_addr"
85
86 #define DISPATCHER                                      "dispatcher"
87 #define DISPATCHER_PTR                          "dispatcher_pointer"
88 #define CMD_DISPATCHER                          "cmd_dispatcher"
89 #define END_DELIM                                       '}'
90 #define END_DELIM_STR                           " }"
91
92 #define muse_return_if_fail(expr) \
93         do { \
94                 if (!(expr)) { \
95                         LOGE("failed [%s]", #expr); \
96                         return; \
97                 } \
98         } while (0)
99
100 #define muse_return_val_if_fail(expr, val) \
101         do { \
102                 if (!(expr)) { \
103                         LOGE("failed [%s]", #expr); \
104                         return (val); \
105                 } \
106         } while (0)
107
108 #define MUSE_FREE(src) \
109         do { \
110                 if (src) { \
111                         free(src); \
112                         src = NULL; \
113                 } \
114         } while (0)
115
116 #define MUSE_G_FREE(src) \
117         do { \
118                 if (src) { \
119                         g_free(src); \
120                         src = NULL; \
121                 } \
122         } while (0)
123
124 typedef enum {
125         MUSE_PLAYER,
126         MUSE_CAMERA,
127         MUSE_RECORDER,
128         MUSE_DRM_SVC,
129         MUSE_EPPLAYER,
130         MUSE_MODULE_MAX
131 } muse_core_module_e;
132
133 typedef enum {
134         API_CREATE,
135         API_DESTROY,
136         API_MAX = MUSE_DISPATCHER_MAX
137 } muse_api_type_e;
138
139 typedef struct muse_channel_info {
140         GThread *thread;
141         int sock_fd;
142         int tbm_fd[MUSE_NUM_FD];
143         union {
144                 GModule *dll_handle;
145                 struct {
146                         GQueue *data_queue;
147                         GMutex data_mutex;
148                         GCond data_cond;
149                 };
150         };
151 } muse_channel_info_t;
152
153 typedef struct muse_module {
154         muse_channel_info_t ch[MUSE_CHANNEL_MAX];
155         char recv_msg[MUSE_MSG_MAX_LENGTH + 1];
156         int msg_offset;
157         int idx;
158         int api;
159         int pid;
160         gpointer user_data;
161         intptr_t handle;
162         gboolean is_created;
163         GMutex dispatch_lock;
164 } muse_module_t;
165
166 typedef struct muse_recv_data_head {
167         unsigned int marker;
168         uint64_t id;
169         int size;
170 } muse_recv_data_head_t;
171
172 typedef struct muse_recv_data {
173         muse_recv_data_head_t header;
174         /* Dynamic allocated data area */
175 } muse_recv_data_t;
176
177 typedef enum {
178         MUSE_MSG_TYPE_NORMAL,
179         MUSE_MSG_TYPE_FDS
180 } muse_msg_type_e;
181
182 typedef struct muse_msg_info {
183         unsigned int marker;
184         muse_msg_type_e type;
185         int size;
186 } muse_msg_info_t;
187
188
189 #ifdef MUSE_GCOV_TEST
190 void muse_core_gcov_flush(void);
191 void muse_core_setenv(const char *name, const char *value, int replace);
192 #endif
193
194 bool muse_core_msg_recv_len(int fd, char *buf, int msg_len);
195 void muse_core_update_fd_state(int fd);
196 void muse_core_get_cur_time(struct timespec *time, char *time_buf);
197
198 #ifdef __cplusplus
199 }
200 #endif
201 #endif  /*__MUSE_CORE_INTERNAL_H__*/