Commit summary:
[platform/core/security/suspicious-activity-monitor.git] / utest / mock / app_control_stub.cpp
1 /**
2  * Samsung Ukraine R&D Center (SRK under a contract between)
3  * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 #include <cassert>
19 #include "app_control_stub.h"
20
21 namespace
22 {
23 static IAppControl* app_control = nullptr;
24
25 void app_control_set_implementation(IAppControl* impl)
26 {
27     app_control = impl;
28 }
29
30 IAppControl* app_control_from_handle(app_control_h handle)
31 {
32     assert(handle);
33     IAppControl** p = reinterpret_cast<IAppControl**>(handle);
34     assert(*p);
35     return *p;
36 }
37 }
38
39 IAppControl::IAppControl()
40 {
41     app_control_set_implementation(this);
42 }
43 IAppControl::~IAppControl()
44 {
45     app_control_set_implementation(nullptr);
46 }
47
48 int app_control_create(app_control_h* handle)
49 {
50     assert(app_control);
51     int ret = app_control->app_control_create(handle);
52     *handle = (app_control_h)&app_control;
53     return ret;
54 }
55 int app_control_destroy(app_control_h handle)
56 {
57     assert(handle);
58     IAppControl** p = reinterpret_cast<IAppControl**>(handle);
59     if (p != nullptr && *p != nullptr && *p == app_control) {
60         (*p)->app_control_destroy();
61     }
62     return 0;
63 }
64
65 int app_control_set_operation(app_control_h handle, const char* operation)
66 {
67     return app_control_from_handle(handle)->app_control_set_operation(operation);
68 }
69 int app_control_set_app_id(app_control_h handle, const char* app_id)
70 {
71     return app_control_from_handle(handle)->app_control_set_app_id(app_id);
72 }
73 int app_control_add_extra_data(app_control_h handle, const char* key, const char* value)
74 {
75     return app_control_from_handle(handle)->app_control_add_extra_data(key, value);
76 }
77
78 int app_control_send_launch_request(app_control_h handle, app_control_reply_cb callback, void* user_data)
79 {
80     return app_control_from_handle(handle)->app_control_send_launch_request(callback, user_data);
81 }