Home | History | Annotate | Download | only in test-rpc-proxy
      1 //
      2 // Copyright (C) 2015 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 PROXY_UTIL_H
     18 #define PROXY_UTIL_H
     19 
     20 #include <string>
     21 #include <vector>
     22 
     23 #include <XmlRpcValue.h>
     24 
     25 #include <brillo/any.h>
     26 #include <brillo/variant_dictionary.h>
     27 
     28 // Conversion functions to go from XmlRpc::XmlRpcValue to brillo::Any and vice
     29 // versa.
     30 void GetXmlRpcValueFromBrilloAnyValue(
     31     const brillo::Any& any_value_in,
     32     XmlRpc::XmlRpcValue* xml_rpc_value_out);
     33 // Note: We assume that all the XmlRpcValue array elements are of the same type
     34 // even though they're not mandated by the Xml Rpc spec.
     35 void GetBrilloAnyValueFromXmlRpcValue(
     36     XmlRpc::XmlRpcValue* xml_rpc_value_in,
     37     brillo::Any* any_value_out);
     38 // Functions to access members of structs sent over XmlRpc and need to be converted
     39 // to corresponding objects. Returns |true| if the value is found in the incoming data
     40 // or |false| if the value was taken from the default supplied.
     41 bool GetBoolValueFromXmlRpcValueStructMember(
     42     XmlRpc::XmlRpcValue* xml_rpc_value_in,
     43     const std::string& member_name,
     44     bool default_value,
     45     bool* value_out);
     46 bool GetIntValueFromXmlRpcValueStructMember(
     47     XmlRpc::XmlRpcValue* xml_rpc_value_in,
     48     const std::string& member_name,
     49     int default_value,
     50     int* value_out);
     51 bool GetDoubleValueFromXmlRpcValueStructMember(
     52     XmlRpc::XmlRpcValue* xml_rpc_value_in,
     53     const std::string& member_name,
     54     double default_value,
     55     double* value_out);
     56 bool GetStringValueFromXmlRpcValueStructMember(
     57     XmlRpc::XmlRpcValue* xml_rpc_value_in,
     58     const std::string& member_name,
     59     const std::string& default_value,
     60     std::string* value_out);
     61 bool GetStringVectorFromXmlRpcValueStructMember(
     62     XmlRpc::XmlRpcValue* xml_rpc_value_in,
     63     const std::string& member_name,
     64     const std::vector<std::string>& default_value,
     65     std::vector<std::string>* value_out);
     66 
     67 inline long GetMillisecondsFromSeconds(int time_seconds) {
     68   return time_seconds * 1000;
     69 }
     70 inline double GetSecondsFromMilliseconds(long time_milliseconds) {
     71   return static_cast<double>(time_milliseconds) / 1000;
     72 }
     73 #endif // PROXY_UTIL_H
     74