2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file client_command_line_parser.cpp
18 * @author Jihoon Chung (jihoon.chung@samsung.com)
21 #include "client_command_line_parser.h"
27 #include <dpl/log/log.h>
28 #include <dpl/optional_typedefs.h>
29 #include <dpl/wrt-dao-ro/common_dao_types.h>
31 namespace ClientModule {
34 std::string parseIdField(int argc, char **argv)
36 if (argv[0] == NULL) {
40 std::string arg = argv[0];
45 if (arg.find("wrt-client") != std::string::npos) {
52 if (arg == "-h" || arg == "--help") {
54 } else if (arg == "-l" ||
67 std::size_t pos = arg.find_last_of('/');
68 if (pos != std::string::npos) {
69 arg = arg.erase(0, pos + 1);
75 DPL::OptionalUInt getIndex(const std::string& tizenId)
78 tizenId.find(WrtDB::AppControlPrefix::PROCESS_PREFIX);
79 if (pos != std::string::npos) {
80 std::string index = tizenId.substr(pos);
81 index.erase(strlen(WrtDB::AppControlPrefix::PROCESS_PREFIX));
82 std::stringstream s(index);
83 unsigned int appControlIndex;
85 return appControlIndex;
87 return DPL::OptionalUInt::Null;
90 std::string removeIndex(const std::string& tizenId)
92 std::string id = tizenId;
94 id.find(WrtDB::AppControlPrefix::PROCESS_PREFIX);
95 if (pos != std::string::npos) {
102 std::string CommandLineParser::getTizenId(int argc, char **argv)
104 std::string id = parseIdField(argc, argv);
108 return removeIndex(id);
111 DPL::OptionalUInt CommandLineParser::getAppControlIndex(int argc, char **argv)
113 std::string id = parseIdField(argc, argv);
115 return DPL::OptionalUInt::Null;