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 DHCP_CLIENT_OPTION_WRITER_H_ 18 #define DHCP_CLIENT_OPTION_WRITER_H_ 19 20 #include <cstdint> 21 #include <string> 22 #include <utility> 23 #include <vector> 24 25 #include <base/lazy_instance.h> 26 #include <shill/net/byte_string.h> 27 28 namespace dhcp_client { 29 30 class DHCPOptionsWriter { 31 public: 32 ~DHCPOptionsWriter() {} 33 static DHCPOptionsWriter* GetInstance(); 34 int WriteUInt8Option(shill::ByteString* buffer, 35 uint8_t option_code, 36 uint8_t value); 37 int WriteUInt16Option(shill::ByteString* buffer, 38 uint8_t option_code, 39 uint16_t value); 40 int WriteUInt32Option(shill::ByteString* buffer, 41 uint8_t option_code, 42 uint32_t value); 43 int WriteUInt8ListOption(shill::ByteString* buffer, 44 uint8_t option_code, 45 const std::vector<uint8_t>& value); 46 int WriteUInt16ListOption(shill::ByteString* buffer, 47 uint8_t option_code, 48 const std::vector<uint16_t>& value); 49 int WriteUInt32ListOption(shill::ByteString* buffer, 50 uint8_t option_code, 51 const std::vector<uint32_t>& value); 52 int WriteUInt32PairListOption(shill::ByteString* buffer, 53 uint8_t option_code, 54 const std::vector<std::pair<uint32_t, uint32_t>>& value); 55 int WriteBoolOption(shill::ByteString* buffer, 56 uint8_t option_code, 57 const bool value); 58 int WriteStringOption(shill::ByteString* buffer, 59 uint8_t option_code, 60 const std::string& value); 61 int WriteByteArrayOption(shill::ByteString* buffer, 62 uint8_t option_code, 63 const shill::ByteString& value); 64 int WriteEndTag(shill::ByteString* buffer); 65 66 protected: 67 DHCPOptionsWriter() {} 68 69 private: 70 friend struct base::DefaultLazyInstanceTraits<DHCPOptionsWriter>; 71 }; 72 73 } // namespace dhcp_client 74 75 #endif // DHCP_CLIENT_OPTION_WRITER_H_ 76