/*
- * rpcproperty.cpp
+ * Sigmadrone
+ * Copyright (c) 2013-2015 The Sigmadrone Developers
*
- * Created on: Oct 22, 2019
- * Author: mstoilov
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Martin Stoilov <martin@sigmadrone.org>
+ * Svetoslav Vassilev <svassilev@sigmadrone.org>
*/
#include "property.h"
/*
- * rpcproperty.h
+ * Sigmadrone
+ * Copyright (c) 2013-2015 The Sigmadrone Developers
*
- * Created on: Oct 22, 2019
- * Author: mstoilov
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Martin Stoilov <martin@sigmadrone.org>
+ * Svetoslav Vassilev <svassilev@sigmadrone.org>
*/
#ifndef RPCPROPERTY_H_
#include <assert.h>
#include <functional>
-#include "rexjson++.h"
+#include "rexjson/rexjson++.h"
namespace rexjson {
set_prop_impl(U* prop, const rexjson::value& val)
{
if (val.get_type() == rexjson::int_type) {
- *prop = val.get_int();
+ *prop = val.get_int64();
+ } else if (val.get_type() == rexjson::real_type) {
+ *prop = (U)val.get_real();
+ } else if (val.get_type() == rexjson::bool_type) {
+ *prop = val.get_bool() ? 1 : 0;
+ } else {
+ throw std::runtime_error("Invalid property type.");
}
}
virtual property& operator[](const std::string& name)
{
- return map_.operator [](name);
+ std::map<std::string, property>::iterator it = map_.find(name);
+ if (it == map_.end())
+ throw std::runtime_error("Invalid property: " + name);
+ return it->second;
}
virtual property& push_back(const property& v) override
#include <stdexcept>
#include <iostream>
#include <functional>
-#include "rexjson++.h"
+#include "rexjson/rexjson++.h"
#ifndef ARRAYSIZE
#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
return rpc_wrapper<Ret, Args...>([=](Args... args)->Ret {return (object->*f)(args...);}, help_msg);
}
+template<typename Ret, typename C, typename ...Args>
+rpc_wrapper<Ret, Args...> make_rpc_wrapper_const(const C* object, Ret (C::*f)(Args...) const, std::string help_msg = std::string())
+{
+ return rpc_wrapper<Ret, Args...>([=](Args... args)->Ret {return (object->*f)(args...);}, help_msg);
+}
+
struct rpc_server_dummy { };