• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #ifndef ART_ADBCONNECTION_JDWPARGS_H_
18 #define ART_ADBCONNECTION_JDWPARGS_H_
19 
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 namespace adbconnection {
25 
26 // A key/value store which respects order of insertion when join the values.
27 // This is necessary for jdwp agent parameter. e.g.: key "transport", must be
28 // issued before "address", otherwise oj-libjdpw will crash.
29 //
30 // If a key were to be re-inserted (a.k.a overwritten), the first insertion
31 // will be used for order.
32 class JdwpArgs {
33  public:
34   explicit JdwpArgs(const std::string& opts);
35   ~JdwpArgs() = default;
36 
37   // Add a key / value
38   void put(const std::string& key, const std::string& value);
39 
contains(const std::string & key)40   bool contains(const std::string& key) { return store.find(key) != store.end(); }
41 
get(const std::string & key)42   std::string& get(const std::string& key) { return store[key]; }
43 
44   // Concatenate all key/value into a command separated list of "key=value" entries.
45   std::string join();
46 
47  private:
48   std::vector<std::string> keys;
49   std::unordered_map<std::string, std::string> store;
50 };
51 
52 }  // namespace adbconnection
53 
54 #endif  // ART_ADBCONNECTION_JDWPARGS_H_
55