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