1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "test_service.h"
17
18 #include <string_ex.h>
19
20 #include "if_system_ability_manager.h"
21 #include "ipc_debug.h"
22 #include "ipc_skeleton.h"
23 #include "iservice_registry.h"
24 #include "system_ability_definition.h"
25
26 namespace OHOS {
27 using namespace OHOS::HiviewDFX;
28
Instantiate()29 int TestService::Instantiate()
30 {
31 ZLOGI(LABEL, "%{public}s call in", __func__);
32 auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
33 if (saMgr == nullptr) {
34 ZLOGE(LABEL, "%{public}s:fail to get Registry", __func__);
35 return -ENODEV;
36 }
37
38 sptr<IRemoteObject> newInstance = new TestService();
39 int result = saMgr->AddSystemAbility(IPC_TEST_SERVICE, newInstance);
40 ZLOGI(LABEL, "%{public}s: IPC_TEST_SERVICE result = %{public}d", __func__, result);
41 return result;
42 }
43
TestService()44 TestService::TestService()
45 {
46 }
47
~TestService()48 TestService::~TestService()
49 {
50 }
51
TestIntTransaction(int data)52 ErrCode TestService::TestIntTransaction(int data)
53 {
54 ZLOGE(LABEL, " TestService:read from client data = %{public}d", data);
55 return ERR_NONE;
56 }
57
TestStringTransaction(const std::string & data)58 ErrCode TestService::TestStringTransaction(const std::string &data)
59 {
60 ZLOGE(LABEL, "TestService:read string from client data = %{public}s", data.c_str());
61 return data.size();
62 }
63 } // namespace OHOS
64