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 <string> 17ca0551cfSopenharmony_ci#include <vector> 18ca0551cfSopenharmony_ci 19ca0551cfSopenharmony_ci#include "ipc_debug.h" 20ca0551cfSopenharmony_ci#include "ipc_skeleton.h" 21ca0551cfSopenharmony_ci#include "test_client.h" 22ca0551cfSopenharmony_ci 23ca0551cfSopenharmony_ciusing namespace OHOS; 24ca0551cfSopenharmony_ciusing namespace OHOS::HiviewDFX; 25ca0551cfSopenharmony_cistatic constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCTestClient" }; 26ca0551cfSopenharmony_ci 27ca0551cfSopenharmony_cienum class TestCommand { 28ca0551cfSopenharmony_ci TEST_CMD_NONE = 0, 29ca0551cfSopenharmony_ci TEST_CMD_INT_TRANS = 1, 30ca0551cfSopenharmony_ci TEST_CMD_STRING_TRANS = 2 31ca0551cfSopenharmony_ci}; 32ca0551cfSopenharmony_ci 33ca0551cfSopenharmony_cinamespace { 34ca0551cfSopenharmony_cistd::vector<std::string> GetArgvOptions(int argc, char **argv) 35ca0551cfSopenharmony_ci{ 36ca0551cfSopenharmony_ci std::vector<std::string> argvOptions; 37ca0551cfSopenharmony_ci for (int i = 1; i < argc; i++) { 38ca0551cfSopenharmony_ci argvOptions.emplace_back(std::string(argv[i])); 39ca0551cfSopenharmony_ci } 40ca0551cfSopenharmony_ci return argvOptions; 41ca0551cfSopenharmony_ci} 42ca0551cfSopenharmony_ci} 43ca0551cfSopenharmony_ci 44ca0551cfSopenharmony_ciint main(int argc, char *argv[]) 45ca0551cfSopenharmony_ci{ 46ca0551cfSopenharmony_ci TestCommand commandId = TestCommand::TEST_CMD_INT_TRANS; 47ca0551cfSopenharmony_ci if (argc > 1) { 48ca0551cfSopenharmony_ci commandId = TestCommand(atoi(argv[1])); 49ca0551cfSopenharmony_ci } else { 50ca0551cfSopenharmony_ci ZLOGE(LABEL, "unknown command"); 51ca0551cfSopenharmony_ci } 52ca0551cfSopenharmony_ci std::vector<std::string> argvOptions; 53ca0551cfSopenharmony_ci argvOptions = GetArgvOptions(argc, argv); 54ca0551cfSopenharmony_ci std::unique_ptr<TestClient> testClient = std::make_unique<TestClient>(); 55ca0551cfSopenharmony_ci if (testClient->ConnectService()) { 56ca0551cfSopenharmony_ci return -1; 57ca0551cfSopenharmony_ci } 58ca0551cfSopenharmony_ci 59ca0551cfSopenharmony_ci ZLOGE(LABEL, "commandId= : %{public}d", commandId); 60ca0551cfSopenharmony_ci switch (commandId) { 61ca0551cfSopenharmony_ci case TestCommand::TEST_CMD_INT_TRANS: 62ca0551cfSopenharmony_ci testClient->StartIntTransaction(); 63ca0551cfSopenharmony_ci break; 64ca0551cfSopenharmony_ci case TestCommand::TEST_CMD_STRING_TRANS: 65ca0551cfSopenharmony_ci testClient->StartStringTransaction(); 66ca0551cfSopenharmony_ci break; 67ca0551cfSopenharmony_ci default: 68ca0551cfSopenharmony_ci ZLOGI(LABEL, "main arg error"); 69ca0551cfSopenharmony_ci break; 70ca0551cfSopenharmony_ci } 71ca0551cfSopenharmony_ci 72ca0551cfSopenharmony_ci IPCSkeleton::JoinWorkThread(); 73ca0551cfSopenharmony_ci return 0; 74ca0551cfSopenharmony_ci} 75