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   std::list<RawAddress> device_;
45   std::list<bluetooth::Uuid> uuid_;
46   uint64_t loop_{1};
47   uint64_t msec_{0};
48 
49   bool close_stderr_{true};
50   bool clear_logcat_{false};
51 
52   mutable std::list<std::string> non_options_;
53 
54   static std::vector<std::string> Split(std::string);
55 
56 private:
57   void ParseValue(char* optarg, std::list<std::string>& my_list);
58   void ProcessOption(int option_index, char* optarg);
59   const char* name_{nullptr};
60   bool valid_{true};
61 };
62 
63 }  // namespace headless
64 }  // namespace test
65 }  // namespace bluetooth
66