Initial Implementation of Node prelaunch
[platform/framework/web/crosswalk-tizen.git] / tizen / common / command_line.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef XWALK_COMMON_COMMAND_LINE_H_
18 #define XWALK_COMMON_COMMAND_LINE_H_
19
20 #include <map>
21 #include <string>
22 #include <vector>
23
24 namespace common {
25
26 class CommandLine {
27  public:
28   // CommandLine only uses long options
29   typedef std::map<std::string, std::string> OptionMap;
30   // Arguments which except for option strings
31   typedef std::vector<std::string> Arguments;
32
33   static bool Init(int argc, char* argv[]);
34   static CommandLine* ForCurrentProcess();
35   static void Reset();
36
37   // Test if options_ has 'option_name'
38   bool HasOptionName(const std::string& option_name);
39   // Get the option's value
40   std::string GetOptionValue(const std::string& option_name);
41   // Get command string include options and arguments
42   std::string GetCommandString();
43
44   std::string GetAppIdFromCommandLine(const std::string& program);
45
46   std::string program() const { return program_; }
47   const OptionMap& options() const { return options_; }
48   const Arguments& arguments() const { return arguments_; }
49   char** argv() const { return argv_; }
50   int argc() const { return argc_; }
51
52  private:
53   CommandLine(int argc, char* argv[]);
54   virtual ~CommandLine();
55
56   void AppendOption(const char* value);
57
58   // The singleton CommandLine instance of current process
59   static CommandLine* current_process_commandline_;
60
61   std::string program_;
62   OptionMap options_;
63   Arguments arguments_;
64   int argc_;
65   char** argv_;
66 };
67
68 }  // namespace common
69
70 #endif  // XWALK_COMMON_COMMAND_LINE_H_