Check the value at idle time for debugging the cpu usage issue
[platform/core/multimedia/mmsvc-core.git] / server / include / muse_server_private.h
1 /*
2  * muse-server
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_SERVER_PRIVATE_H__
23 #define __MUSE_SERVER_PRIVATE_H__
24
25 #include "muse_server.h"
26 #include "muse_server_config.h"
27 #include "muse_server_connection.h"
28 #include "muse_server_log.h"
29 #include "muse_server_module.h"
30 #include "muse_server_signal.h"
31 #include "muse_server_security.h"
32 #include "muse_server_system.h"
33 #include "muse_server_watchdog.h"
34 #include "muse_server_tool.h"
35 #include <systemd/sd-daemon.h>
36 #include <pwd.h>
37 #include <grp.h>
38 #include <dlfcn.h>
39
40 #ifdef MUSE_TTRACE_LOG
41 #include <trace.h>
42 #endif
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #undef LOG_TAG
49 #define LOG_TAG                                         "MUSED_SERVER"
50 #define MSG_KEY_PID                                     "pid"
51 #define MS_TIMEOUT_SEC                          1
52 #define MS_TIMEOUT_MSEC                         MS_TIMEOUT_SEC * 1000
53 #define MS_RECV_TRY_COUNT_MAX           3
54 #define MSG_DONE                                        "DONE"
55
56 gboolean ms_ipc_create_msg_dispatch_worker(muse_module_h m);
57 gboolean ms_ipc_create_data_dispatch_worker(muse_module_h m);
58
59 typedef enum {
60         MUSE_SERVER_STATE_IDLE,
61         MUSE_SERVER_STATE_READY
62 } ms_state_e;
63
64 typedef struct _muse_server *muse_server_h;
65
66 typedef struct _muse_server {
67         int msg_fd;
68         int data_fd;
69         int type;
70         int stop;
71         int retval;
72         int pid;
73         int cpu_threshold;
74         gint running;
75         tbm_bufmgr bufmgr;
76         GMainLoop *main_loop;
77         GThread *diag_idle_state_thread;
78         GThread *diag_connection_event_thread;
79         ms_config_t *conf;
80         ms_connection_t *connection;
81         ms_module_t *module[MUSE_MODULE_MAX];
82         ms_log_t *log;
83         ms_security_t *security;
84         ms_system_t *system;
85         ms_watchdog_t *watchdog;
86         ms_state_e state;
87         GMutex state_lock;
88         struct timeval tv_s;
89         char instance_pid_info[MUSE_MSG_LEN_MAX];
90 } muse_server_t;
91
92 typedef struct ms_cmd_dispatch_info {
93         muse_module_command_e cmd;
94         muse_external_storage_info_t storage;
95 } ms_cmd_dispatcher_info_t;
96
97 void ms_setup_syslog(void);
98 void ms_fork(int *notify_fd);
99 pid_t ms_daemonize(int *notify_fd);
100 void ms_daemonize_complete(int notify_fd);
101 void ms_gst_init(char **cmd);
102 void ms_gst_preload_plugin(void);
103 int ms_pidfile_create(const char *path, pid_t pid);
104 void ms_init(char **argv);
105 muse_server_h ms_get_instance(void);
106 gboolean ms_check_module_idx(int idx);
107 ms_module_t *ms_get_module_instance(int idx);
108 int ms_deinit(void);
109 void ms_check_cpu_memory(int pid);
110 void ms_new(void);
111 int ms_open_lockfile(void);
112 void ms_run(void);
113 void ms_cmd_dispatch(muse_module_h m, muse_module_command_e cmd);
114 void ms_respawn(int signo);
115 int ms_get_pid(muse_module_h m);
116 void ms_log_process_info(int pid);
117 void ms_log_user_group_info(void);
118 gboolean ms_is_log_enabled(void);
119 int ms_kill_thread(int signo);
120 gboolean ms_init_bufmgr(void);
121 void ms_deinit_bufmgr(void);
122 void ms_cmd_dispatch_foreach_func(gpointer data, gpointer user_data);
123 void ms_set_state(ms_state_e state);
124 gboolean ms_is_server_ready(void);
125 void ms_diag_thread_create(void);
126 void ms_diag_thread_destroy(void);
127 gboolean ms_create_ready_file(void);
128 void ms_remove_ready_file(void);
129
130 #ifdef __cplusplus
131 }
132 #endif
133 #endif  /*__MUSE_SERVER_PRIVATE_H__*/