16#ifndef HAVE_PRE_0_7_6_SYSREPO
17using namespace sysrepo;
22string encode64(
const string& input) {
23 vector<uint8_t> binary;
24 binary.resize(input.size());
25 memmove(&binary[0], input.c_str(), binary.size());
29string decode64(
const string& input) {
30 vector<uint8_t> binary;
33 result.resize(binary.size());
34 memmove(&result[0], &binary[0], result.size());
44 : session_(session), model_(model) {
55 switch (s_val->type()) {
57 case SR_CONTAINER_PRESENCE_T:
71 return (
Element::create(
static_cast<long long>(s_val->data()->get_uint8())));
74 return (
Element::create(
static_cast<long long>(s_val->data()->get_uint16())));
77 return (
Element::create(
static_cast<long long>(s_val->data()->get_uint32())));
80 return (
Element::create(
static_cast<long long>(s_val->data()->get_int8())));
83 return (
Element::create(
static_cast<long long>(s_val->data()->get_int16())));
86 return (
Element::create(
static_cast<long long>(s_val->data()->get_int32())));
88 case SR_IDENTITYREF_T:
99 "value called with unupported type: " << s_val->type());
107 s_val =
session_->get_item(xpath.c_str());
108 }
catch (
const sysrepo_exception& ex) {
110 <<
"': " << ex.
what());
115 return (
value(s_val));
122 s_vals =
session_->get_items(xpath.c_str());
127 for (
size_t i = 0; i < s_vals->val_cnt(); ++i) {
128 S_Val s_val = s_vals->val(i);
129 result->add(
value(s_val));
132 }
catch (
const sysrepo_exception& ex) {
134 "sysrepo error getting item at '" << xpath
135 <<
"': " << ex.
what());
147 case SR_CONTAINER_PRESENCE_T:
159 case SR_IDENTITYREF_T:
163 "value for a string called with not a string: "
166 s_val.reset(
new Val(elem->stringValue().c_str(), type));
172 "value for a boolean called with not a boolean: "
175 s_val.reset(
new Val(elem->boolValue(), type));
181 "value for an integer called with not an integer: "
184 s_val.reset(
new Val(
static_cast<uint8_t
>(elem->intValue()), type));
190 "value for an integer called with not an integer: "
193 s_val.reset(
new Val(
static_cast<uint16_t
>(elem->intValue()), type));
199 "value for an integer called with not an integer: "
202 s_val.reset(
new Val(
static_cast<uint32_t
>(elem->intValue()), type));
208 "value for an integer called with not an integer: "
211 s_val.reset(
new Val(
static_cast<int8_t
>(elem->intValue()), type));
217 "value for an integer called with not an integer: "
220 s_val.reset(
new Val(
static_cast<int16_t
>(elem->intValue()), type));
226 "value for an integer called with not an integer: "
229 s_val.reset(
new Val(
static_cast<int32_t
>(elem->intValue()), type));
235 "value for a base64 called with not a string: "
238 s_val.reset(
new Val(encode64(elem->stringValue()).c_str(), type));
243 "value called with unupported type: " << type);
252 S_Val s_val =
value(elem, type);
253 if (!s_val && (type != SR_LIST_T)) {
257 session_->set_item(xpath.c_str(), s_val);
258 }
catch (
const sysrepo_exception& ex) {
260 "sysrepo error setting item '" << elem->str()
261 <<
"' at '" << xpath <<
"': " << ex.
what());
268 session_->delete_item(xpath.c_str());
269 }
catch (
const sysrepo_exception& ex) {
271 "sysrepo error deleting item at '"
272 << xpath <<
"': " << ex.
what());
279 return (
session_->get_items_iter(xpath.c_str()));
289 s_val =
session_->get_item_next(iter);
290 }
catch (
const sysrepo_exception&) {
297 return (s_val->xpath());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
std::string getNext(sysrepo::S_Iter_Value iter)
Get xpath of the next YANG list item.
isc::data::ElementPtr getItem(const std::string &xpath)
Get and translate basic value from YANG to JSON.
sysrepo::S_Iter_Value getIter(const std::string &xpath)
List iterator methods keeping the session private.
static isc::data::ElementPtr value(sysrepo::S_Val s_val)
Translate basic value from YANG to JSON.
TranslatorBasic(sysrepo::S_Session session, const std::string &model)
Constructor.
void delItem(const std::string &xpath)
Delete basic value from YANG.
void setItem(const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
Translate and set basic value from JSON to YANG.
sysrepo::S_Session session_
The sysrepo session.
isc::data::ElementPtr getItems(const std::string &xpath)
Get and translate a list of basic values from YANG to JSON.
virtual ~TranslatorBasic()
Destructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
void decodeBase64(const std::string &input, std::vector< uint8_t > &result)
Decode a text encoded in the base64 format into the original data.
std::string encodeBase64(const std::vector< uint8_t > &binary)
Encode binary data in the base64 format.
Defines the logger used by the top-level component of kea-dhcp-ddns.