Move function definition to aul header
[platform/core/appfw/aul-1.git] / src / aul_comp_status.cc
1 /*
2  * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 "include/aul_comp_status.h"
18
19 #include <bundle_cpp.h>
20
21 #include "include/aul.h"
22 #include "include/aul_sock.h"
23 #include "include/aul_error.h"
24 #include "aul_util.h"
25 #include "aul_api.h"
26
27 #include "app_request.h"
28
29 using namespace aul::internal;
30
31 extern "C" API int aul_comp_status_update(const char* instance_id, int status) {
32   if (instance_id == nullptr ||
33       status < STATUS_LAUNCHING ||
34       status > STATUS_TERMINATE) {
35     _E("Invalid parameter");
36     return AUL_R_EINVAL;
37   }
38
39   tizen_base::Bundle b {
40     { AUL_K_INSTANCE_ID, instance_id },
41     { AUL_K_STATUS, std::to_string(status) },
42   };
43
44   return AppRequest(COMP_STATUS_UPDATE, getuid())
45       .With(std::move(b))
46       .SendSimply(AUL_SOCK_NOREPLY);
47 }
48
49 extern "C" API int aul_comp_notify_start(const char* instance_id) {
50   if (instance_id == nullptr) {
51     _E("Invalid parameter");
52     return AUL_R_EINVAL;
53   }
54
55   return AppRequest(COMP_NOTIFY_START, getuid())
56       .SetInstId(instance_id)
57       .SendSimply(AUL_SOCK_NOREPLY);
58 }
59
60 extern "C" API int aul_comp_notify_exit(const char* instance_id) {
61   if (instance_id == nullptr) {
62     _E("Invalid parameter");
63     return AUL_R_EINVAL;
64   }
65
66   return AppRequest(COMP_NOTIFY_EXIT, getuid())
67       .SetInstId(instance_id)
68       .SendSimply(AUL_SOCK_NOREPLY);
69 }
70
71 extern "C" API int aul_comp_resume(const char* instance_id) {
72   if (instance_id == nullptr) {
73     _E("Invalid parameter");
74     return AUL_R_EINVAL;
75   }
76
77   return AppRequest(COMP_CONTEXT_RESUME, getuid())
78       .SetInstId(instance_id)
79       .SendSimply();
80 }
81
82 extern "C" API int aul_comp_terminate(const char* instance_id) {
83   if (instance_id == nullptr) {
84     _E("Invalid parameter");
85     return AUL_R_EINVAL;
86   }
87
88   return AppRequest(COMP_CONTEXT_TERMINATE, getuid())
89       .SetInstId(instance_id)
90       .SendSimply();
91 }
92
93 extern "C" API int aul_comp_is_running(const char* instance_id, bool* running) {
94   if (instance_id == nullptr || running == nullptr) {
95     _E("Invalid parameter");
96     return AUL_R_EINVAL;
97   }
98
99   int ret = AppRequest(COMP_CONTEXT_IS_RUNNING, getuid())
100       .SetInstId(instance_id)
101       .SendSimply();
102   if (ret < 0)
103     return ret;
104
105   *running = (ret == 0) ? false : true;
106   return AUL_R_OK;
107 }