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_client.h"
17ca0551cfSopenharmony_ci
18ca0551cfSopenharmony_ci#include "if_system_ability_manager.h"
19ca0551cfSopenharmony_ci#include "ipc_debug.h"
20ca0551cfSopenharmony_ci#include "ipc_skeleton.h"
21ca0551cfSopenharmony_ci#include "iservice_registry.h"
22ca0551cfSopenharmony_ci#include "system_ability_definition.h"
23ca0551cfSopenharmony_ci
24ca0551cfSopenharmony_cinamespace OHOS {
25ca0551cfSopenharmony_ciint TestClient::ConnectService()
26ca0551cfSopenharmony_ci{
27ca0551cfSopenharmony_ci    auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
28ca0551cfSopenharmony_ci    if (saMgr == nullptr) {
29ca0551cfSopenharmony_ci        ZLOGE(LABEL, "get registry fail");
30ca0551cfSopenharmony_ci        return -1;
31ca0551cfSopenharmony_ci    }
32ca0551cfSopenharmony_ci
33ca0551cfSopenharmony_ci    sptr<IRemoteObject> object = saMgr->GetSystemAbility(IPC_TEST_SERVICE);
34ca0551cfSopenharmony_ci    if (object != nullptr) {
35ca0551cfSopenharmony_ci        ZLOGE(LABEL, "Got test Service object");
36ca0551cfSopenharmony_ci        testService_ = (new (std::nothrow) IdlTestServiceProxy(object));
37ca0551cfSopenharmony_ci    }
38ca0551cfSopenharmony_ci
39ca0551cfSopenharmony_ci    if (testService_ == nullptr) {
40ca0551cfSopenharmony_ci        ZLOGE(LABEL, "Could not find Test Service!");
41ca0551cfSopenharmony_ci        return -1;
42ca0551cfSopenharmony_ci    }
43ca0551cfSopenharmony_ci
44ca0551cfSopenharmony_ci    return 0;
45ca0551cfSopenharmony_ci}
46ca0551cfSopenharmony_ci
47ca0551cfSopenharmony_civoid TestClient::StartIntTransaction()
48ca0551cfSopenharmony_ci{
49ca0551cfSopenharmony_ci    if (testService_ != nullptr) {
50ca0551cfSopenharmony_ci        ZLOGE(LABEL, "StartIntTransaction");
51ca0551cfSopenharmony_ci        [[maybe_unused]] int result = 0;
52ca0551cfSopenharmony_ci        testService_->TestIntTransaction(1234); // 1234 : test number
53ca0551cfSopenharmony_ci        ZLOGE(LABEL, "Rec result from server %{public}d.", result);
54ca0551cfSopenharmony_ci    }
55ca0551cfSopenharmony_ci}
56ca0551cfSopenharmony_ci
57ca0551cfSopenharmony_civoid TestClient::StartStringTransaction()
58ca0551cfSopenharmony_ci{
59ca0551cfSopenharmony_ci    if (testService_ != nullptr) {
60ca0551cfSopenharmony_ci        ZLOGI(LABEL, "StartIntTransaction");
61ca0551cfSopenharmony_ci        testService_->TestStringTransaction("IDL Test");
62ca0551cfSopenharmony_ci    }
63ca0551cfSopenharmony_ci}
64ca0551cfSopenharmony_ci} // namespace OHOS
65