1 /*
2  * Copyright 2020 The Android Open Source Project
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 #pragma once
18 
19 #include <list>
20 #include <string>
21 #include <vector>
22 
23 #include "types/bluetooth/uuid.h"
24 #include "types/raw_address.h"
25 
26 namespace bluetooth {
27 namespace test {
28 namespace headless {
29 
30 class GetOpt {
31  public:
32   GetOpt(int argc, char** arv);
33   virtual ~GetOpt();
34 
35   virtual void Usage() const;
IsValid()36   virtual bool IsValid() const { return valid_; };
37 
GetNextSubTest()38   std::string GetNextSubTest() const {
39     std::string test = non_options_.front();
40     non_options_.pop_front();
41     return test;
42   }
43 
44   const char** StackInitFlags() const;
45 
46   std::list<RawAddress> device_;
47   std::list<std::string> init_flags_;
48   std::list<bluetooth::Uuid> uuid_;
49   unsigned long loop_{1};
50   unsigned long msec_{0};
51 
52   bool close_stderr_{true};
53   bool clear_logcat_{false};
54 
55   mutable std::list<std::string> non_options_;
56 
57   static std::vector<std::string> Split(std::string);
58 
59  private:
60   void ParseValue(char* optarg, std::list<std::string>& my_list);
61   void ProcessOption(int option_index, char* optarg);
62   void ParseStackInitFlags();
63   const char* name_{nullptr};
64   const char** stack_init_flags_{nullptr};
65   bool valid_{true};
66 };
67 
68 }  // namespace headless
69 }  // namespace test
70 }  // namespace bluetooth
71