Check the value at idle time for debugging the cpu usage issue
[platform/core/multimedia/mmsvc-core.git] / core / include / muse_core.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_H__
23 #define __MUSE_CORE_H__
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <stdbool.h>
30 #include <stdint.h>
31 #include <mm_error.h>
32
33 #define MUSE_URI_MAX_LENGTH             4096
34 #define MUSE_MSG_MAX_LENGTH             4096
35 #define MUSE_NUM_FD                             4
36
37 #define MUSE_SERVER_READY               "/tmp/.muse_server_ready"
38 #define MUSE_DATA_HEAD                  0xda1a6ead
39 #define MUSE_MSG_HEAD                   0xda1a6eae
40 #define MUSE_PARAM_HANDLE               "handle"
41 #define MUSE_PARAM_RETURN               "ret"
42 #define MUSE_PARAM_EVENT                "event"
43
44 typedef struct muse_module *muse_module_h;
45
46 typedef enum {
47         MUSE_TYPE_INT = 1,
48         MUSE_TYPE_INT64,
49         MUSE_TYPE_POINTER,
50         MUSE_TYPE_DOUBLE,
51         MUSE_TYPE_STRING,
52         MUSE_TYPE_ARRAY,
53         MUSE_TYPE_ANY,
54         MUSE_TYPE_MAX
55 } muse_core_msg_type_e;
56
57 typedef enum {
58         MUSE_MSG_PARSE_ERROR_NONE,
59         MUSE_MSG_PARSE_ERROR_CONTINUE,
60         MUSE_MSG_PARSE_ERROR_OTHER,
61         MUSE_MSG_PARSE_ERROR_MAX
62 } muse_core_msg_parse_err_e;
63
64 typedef enum {
65         MUSE_MODULE_COMMAND_INITIALIZE,
66         MUSE_MODULE_COMMAND_SHUTDOWN,
67         MUSE_MODULE_COMMAND_DEBUG_INFO_DUMP,
68         MUSE_MODULE_COMMAND_CREATE_SERVER_ACK,
69         MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE,
70         MUSE_MODULE_COMMAND_EXTERNAL_STORAGE_STATE_CHANGED,
71         MUSE_MODULE_COMMAND_CREATE_CAUTION,
72         MUSE_MODULE_COMMAND_RESOURCE_MANAGER_SHUTDOWN,
73         MUSE_MODULE_COMMAND_MAX
74 } muse_module_command_e;
75
76 typedef enum {
77         MUSE_CHANNEL_MSG,
78         MUSE_CHANNEL_DATA,
79         MUSE_CHANNEL_MAX
80 } muse_channel_e;
81
82 typedef struct muse_external_storage_info {
83         int id;
84         int state;
85         const char *path;
86 } muse_external_storage_info_t;
87
88 #ifdef MUSE_GCOV_TEST
89 extern void __gcov_flush(void);
90 #endif
91
92 int muse_core_connection_close(int sock_fd);
93 int muse_core_set_nonblocking(int fd, bool value);
94 int muse_core_set_socket_timeout(int sock_fd, int timeout_sec);
95 bool muse_core_fd_is_valid(int fd);
96 void muse_core_fd_close(int fd);
97
98 /* message */
99 int muse_core_msg_send(int sock_fd, const char *msg);
100 int muse_core_msg_recv(int sock_fd, char *msg, int msg_len);
101 int muse_core_msg_send_fd(int sock_fd, int *fds, const char *buf);
102 int muse_core_msg_recv_fd(int sock_fd, char *buf, int buf_len, int *out_fd);
103 char *muse_core_msg_new(int api, ...);
104 bool muse_core_msg_deserialize(const char *key, char *buf, int *parse_len,
105                 muse_core_msg_parse_err_e *err, muse_core_msg_type_e m_type, void *data);
106 void muse_core_msg_free(char *msg);
107 void *muse_core_msg_object_new(char *str, int *parse_len, muse_core_msg_parse_err_e *err);
108 bool muse_core_msg_object_get_value(const char *key, void *jobj, muse_core_msg_type_e m_type, void *data);
109 void muse_core_msg_object_free(void *msg_obj);
110
111 void muse_core_dump_fd_state(int fd);
112
113 void muse_core_create_fd_table(void);
114 void muse_core_remove_all_fd_table(void);
115 void muse_core_destroy_fd_table(void);
116 void muse_core_log_process_thread_info(int pid);
117 void muse_core_log_process_opened_fds(int pid);
118 void muse_core_log_process_cpu_memory(int pid);
119 int muse_core_get_process_cpu_usage(int pid);
120 void muse_core_log_file_list(const char *path);
121 void muse_core_log_cmd_info(char *cmd);
122 void muse_core_remove_symlink(const char *path);
123
124 bool muse_server_is_ready(void);
125
126 #ifdef __cplusplus
127 }
128 #endif
129 #endif  /*__MUSE_CORE_H__*/