diff --git a/src/lib/libubus-cpp/include/ubus-cpp/ubus-call.h b/src/lib/libubus-cpp/include/ubus-cpp/ubus-call.h index 43bb73a9..c888dfcb 100644 --- a/src/lib/libubus-cpp/include/ubus-cpp/ubus-call.h +++ b/src/lib/libubus-cpp/include/ubus-cpp/ubus-call.h @@ -31,9 +31,9 @@ /*---------------------------------- DEFINE ----------------------------------*/ -#define kExecSuccess 0 -#define kExecFailed -6 -#define kExecInvalidArguments -5 +#define kExecSuccess 0 +#define kExecFailed -6 +#define kExecInvalidArguments -5 /*---------------------------------- DEPS ----------------------------------*/ @@ -43,18 +43,18 @@ class UBusExecReceiver; class UBusCall { -public: - UBusCall (void); - - int exec (const std::string &a_path, const std::string &a_method, - const std::string &a_parameter, std::string &a_result); + public: + UBusCall(void); - int exec_async (struct ubus_context *a_ctx, uint32_t an_object, const std::string &a_method, const std::string &a_parameter, UBusExecReceiver *a_receiver); + int exec(const std::string &a_path, const std::string &a_method, + const std::string &a_parameter, std::string &a_result); - int set_timeout (int a_timeout); - int set_result (const std::string &a_result); + int exec_async(struct ubus_context *a_ctx, uint32_t an_object, const std::string &a_method, const std::string &a_parameter, UBusExecReceiver *a_receiver); -private: + int set_timeout(int a_timeout); + int set_result(const std::string &a_result); + + private: int m_timeout; std::string m_data; }; diff --git a/src/lib/libubus-cpp/include/ubus-cpp/ubus-cpp.h b/src/lib/libubus-cpp/include/ubus-cpp/ubus-cpp.h index 893a07d4..a5e097a0 100644 --- a/src/lib/libubus-cpp/include/ubus-cpp/ubus-cpp.h +++ b/src/lib/libubus-cpp/include/ubus-cpp/ubus-cpp.h @@ -27,30 +27,33 @@ /*------------------------------- INCLUDES ----------------------------------*/ -extern "C" { +extern "C" { #include } +namespace UBus +{ -namespace UBus { - -namespace detail { +namespace detail +{ /** * simple POD vehicle for arrays */ -template -struct Array { - T* ptr; - size_t count; +template +struct Array +{ + T *ptr; + size_t count; }; /** * construct a detail::Array with one arg * @note : T should be a POD and each argument will be copied as is using memcpy */ -template -static inline Array makeArray(const T& e0) { +template +static inline Array makeArray(const T &e0) +{ Array result; result.count = 1; result.ptr = new T[result.count](); @@ -58,8 +61,9 @@ static inline Array makeArray(const T& e0) { return result; } -template -static inline Array makeArray(const T& e0, const T& e1) { +template +static inline Array makeArray(const T &e0, const T &e1) +{ Array result; result.count = 2; result.ptr = new T[result.count](); @@ -68,8 +72,9 @@ static inline Array makeArray(const T& e0, const T& e1) { return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2) +{ Array result; result.count = 3; result.ptr = new T[result.count](); @@ -79,9 +84,10 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2) { return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3) +{ Array result; result.count = 4; result.ptr = new T[result.count](); @@ -92,9 +98,10 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4) +{ Array result; result.count = 5; result.ptr = new T[result.count](); @@ -106,10 +113,10 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } - -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5) +{ Array result; result.count = 6; result.ptr = new T[result.count](); @@ -122,11 +129,11 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } - -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6) +{ Array result; result.count = 7; result.ptr = new T[result.count](); @@ -140,11 +147,11 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } - -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7) +{ Array result; result.count = 8; result.ptr = new T[result.count](); @@ -159,11 +166,11 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } - -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8) +{ Array result; result.count = 9; result.ptr = new T[result.count](); @@ -179,11 +186,12 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9) +{ Array result; result.count = 10; result.ptr = new T[result.count](); @@ -200,11 +208,12 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10) +{ Array result; result.count = 11; result.ptr = new T[result.count](); @@ -222,11 +231,12 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11) +{ Array result; result.count = 12; result.ptr = new T[result.count](); @@ -245,12 +255,13 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11, - const T& e12) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11, + const T &e12) +{ Array result; result.count = 13; result.ptr = new T[result.count](); @@ -270,13 +281,13 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } - -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11, - const T& e12, const T& e13) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11, + const T &e12, const T &e13) +{ Array result; result.count = 14; result.ptr = new T[result.count](); @@ -297,12 +308,13 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11, - const T& e12, const T& e13, const T& e14) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11, + const T &e12, const T &e13, const T &e14) +{ Array result; result.count = 15; result.ptr = new T[result.count](); @@ -324,13 +336,14 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11, - const T& e12, const T& e13, const T& e14, - const T& e15) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11, + const T &e12, const T &e13, const T &e14, + const T &e15) +{ Array result; result.count = 16; result.ptr = new T[result.count](); @@ -353,13 +366,14 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11, - const T& e12, const T& e13, const T& e14, - const T& e15, const T& e16) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11, + const T &e12, const T &e13, const T &e14, + const T &e15, const T &e16) +{ Array result; result.count = 17; result.ptr = new T[result.count](); @@ -383,13 +397,14 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11, - const T& e12, const T& e13, const T& e14, - const T& e15, const T& e16, const T& e17) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11, + const T &e12, const T &e13, const T &e14, + const T &e15, const T &e16, const T &e17) +{ Array result; result.count = 18; result.ptr = new T[result.count](); @@ -414,14 +429,15 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11, - const T& e12, const T& e13, const T& e14, - const T& e15, const T& e16, const T& e17, - const T& e18) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11, + const T &e12, const T &e13, const T &e14, + const T &e15, const T &e16, const T &e17, + const T &e18) +{ Array result; result.count = 19; result.ptr = new T[result.count](); @@ -447,14 +463,15 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } -template -static inline Array makeArray(const T& e0, const T& e1, const T& e2, - const T& e3, const T& e4, const T& e5, - const T& e6, const T& e7, const T& e8, - const T& e9, const T& e10, const T& e11, - const T& e12, const T& e13, const T& e14, - const T& e15, const T& e16, const T& e17, - const T& e18, const T& e19) { +template +static inline Array makeArray(const T &e0, const T &e1, const T &e2, + const T &e3, const T &e4, const T &e5, + const T &e6, const T &e7, const T &e8, + const T &e9, const T &e10, const T &e11, + const T &e12, const T &e13, const T &e14, + const T &e15, const T &e16, const T &e17, + const T &e18, const T &e19) +{ Array result; result.count = 20; result.ptr = new T[result.count](); @@ -481,25 +498,28 @@ static inline Array makeArray(const T& e0, const T& e1, const T& e2, return result; } - /** * simple copy of c string, free should be used to release memory */ -static inline char* copy_str(const char* str) { - return str ? strdup(str) : 0; +static inline char *copy_str(const char *str) +{ + return str ? strdup(str) : 0; } /** * generic function which copy an Array */ -template -static inline T* copy_array(const T* src, const size_t count, void(*copy_func)(T&, const T&)) { - if(count == 0 || src == 0) { +template +static inline T *copy_array(const T *src, const size_t count, void (*copy_func)(T &, const T &)) +{ + if (count == 0 || src == 0) + { return 0; } - T* result = new T[count]; - for(size_t i = 0; i < count; ++i) { + T *result = new T[count]; + for (size_t i = 0; i < count; ++i) + { copy_func(result[i], src[i]); } @@ -509,54 +529,65 @@ static inline T* copy_array(const T* src, const size_t count, void(*copy_func)(T /** * generic function which delete an array */ -template -static inline void delete_array(T* target, const size_t count, - void(*delete_func)(T&)) { - if(count == 0 || target == 0) { +template +static inline void delete_array(T *target, const size_t count, + void (*delete_func)(T &)) +{ + if (count == 0 || target == 0) + { return; } - for(size_t i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) + { delete_func(target[i]); } delete[] target; } - -struct Arg : public blobmsg_policy { }; +struct Arg : public blobmsg_policy +{ +}; /** * copy ubus method argument * @important : does not delete the previous content */ -static inline void copy_arg(blobmsg_policy& dest, const blobmsg_policy& src) { +static inline void copy_arg(blobmsg_policy &dest, const blobmsg_policy &src) +{ dest.name = copy_str(src.name); dest.type = src.type; } -static inline blobmsg_policy* copy_args(const blobmsg_policy* src, const size_t count) { +static inline blobmsg_policy *copy_args(const blobmsg_policy *src, const size_t count) +{ return copy_array(src, count, copy_arg); } -static inline void delete_arg(blobmsg_policy& target) { - free((char*)target.name); +static inline void delete_arg(blobmsg_policy &target) +{ + free((char *)target.name); } -static inline void delete_args(blobmsg_policy* target, size_t count) { +static inline void delete_args(blobmsg_policy *target, size_t count) +{ delete_array(target, count, delete_arg); } /** * simple wrapper which avoid mixin of c and c++ declaration */ -struct _Method : public ubus_method { }; +struct _Method : public ubus_method +{ +}; /** * copy a Method * @important : does not delete the prpevious content !!! */ -static inline void copy_method(ubus_method& dest, const ubus_method& src) { +static inline void copy_method(ubus_method &dest, const ubus_method &src) +{ dest.name = copy_str(src.name); dest.handler = src.handler; dest.mask = src.mask; @@ -567,213 +598,238 @@ static inline void copy_method(ubus_method& dest, const ubus_method& src) { /** * copy an array of Method */ -static inline ubus_method* copy_methods(const ubus_method* src, const size_t count) { +static inline ubus_method *copy_methods(const ubus_method *src, const size_t count) +{ return copy_array(src, count, copy_method); } /** * delete an Method */ -static inline void delete_method(ubus_method& target) { - free((char*)target.name); - delete_args((blobmsg_policy*)target.policy, target.n_policy); +static inline void delete_method(ubus_method &target) +{ + free((char *)target.name); + delete_args((blobmsg_policy *)target.policy, target.n_policy); } /** * delete an array of Method */ -static inline void delete_methods(ubus_method* target, const size_t count) { +static inline void delete_methods(ubus_method *target, const size_t count) +{ delete_array(target, count, delete_method); } - } - - -class ObjectType : public ubus_object_type { -public: - ObjectType(const char* name_, const detail::_Method& m0) { +class ObjectType : public ubus_object_type +{ + public: + ObjectType(const char *name_, const detail::_Method &m0) + { Init(name_, detail::makeArray(m0)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1) { + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1) + { Init(name_, detail::makeArray(m0, m1)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2) { + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2) + { Init(name_, detail::makeArray(m0, m1, m2)); } - - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3) { + + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3) + { Init(name_, detail::makeArray(m0, m1, m2, m3)); } - - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method m4) { + + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method m4) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4)); } - - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method m4, - const detail::_Method& m5) { + + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method m4, + const detail::_Method &m5) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5)); } - - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method m4, - const detail::_Method& m5, const detail::_Method& m6) { + + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method m4, + const detail::_Method &m5, const detail::_Method &m6) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6)); } - - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7) { + + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7)); } - - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8) { + + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9) { + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10) { + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11) { + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11, const detail::_Method& m12) { + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11, const detail::_Method &m12) + { Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11, const detail::_Method& m12, const detail::_Method& m13) { - Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, - m13)); + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11, const detail::_Method &m12, const detail::_Method &m13) + { + Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, + m13)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11, const detail::_Method& m12, const detail::_Method& m13, - const detail::_Method& m14) { - Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, - m13, m14)); + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11, const detail::_Method &m12, const detail::_Method &m13, + const detail::_Method &m14) + { + Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, + m13, m14)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11, const detail::_Method& m12, const detail::_Method& m13, - const detail::_Method& m14, const detail::_Method& m15) { - Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, - m13, m14, m15)); + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11, const detail::_Method &m12, const detail::_Method &m13, + const detail::_Method &m14, const detail::_Method &m15) + { + Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, + m13, m14, m15)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11, const detail::_Method& m12, const detail::_Method& m13, - const detail::_Method& m14, const detail::_Method& m15, const detail::_Method& m16) { - Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, - m13, m14, m15, m16)); + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11, const detail::_Method &m12, const detail::_Method &m13, + const detail::_Method &m14, const detail::_Method &m15, const detail::_Method &m16) + { + Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, + m13, m14, m15, m16)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11, const detail::_Method& m12, const detail::_Method& m13, - const detail::_Method& m14, const detail::_Method& m15, const detail::_Method& m16, - const detail::_Method& m17) { - Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, - m13, m14, m15, m16, m17)); + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11, const detail::_Method &m12, const detail::_Method &m13, + const detail::_Method &m14, const detail::_Method &m15, const detail::_Method &m16, + const detail::_Method &m17) + { + Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, + m13, m14, m15, m16, m17)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11, const detail::_Method& m12, const detail::_Method& m13, - const detail::_Method& m14, const detail::_Method& m15, const detail::_Method& m16, - const detail::_Method& m17, const detail::_Method& m18) { - Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, - m13, m14, m15, m16, m17, m18)); + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11, const detail::_Method &m12, const detail::_Method &m13, + const detail::_Method &m14, const detail::_Method &m15, const detail::_Method &m16, + const detail::_Method &m17, const detail::_Method &m18) + { + Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, + m13, m14, m15, m16, m17, m18)); } - ObjectType(const char* name_, const detail::_Method& m0, const detail::_Method& m1, - const detail::_Method& m2, const detail::_Method& m3, const detail::_Method& m4, - const detail::_Method& m5, const detail::_Method& m6, const detail::_Method& m7, - const detail::_Method& m8, const detail::_Method& m9, const detail::_Method& m10, - const detail::_Method& m11, const detail::_Method& m12, const detail::_Method& m13, - const detail::_Method& m14, const detail::_Method& m15, const detail::_Method& m16, - const detail::_Method& m17, const detail::_Method& m18, const detail::_Method& m19) { - Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, - m13, m14, m15, m16, m17, m18, m19)); + ObjectType(const char *name_, const detail::_Method &m0, const detail::_Method &m1, + const detail::_Method &m2, const detail::_Method &m3, const detail::_Method &m4, + const detail::_Method &m5, const detail::_Method &m6, const detail::_Method &m7, + const detail::_Method &m8, const detail::_Method &m9, const detail::_Method &m10, + const detail::_Method &m11, const detail::_Method &m12, const detail::_Method &m13, + const detail::_Method &m14, const detail::_Method &m15, const detail::_Method &m16, + const detail::_Method &m17, const detail::_Method &m18, const detail::_Method &m19) + { + Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, + m13, m14, m15, m16, m17, m18, m19)); } - - ObjectType(const char* name_, detail::Array m) { + ObjectType(const char *name_, detail::Array m) + { Init(name_, m); } - - ObjectType(const ObjectType& other) { - name = detail::copy_str(other.name); - id = other.id; - methods = detail::copy_methods(other.methods, other.n_methods); + ObjectType(const ObjectType &other) + { + name = detail::copy_str(other.name); + id = other.id; + methods = detail::copy_methods(other.methods, other.n_methods); n_methods = other.n_methods; } - ~ObjectType() { - free((char*)name); - detail::delete_methods((ubus_method*) methods, n_methods); + ~ObjectType() + { + free((char *)name); + detail::delete_methods((ubus_method *)methods, n_methods); } - ObjectType& operator=(ObjectType other) { + ObjectType &operator=(ObjectType other) + { Swap(other); return *this; } - void Swap(ObjectType& other) { + void Swap(ObjectType &other) + { ubus_object_type tmp = other; memcpy(&other, this, sizeof(*this)); memcpy(this, &tmp, sizeof(*this)); } -private: + private: // delegate constructor ... - void Init(const char* name_, detail::Array m) { + void Init(const char *name_, detail::Array m) + { name = detail::copy_str(name_); id = 0; methods = m.ptr; @@ -781,11 +837,11 @@ private: } }; - /** * generate an ubus_method without arg */ -static inline detail::_Method Method(const char* name, ubus_handler_t handler) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler) +{ detail::_Method result; result.name = detail::copy_str(name); result.handler = handler; @@ -799,130 +855,145 @@ static inline detail::_Method Method(const char* name, ubus_handler_t handler) { /** * generate an ubus_method with an array of args */ -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - detail::Array args) { - detail::_Method result; - result.name = detail::copy_str(name); +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + detail::Array args) +{ + detail::_Method result; + result.name = detail::copy_str(name); result.handler = handler; result.mask = 0; result.policy = args.ptr; - result.n_policy = args.count; + result.n_policy = args.count; return result; } /** * generate an ubus_method with one arg (shortcut for Array of one arg) - */ -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0) { + */ +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0) +{ return Method(name, handler, detail::makeArray(arg0)); } -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0, const detail::Arg& arg1) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0, const detail::Arg &arg1) +{ return Method(name, handler, detail::makeArray(arg0, arg1)); } -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0, const detail::Arg& arg1, - const detail::Arg& arg2) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0, const detail::Arg &arg1, + const detail::Arg &arg2) +{ return Method(name, handler, detail::makeArray(arg0, arg1, arg2)); } -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0, const detail::Arg& arg1, - const detail::Arg& arg2, const detail::Arg& arg3) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0, const detail::Arg &arg1, + const detail::Arg &arg2, const detail::Arg &arg3) +{ return Method(name, handler, detail::makeArray(arg0, arg1, arg2, arg3)); } -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0, const detail::Arg& arg1, - const detail::Arg& arg2, const detail::Arg& arg3, - const detail::Arg& arg4) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0, const detail::Arg &arg1, + const detail::Arg &arg2, const detail::Arg &arg3, + const detail::Arg &arg4) +{ return Method(name, handler, detail::makeArray(arg0, arg1, arg2, arg3, arg4)); } -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0, const detail::Arg& arg1, - const detail::Arg& arg2, const detail::Arg& arg3, - const detail::Arg& arg4, const detail::Arg& arg5) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0, const detail::Arg &arg1, + const detail::Arg &arg2, const detail::Arg &arg3, + const detail::Arg &arg4, const detail::Arg &arg5) +{ return Method(name, handler, detail::makeArray(arg0, arg1, arg2, arg3, arg4, arg5)); } -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0, const detail::Arg& arg1, - const detail::Arg& arg2, const detail::Arg& arg3, - const detail::Arg& arg4, const detail::Arg& arg5, - const detail::Arg& arg6) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0, const detail::Arg &arg1, + const detail::Arg &arg2, const detail::Arg &arg3, + const detail::Arg &arg4, const detail::Arg &arg5, + const detail::Arg &arg6) +{ return Method(name, handler, detail::makeArray(arg0, arg1, arg2, arg3, arg4, arg5, arg6)); } - -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0, const detail::Arg& arg1, - const detail::Arg& arg2, const detail::Arg& arg3, - const detail::Arg& arg4, const detail::Arg& arg5, - const detail::Arg& arg6, const detail::Arg& arg7) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0, const detail::Arg &arg1, + const detail::Arg &arg2, const detail::Arg &arg3, + const detail::Arg &arg4, const detail::Arg &arg5, + const detail::Arg &arg6, const detail::Arg &arg7) +{ return Method(name, handler, detail::makeArray(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); } - - -static inline detail::_Method Method(const char* name, ubus_handler_t handler, - const detail::Arg& arg0, const detail::Arg& arg1, - const detail::Arg& arg2, const detail::Arg& arg3, - const detail::Arg& arg4, const detail::Arg& arg5, - const detail::Arg& arg6, const detail::Arg& arg7, - const detail::Arg& arg8) { +static inline detail::_Method Method(const char *name, ubus_handler_t handler, + const detail::Arg &arg0, const detail::Arg &arg1, + const detail::Arg &arg2, const detail::Arg &arg3, + const detail::Arg &arg4, const detail::Arg &arg5, + const detail::Arg &arg6, const detail::Arg &arg7, + const detail::Arg &arg8) +{ return Method(name, handler, detail::makeArray(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); } - -static inline detail::Arg Arg(const char* name, enum blobmsg_type type) { +static inline detail::Arg Arg(const char *name, enum blobmsg_type type) +{ detail::Arg res; res.name = detail::copy_str(name); res.type = type; return res; } -static inline detail::Arg UnspecArg(const char* name) { +static inline detail::Arg UnspecArg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_UNSPEC); } -static inline detail::Arg ArrayArg(const char* name) { +static inline detail::Arg ArrayArg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_ARRAY); } -static inline detail::Arg TableArg(const char* name) { +static inline detail::Arg TableArg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_TABLE); } -static inline detail::Arg StringArg(const char* name) { +static inline detail::Arg StringArg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_STRING); } -static inline detail::Arg Int64Arg(const char* name) { +static inline detail::Arg Int64Arg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_INT64); } -static inline detail::Arg Int32Arg(const char* name) { +static inline detail::Arg Int32Arg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_INT32); } -static inline detail::Arg Int16Arg(const char* name) { +static inline detail::Arg Int16Arg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_INT16); } -static inline detail::Arg Int8Arg(const char* name) { +static inline detail::Arg Int8Arg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_INT8); } -static inline detail::Arg BoolArg(const char* name) { +static inline detail::Arg BoolArg(const char *name) +{ return Arg(name, BLOBMSG_TYPE_BOOL); } - -} // namespace UBus +} // namespace UBus /** * Generate a function which dispatch a ubus method call to the appropriate @@ -935,14 +1006,13 @@ static inline detail::Arg BoolArg(const char* name) { * has the signature : * int(struct ubus_context *ctx, struct ubus_request_data *req, struct blob_attr *msg) */ -template -static int ubus_hook (struct ubus_context *ctx, struct ubus_object *obj, - struct ubus_request_data *req, const char *method, - struct blob_attr *msg) -{ - return (static_cast(obj)->*Method)(ctx, req, msg); +template +static int ubus_hook(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + return (static_cast(obj)->*Method)(ctx, req, msg); } /** diff --git a/src/lib/libubus-cpp/include/ubus-cpp/ubus-event-receiver.h b/src/lib/libubus-cpp/include/ubus-cpp/ubus-event-receiver.h index aa66ec64..bc832a6a 100644 --- a/src/lib/libubus-cpp/include/ubus-cpp/ubus-event-receiver.h +++ b/src/lib/libubus-cpp/include/ubus-cpp/ubus-event-receiver.h @@ -28,7 +28,7 @@ #include #include -extern "C" { +extern "C" { #include } @@ -38,16 +38,16 @@ struct ubus_context; /*--------------------------------- CLASS ----------------------------------*/ -class UBusEventReceiver : public ubus_event_handler { +class UBusEventReceiver : public ubus_event_handler +{ + public: + UBusEventReceiver(void); + virtual ~UBusEventReceiver(void); -public: - UBusEventReceiver (void); - virtual ~UBusEventReceiver (void); + int register_event(struct ubus_context *a_ctx, const std::string &an_event); + int unregister_event(struct ubus_context *a_ctx); - int register_event (struct ubus_context *a_ctx, const std::string &an_event); - int unregister_event (struct ubus_context *a_ctx); - - virtual void handle_event (const char *a_type, const char *a_json_msg) = 0; + virtual void handle_event(const char *a_type, const char *a_json_msg) = 0; }; #endif /* _UBUS_EVENT_RECEIVER_H */ diff --git a/src/lib/libubus-cpp/include/ubus-cpp/ubus-event.h b/src/lib/libubus-cpp/include/ubus-cpp/ubus-event.h index 65af13c5..9bb09775 100644 --- a/src/lib/libubus-cpp/include/ubus-cpp/ubus-event.h +++ b/src/lib/libubus-cpp/include/ubus-cpp/ubus-event.h @@ -28,7 +28,7 @@ #include #include -extern "C" { +extern "C" { #include } @@ -39,18 +39,18 @@ struct ubus_event_handler; /*--------------------------------- CLASS ----------------------------------*/ -class UBusEvent { +class UBusEvent +{ + public: + UBusEvent(void); + virtual ~UBusEvent(void); -public: - UBusEvent (void); - virtual ~UBusEvent (void); + int listen(struct ubus_context *a_ctx, const std::string &an_event); + virtual void handle_event(const char *a_type, const char *a_json_msg); + static int send(const std::string &an_event, const std::string &a_data); - int listen (struct ubus_context *a_ctx, const std::string &an_event); - virtual void handle_event (const char *a_type, const char *a_json_msg); - static int send (const std::string &an_event, const std::string &a_data); - -private: - std::list m_listeners; + private: + std::list m_listeners; }; #endif /* _UBUS_EVENT_H */ diff --git a/src/lib/libubus-cpp/include/ubus-cpp/ubus-exec-receiver.h b/src/lib/libubus-cpp/include/ubus-cpp/ubus-exec-receiver.h index 8e7eb58c..24796d02 100644 --- a/src/lib/libubus-cpp/include/ubus-cpp/ubus-exec-receiver.h +++ b/src/lib/libubus-cpp/include/ubus-cpp/ubus-exec-receiver.h @@ -20,9 +20,8 @@ * @Date: 04/05/2017 */ -#ifndef _UBUS_EXEC_RECIVER_H -#define _UBUS_EXEC_RECIVER_H - +#ifndef _UBUS_EXEC_RECEIVER_H +#define _UBUS_EXEC_RECEIVER_H /*------------------------------- INCLUDES ----------------------------------*/ @@ -35,26 +34,26 @@ extern "C" { /*--------------------------------- CLASS ----------------------------------*/ -class UBusExecReceiver : public ubus_request { +class UBusExecReceiver : public ubus_request +{ + public: + UBusExecReceiver(void); + virtual ~UBusExecReceiver(void); -public: - UBusExecReceiver (void); - virtual ~UBusExecReceiver (void); + int abort(struct ubus_context *a_ctx); + int complete_request_async(struct ubus_context *a_ctx); - int abort (struct ubus_context *a_ctx); - int complete_request_async (struct ubus_context *a_ctx); + void add_data(std::string a_data); + const std::string &get_data(void); - void add_data (std::string a_data); - const std::string &get_data (void); - - void add_result (int a_result); - int get_result (void); - - virtual void complete (void) = 0; + void add_result(int a_result); + int get_result(void); -private: + virtual void complete(void) = 0; + + private: std::string m_data; int m_result; }; -#endif /* _UBUS_EXEC_RECIVER_H */ +#endif /* _UBUS_EXEC_RECEIVER_H */ diff --git a/src/lib/libubus-cpp/include/ubus-cpp/ubus-object.h b/src/lib/libubus-cpp/include/ubus-cpp/ubus-object.h index ceb7c4f3..7453aa94 100644 --- a/src/lib/libubus-cpp/include/ubus-cpp/ubus-object.h +++ b/src/lib/libubus-cpp/include/ubus-cpp/ubus-object.h @@ -30,21 +30,19 @@ /*----------------------------- Dependencies --------------------------------*/ - /*--------------------------------- CLASS ----------------------------------*/ -class UBusObject : public ubus_object { - - // Disable copy construction and copy assignement - UBusObject (const UBusObject&); - UBusObject &operator=(const UBusObject&); - -public: - UBusObject (ubus_object_type &anObjType, const char *AnObjName, int anObjID = 0, - const char *anObjPath = 0); +class UBusObject : public ubus_object +{ + // Disable copy construction and copy assignment + UBusObject(const UBusObject &); + UBusObject &operator=(const UBusObject &); + + public: + UBusObject(ubus_object_type &anObjType, const char *AnObjName, int anObjID = 0, + const char *anObjPath = 0); //SHOULD virtual ~UBusObject (void); - ~UBusObject (void); + ~UBusObject(void); }; - #endif /* _UBUS_OBJECT_H */ diff --git a/src/lib/libubus-cpp/include/ubus-cpp/uloop-timer.h b/src/lib/libubus-cpp/include/ubus-cpp/uloop-timer.h index 5d10ae49..fab05b43 100644 --- a/src/lib/libubus-cpp/include/ubus-cpp/uloop-timer.h +++ b/src/lib/libubus-cpp/include/ubus-cpp/uloop-timer.h @@ -38,7 +38,7 @@ extern "C" { class ULoopTimer : public uloop_timeout { - // Disable copy construction and copy assignement + // Disable copy construction and copy assignment ULoopTimer(const ULoopTimer &); ULoopTimer &operator=(const ULoopTimer &); diff --git a/src/lib/libubus-cpp/src/common.h b/src/lib/libubus-cpp/src/common.h index 91021a23..be024bcf 100644 --- a/src/lib/libubus-cpp/src/common.h +++ b/src/lib/libubus-cpp/src/common.h @@ -30,4 +30,4 @@ #define UNUSED_PARAMETER(x) (void)(x) #endif - #endif /* _UBUS_COMMON_H */ +#endif /* _UBUS_COMMON_H */ diff --git a/src/lib/libubus-cpp/src/ubus-call.cpp b/src/lib/libubus-cpp/src/ubus-call.cpp index d6e56bbf..d7cc55e7 100644 --- a/src/lib/libubus-cpp/src/ubus-call.cpp +++ b/src/lib/libubus-cpp/src/ubus-call.cpp @@ -26,7 +26,7 @@ extern "C" { #include -#include +#include } extern "C" { @@ -39,7 +39,7 @@ extern "C" { #include "ubus-cpp/ubus-call.h" -#define kDefaultTimeoutInSecond 5 +#define kDefaultTimeoutInSecond 5 // #define UBUS_PROFILE 1 /*! ---------------------------------------------------------------------------- @@ -47,15 +47,15 @@ extern "C" { * * @brief callback of result. */ -static void receive_call_result_data (struct ubus_request *a_req, int a_type, struct blob_attr *a_msg) +static void receive_call_result_data(struct ubus_request *a_req, int a_type, struct blob_attr *a_msg) { char *the_str; - UBusCall *a_caller = static_cast(a_req->priv); - + UBusCall *a_caller = static_cast(a_req->priv); + the_str = blobmsg_format_json(a_msg, true); - + a_caller->set_result(the_str); - + free(the_str); } @@ -64,19 +64,17 @@ static void receive_call_result_data (struct ubus_request *a_req, int a_type, st * * @brief Constructor of the UBus Call Command. */ -UBusCall::UBusCall (void): -m_timeout(kDefaultTimeoutInSecond) +UBusCall::UBusCall(void) : m_timeout(kDefaultTimeoutInSecond) { } - /*! ---------------------------------------------------------------------------- * @fn exec * * @brief execute a. */ -int UBusCall::exec (const std::string &a_path, const std::string &a_method, - const std::string &a_parameter, std::string &a_result) +int UBusCall::exec(const std::string &a_path, const std::string &a_method, + const std::string &a_parameter, std::string &a_result) { int the_ret = 0; #ifdef UBUS_PROFILE @@ -84,8 +82,9 @@ int UBusCall::exec (const std::string &a_path, const std::string &a_method, gettimeofday(&the_start_request, NULL); #endif the_ret = ubus_sync_exec(a_path.c_str(), a_method.c_str(), a_parameter.c_str(), receive_call_result_data, this); - - if (!m_data.empty()) { + + if (!m_data.empty()) + { a_result = m_data.c_str(); } @@ -99,27 +98,27 @@ int UBusCall::exec (const std::string &a_path, const std::string &a_method, /*! ---------------------------------------------------------------------------- * @fn exec-async * - * @brief Execute an UBus Method Asynchrously; + * @brief Execute an UBus Method Asynchronously; */ -int UBusCall::exec_async (struct ubus_context *a_ctx, uint32_t an_object, const std::string &a_method, const std::string &a_parameter, UBusExecReceiver *a_receiver) +int UBusCall::exec_async(struct ubus_context *a_ctx, uint32_t an_object, const std::string &a_method, const std::string &a_parameter, UBusExecReceiver *a_receiver) { int the_return = -1; - struct blob_buf the_parameter = { 0 }; - a_receiver->abort (a_ctx); + struct blob_buf the_parameter = {0}; + a_receiver->abort(a_ctx); - blob_buf_init (&the_parameter, 0); + blob_buf_init(&the_parameter, 0); if (!a_parameter.empty()) - blobmsg_add_json_from_string (&the_parameter, a_parameter.c_str()); - - if (!ubus_invoke_async (a_ctx, an_object, a_method.c_str(), the_parameter.head, a_receiver)) { - - a_receiver->complete_request_async (a_ctx); + blobmsg_add_json_from_string(&the_parameter, a_parameter.c_str()); + + if (!ubus_invoke_async(a_ctx, an_object, a_method.c_str(), the_parameter.head, a_receiver)) + { + a_receiver->complete_request_async(a_ctx); the_return = 0; } - - blob_buf_free (&the_parameter); - + + blob_buf_free(&the_parameter); + return the_return; } @@ -128,7 +127,7 @@ int UBusCall::exec_async (struct ubus_context *a_ctx, uint32_t an_object, const * * @brief Save the Result received by UBus. */ -int UBusCall::set_result (const std::string &a_result) +int UBusCall::set_result(const std::string &a_result) { m_data = a_result; return 0; diff --git a/src/lib/libubus-cpp/src/ubus-event-receiver.cpp b/src/lib/libubus-cpp/src/ubus-event-receiver.cpp index 5d04f58b..e68fc7e2 100644 --- a/src/lib/libubus-cpp/src/ubus-event-receiver.cpp +++ b/src/lib/libubus-cpp/src/ubus-event-receiver.cpp @@ -24,7 +24,7 @@ #include -extern "C" { +extern "C" { #include } @@ -34,64 +34,59 @@ extern "C" { /*--------------------------------- DEFINES ---------------------------------*/ - /*! ---------------------------------------------------------------------------- * @fn receive_event * * @brief callback called when the event arrive. */ -static void receive_event (struct ubus_context *a_ctx, struct ubus_event_handler *an_ev, - const char *a_type, struct blob_attr *a_msg) +static void receive_event(struct ubus_context *a_ctx, struct ubus_event_handler *an_ev, + const char *a_type, struct blob_attr *a_msg) { char *the_string; UBusEventReceiver *the_receiver = static_cast(an_ev); - the_string = blobmsg_format_json (a_msg, true); + the_string = blobmsg_format_json(a_msg, true); - the_receiver->handle_event (a_type, the_string); + the_receiver->handle_event(a_type, the_string); - free (the_string); + free(the_string); } - /*! ---------------------------------------------------------------------------- * @fn UBusEventReceiver * * @brief Constructor of the UBus Event Receiver */ -UBusEventReceiver::UBusEventReceiver (void) +UBusEventReceiver::UBusEventReceiver(void) { - obj = { 0 }; + obj = {0}; cb = receive_event; } - /*! ---------------------------------------------------------------------------- * @fn ~UBusEventReceiver * * @brief Destructor of of the UBus Event Receiver */ -UBusEventReceiver::~UBusEventReceiver (void) +UBusEventReceiver::~UBusEventReceiver(void) { } - /*! ---------------------------------------------------------------------------- * @fn register_event * * @brief register to an ubus event type. */ -int UBusEventReceiver::register_event (struct ubus_context *a_ctx, const std::string &an_event) +int UBusEventReceiver::register_event(struct ubus_context *a_ctx, const std::string &an_event) { - return ubus_register_event_handler (a_ctx, this, an_event.c_str());; + return ubus_register_event_handler(a_ctx, this, an_event.c_str()); } - /*! ---------------------------------------------------------------------------- * @fn unregister_event * * @brief un register to an ubus event type. */ -int UBusEventReceiver::unregister_event (struct ubus_context *a_ctx) +int UBusEventReceiver::unregister_event(struct ubus_context *a_ctx) { - return ubus_unregister_event_handler (a_ctx, this); + return ubus_unregister_event_handler(a_ctx, this); } diff --git a/src/lib/libubus-cpp/src/ubus-event.cpp b/src/lib/libubus-cpp/src/ubus-event.cpp index f51737d7..f852442f 100644 --- a/src/lib/libubus-cpp/src/ubus-event.cpp +++ b/src/lib/libubus-cpp/src/ubus-event.cpp @@ -13,7 +13,7 @@ #include #include -extern "C" { +extern "C" { #include #include "ubus-sync.h" } @@ -26,59 +26,55 @@ extern "C" { // #define UBUS_PROFILE 1 - -static void receive_event (struct ubus_context *a_ctx, struct ubus_event_handler *an_ev, - const char *a_type, struct blob_attr *a_msg) +static void receive_event(struct ubus_context *a_ctx, struct ubus_event_handler *an_ev, + const char *a_type, struct blob_attr *a_msg) { char *the_str; - UBusEvent *a_caller = static_cast(an_ev->priv); - + UBusEvent *a_caller = static_cast(an_ev->priv); + the_str = blobmsg_format_json(a_msg, true); - + a_caller->handle_event(a_type, the_str); - + free(the_str); } - /*! ---------------------------------------------------------------------------- * @fn UBusEvent * * @brief Constructor of the UBusEvent */ -UBusEvent::UBusEvent (void) +UBusEvent::UBusEvent(void) { } - /*! ---------------------------------------------------------------------------- * @fn ~UBusEvent * * @brief Destructor of the UBusEvent */ -UBusEvent::~UBusEvent (void) +UBusEvent::~UBusEvent(void) { - while (!m_listeners.empty()) { - + while (!m_listeners.empty()) + { delete *(m_listeners.begin()); m_listeners.erase(m_listeners.begin()); - } + } } - /*! ---------------------------------------------------------------------------- * @fn listen * * @brief Handle an UBUS Event. */ -int UBusEvent::listen (struct ubus_context *a_ctx, const std::string &an_event) +int UBusEvent::listen(struct ubus_context *a_ctx, const std::string &an_event) { //static struct ubus_event_handler theListener; //fprintf (stderr, "%s\n", __PRETTY_FUNCTION__); - + struct ubus_event_handler *the_evt_listener = new ubus_event_handler; - memset (the_evt_listener, 0, sizeof (struct ubus_event_handler)); + memset(the_evt_listener, 0, sizeof(struct ubus_event_handler)); the_evt_listener->cb = receive_event; the_evt_listener->priv = this; @@ -87,23 +83,21 @@ int UBusEvent::listen (struct ubus_context *a_ctx, const std::string &an_event) return ubus_register_event_handler(a_ctx, the_evt_listener, an_event.c_str()); } - /*! ---------------------------------------------------------------------------- * @fn handle_event * * @brief Handle an UBUS Event. */ -void UBusEvent::handle_event (const char *a_type, const char *a_json_msg) +void UBusEvent::handle_event(const char *a_type, const char *a_json_msg) { } - /*! ---------------------------------------------------------------------------- * @fn send * * @brief Send an UBus Method */ -int UBusEvent::send (const std::string &an_event, const std::string &a_data) +int UBusEvent::send(const std::string &an_event, const std::string &a_data) { int the_result; #ifdef UBUS_PROFILE @@ -115,7 +109,7 @@ int UBusEvent::send (const std::string &an_event, const std::string &a_data) #ifdef UBUS_PROFILE gettimeofday(&the_current_timeval, NULL); - printf ("ubus_event [%s] duree: %.0lf ms\n", an_event.c_str(), time_diff(the_start_request, the_current_timeval) / 1000); + printf("ubus_event [%s] duree: %.0lf ms\n", an_event.c_str(), time_diff(the_start_request, the_current_timeval) / 1000); #endif return the_result; diff --git a/src/lib/libubus-cpp/src/ubus-exec-receiver.cpp b/src/lib/libubus-cpp/src/ubus-exec-receiver.cpp index 46a8464f..53a0bb9e 100644 --- a/src/lib/libubus-cpp/src/ubus-exec-receiver.cpp +++ b/src/lib/libubus-cpp/src/ubus-exec-receiver.cpp @@ -20,55 +20,51 @@ * @Date: 04/05/2017 */ - /*-------------------------------- INCLUDES ---------------------------------*/ #include "ubus-cpp/ubus-exec-receiver.h" - /*! ---------------------------------------------------------------------------- * @fn handle_data_request * * @brief callback called when data arrive. */ -static void handle_data_request (struct ubus_request *a_req, int, struct blob_attr *a_msg) +static void handle_data_request(struct ubus_request *a_req, int, struct blob_attr *a_msg) { char *the_string; UBusExecReceiver *the_receiver = static_cast(a_req); //printf ("handle_data_request\n"); - the_string = blobmsg_format_json (a_msg, true); - the_receiver->add_data (the_string); + the_string = blobmsg_format_json(a_msg, true); + the_receiver->add_data(the_string); - free (the_string); + free(the_string); } - /*! ---------------------------------------------------------------------------- * @fn handle_complete_request * * @brief callback called when the request is complete. */ -static void handle_complete_request (struct ubus_request *a_req, int a_ret) +static void handle_complete_request(struct ubus_request *a_req, int a_ret) { UBusExecReceiver *the_receiver = static_cast(a_req); //printf ("handle_complete_request (%d)\n", a_ret); - - the_receiver->add_result (a_ret); - the_receiver->complete (); -} + the_receiver->add_result(a_ret); + the_receiver->complete(); +} /*! ---------------------------------------------------------------------------- * @fn UBusExecReceiver * * @brief Constructor of the Ubus Exec Receiver */ -UBusExecReceiver::UBusExecReceiver (void) +UBusExecReceiver::UBusExecReceiver(void) { - list = LIST_HEAD_INIT (list); + list = LIST_HEAD_INIT(list); - pending = { 0 }; + pending = {0}; status_code = 0; status_msg = 0; blocked = 0; @@ -89,85 +85,78 @@ UBusExecReceiver::UBusExecReceiver (void) m_result = -1; } - /*! ---------------------------------------------------------------------------- * @fn ~UBusExecReceiver * * @brief Destructor of the Ubus Exec Receiver */ -UBusExecReceiver::~UBusExecReceiver (void) +UBusExecReceiver::~UBusExecReceiver(void) { } - /*! ---------------------------------------------------------------------------- * @fn abort * * @brief abort the current exec command. */ -int UBusExecReceiver::abort (struct ubus_context *a_ctx) +int UBusExecReceiver::abort(struct ubus_context *a_ctx) { - ubus_abort_request (a_ctx, this); + ubus_abort_request(a_ctx, this); return 0; } - /*! ---------------------------------------------------------------------------- * @fn complete_request_async * * @brief launch the registered async request. */ -int UBusExecReceiver::complete_request_async (struct ubus_context *a_ctx) +int UBusExecReceiver::complete_request_async(struct ubus_context *a_ctx) { data_cb = handle_data_request; complete_cb = handle_complete_request; - ubus_complete_request_async (a_ctx, this); + ubus_complete_request_async(a_ctx, this); return 0; } - /*! ---------------------------------------------------------------------------- * @fn add_data * * @brief add data from the receiver. */ -void UBusExecReceiver::add_data (std::string a_data) +void UBusExecReceiver::add_data(std::string a_data) { m_data += a_data; } - /*! ---------------------------------------------------------------------------- * @fn get_data * * @brief return the data received from the command. */ -const std::string &UBusExecReceiver::get_data (void) +const std::string &UBusExecReceiver::get_data(void) { return m_data; } - /*! ---------------------------------------------------------------------------- * @fn get_data * * @brief save the result of the request. */ -void UBusExecReceiver::add_result (int a_result) +void UBusExecReceiver::add_result(int a_result) { m_result = a_result; } - /*! ---------------------------------------------------------------------------- * @fn get_result * * @brief return the result of the request. */ -int UBusExecReceiver::get_result (void) +int UBusExecReceiver::get_result(void) { return m_result; } diff --git a/src/lib/libubus-cpp/src/ubus-object.cpp b/src/lib/libubus-cpp/src/ubus-object.cpp index a5c00ff3..ffd3aa4b 100644 --- a/src/lib/libubus-cpp/src/ubus-object.cpp +++ b/src/lib/libubus-cpp/src/ubus-object.cpp @@ -22,7 +22,6 @@ * */ - /*------------------------------- INCLUDES ----------------------------------*/ #include "ubus-cpp/ubus-object.h" @@ -31,45 +30,42 @@ /*--------------------------------- DEFINES ---------------------------------*/ - - /*! ---------------------------------------------------------------------------- - * @fn awUBusObject + * @fn UBusObject * - * @brief Construct a new awUBusObject, the object type and methods is + * @brief Construct a new UBusObject, the object type and methods is * provided statically using the type Derived * - * @param anObjType object type, be carreful it should not be a temporary !!! + * @param anObjType object type, be careful it should not be a temporary !!! * @param AnObjName : the name of the object * @param anObjID : TO BE DEFINED * @param anObjPath : TO BE DEFINED * * @important : the parameter anObjType should not be a temporary !!! */ -UBusObject::UBusObject (ubus_object_type &anObjType, const char *AnObjName, int anObjID, - const char *anObjPath) +UBusObject::UBusObject(ubus_object_type &anObjType, const char *AnObjName, int anObjID, + const char *anObjPath) { - name = AnObjName ? strdup (AnObjName) : 0; + name = AnObjName ? strdup(AnObjName) : 0; id = anObjID; - path = anObjPath ? strdup (anObjPath) : 0; - + path = anObjPath ? strdup(anObjPath) : 0; + type = &anObjType; methods = anObjType.methods; n_methods = anObjType.n_methods; - - // nullify last fields + + // nullify last fields subscribe_cb = 0; has_subscribers = false; } - /*! ---------------------------------------------------------------------------- * @fn ~UBusObject * * @brief Destructor of the UBusObject */ -UBusObject::~UBusObject (void) +UBusObject::~UBusObject(void) { - free ((char*)name); - free ((char*)path); + free((char *)name); + free((char *)path); } diff --git a/src/lib/libubus-cpp/src/ubus-sync.c b/src/lib/libubus-cpp/src/ubus-sync.c index c5a82424..eb6d5d9b 100644 --- a/src/lib/libubus-cpp/src/ubus-sync.c +++ b/src/lib/libubus-cpp/src/ubus-sync.c @@ -44,8 +44,8 @@ #include "ubus-sync.h" - -struct ubus_sync_context { +struct ubus_sync_context +{ uint16_t request_seq; int fd; bool eof; @@ -56,23 +56,27 @@ struct ubus_sync_context { struct avl_tree objects; }; -#define STATIC_IOV(_var) { .iov_base = (char *) &(_var), .iov_len = sizeof(_var) } +#define STATIC_IOV(_var) \ + { \ + .iov_base = (char *)&(_var), .iov_len = sizeof(_var) \ + } struct blob_buf b = {}; static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = { - [UBUS_ATTR_STATUS] = { .type = BLOB_ATTR_INT32 }, - [UBUS_ATTR_OBJID] = { .type = BLOB_ATTR_INT32 }, - [UBUS_ATTR_OBJPATH] = { .type = BLOB_ATTR_STRING }, - [UBUS_ATTR_METHOD] = { .type = BLOB_ATTR_STRING }, - [UBUS_ATTR_ACTIVE] = { .type = BLOB_ATTR_INT8 }, - [UBUS_ATTR_NO_REPLY] = { .type = BLOB_ATTR_INT8 }, - [UBUS_ATTR_SUBSCRIBERS] = { .type = BLOB_ATTR_NESTED }, + [UBUS_ATTR_STATUS] = {.type = BLOB_ATTR_INT32}, + [UBUS_ATTR_OBJID] = {.type = BLOB_ATTR_INT32}, + [UBUS_ATTR_OBJPATH] = {.type = BLOB_ATTR_STRING}, + [UBUS_ATTR_METHOD] = {.type = BLOB_ATTR_STRING}, + [UBUS_ATTR_ACTIVE] = {.type = BLOB_ATTR_INT8}, + [UBUS_ATTR_NO_REPLY] = {.type = BLOB_ATTR_INT8}, + [UBUS_ATTR_SUBSCRIBERS] = {.type = BLOB_ATTR_NESTED}, }; static struct blob_attr *attrbuf[UBUS_ATTR_MAX]; -struct ubus_pending_data { +struct ubus_pending_data +{ struct list_head list; int type; struct blob_attr data[]; @@ -80,27 +84,26 @@ struct ubus_pending_data { /* --------------------------------------------------------------------------- */ -void aw_ubus_handle_data (struct ubus_sync_context *ctx, unsigned int events); -static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd); -static int recv_retry (int fd, struct iovec *iov, bool wait, int *recv_fd); -static void aw_ubus_set_req_status (struct ubus_request *req, int ret); -static void aw_ubus_process_req_data (struct ubus_request *req, struct ubus_msghdr_buf *buf); -static void aw_ubus_req_complete_cb (struct ubus_request *req); -static void req_data_cb (struct ubus_request *req, int type, struct blob_attr *data); +void aw_ubus_handle_data(struct ubus_sync_context *ctx, unsigned int events); +static bool aw_get_next_msg(struct ubus_sync_context *ctx, int *recv_fd); +static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd); +static void aw_ubus_set_req_status(struct ubus_request *req, int ret); +static void aw_ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr_buf *buf); +static void aw_ubus_req_complete_cb(struct ubus_request *req); +static void req_data_cb(struct ubus_request *req, int type, struct blob_attr *data); /* --------------------------------------------------------------------------- */ - -double time_diff(struct timeval x , struct timeval y) +double time_diff(struct timeval x, struct timeval y) { - double x_ms , y_ms , diff; + double x_ms, y_ms, diff; - x_ms = (double)x.tv_sec*1000000 + (double)x.tv_usec; - y_ms = (double)y.tv_sec*1000000 + (double)y.tv_usec; + x_ms = (double)x.tv_sec * 1000000 + (double)x.tv_usec; + y_ms = (double)y.tv_sec * 1000000 + (double)y.tv_usec; - diff = (double)y_ms - (double)x_ms; + diff = (double)y_ms - (double)x_ms; - return diff; + return diff; } /*! ---------------------------------------------------------------------------- @@ -108,12 +111,14 @@ double time_diff(struct timeval x , struct timeval y) * * @brief check if a row is eq or not. */ -int rows_eq (int *a, int *b) +int rows_eq(int *a, int *b) { int i; - for (i=0; i<16; i++) { - if (a[i] != b[i]) { + for (i = 0; i < 16; i++) + { + if (a[i] != b[i]) + { return 0; } } @@ -121,38 +126,45 @@ int rows_eq (int *a, int *b) return 1; } - /*! ---------------------------------------------------------------------------- * @fn dump_row * * @brief dump row */ -void dump_row (long a_count, int a_numinrow, int *a_chs) +void dump_row(long a_count, int a_numinrow, int *a_chs) { int i; printf("%08lX:", a_count - a_numinrow); - if (a_numinrow > 0) { - - for (i = 0; i < a_numinrow; i++) { - if (i == 8) { + if (a_numinrow > 0) + { + for (i = 0; i < a_numinrow; i++) + { + if (i == 8) + { printf(" :"); } printf(" %02X", a_chs[i]); - } + } - for (i = a_numinrow; i < 16; i++) { - if (i == 8) { + for (i = a_numinrow; i < 16; i++) + { + if (i == 8) + { printf(" :"); } printf(" "); } printf(" "); - for (i = 0; i < a_numinrow; i++) { - if (isprint(a_chs[i])) { + for (i = 0; i < a_numinrow; i++) + { + if (isprint(a_chs[i])) + { printf("%c", a_chs[i]); - } else { + } + else + { printf("."); } } @@ -160,40 +172,45 @@ void dump_row (long a_count, int a_numinrow, int *a_chs) printf("\n"); } - /*! ---------------------------------------------------------------------------- * @fn dump * * @brief dump on the console a memory block. */ -void dump (void const *a_buffer, size_t a_len) +void dump(void const *a_buffer, size_t a_len) { - unsigned char *the_buf = (unsigned char *) a_buffer; + unsigned char *the_buf = (unsigned char *)a_buffer; long the_count = 0; int the_numinrow = 0; int the_chs[16]; - int the_oldchs[16] = { 0 }; + int the_oldchs[16] = {0}; int the_showed_dots = 0; size_t i; - for (i = 0; i < a_len; i++) { + for (i = 0; i < a_len; i++) + { int the_ch = the_buf[i]; - if (the_numinrow == 16) { - + if (the_numinrow == 16) + { int j; - if (rows_eq(the_oldchs, the_chs)) { - if (!the_showed_dots) { + if (rows_eq(the_oldchs, the_chs)) + { + if (!the_showed_dots) + { the_showed_dots = 1; printf(" .. .. .. .. .. .. .. .. : .. .. .. .. .. .. .. ..\n"); } - } else { + } + else + { the_showed_dots = 0; dump_row(the_count, the_numinrow, the_chs); } - for (j=0; j<16; j++) { + for (j = 0; j < 16; j++) + { the_oldchs[j] = the_chs[j]; } @@ -206,14 +223,15 @@ void dump (void const *a_buffer, size_t a_len) dump_row(the_count, the_numinrow, the_chs); - if (the_numinrow != 0) { + if (the_numinrow != 0) + { printf("%08lX:\n", the_count); } } /* --------------------------------------------------------------------------- */ -struct blob_attr **aw_ubus_parse_msg (struct blob_attr *msg) +struct blob_attr **aw_ubus_parse_msg(struct blob_attr *msg) { int the_ret; // printf ("==> aw_ubus_parse_msg\n"); @@ -222,10 +240,9 @@ struct blob_attr **aw_ubus_parse_msg (struct blob_attr *msg) return attrbuf; } - /* --------------------------------------------------------------------------- */ -static void ubus_lookup_id_cb (struct ubus_request *req, int type, struct blob_attr *msg) +static void ubus_lookup_id_cb(struct ubus_request *req, int type, struct blob_attr *msg) { struct blob_attr **attr; uint32_t *id = req->priv; @@ -242,7 +259,7 @@ static void ubus_lookup_id_cb (struct ubus_request *req, int type, struct blob_a /* --------------------------------------------------------------------------- */ -static void aw_ubus_sync_req_cb (struct ubus_request *req, int ret) +static void aw_ubus_sync_req_cb(struct ubus_request *req, int ret) { // printf ("==> aw_ubus_sync_req_cb\n"); req->status_msg = true; @@ -250,12 +267,11 @@ static void aw_ubus_sync_req_cb (struct ubus_request *req, int ret) // uloop_end(); } - /* --------------------------------------------------------------------------- */ -static bool aw_ubus_validate_hdr (struct ubus_msghdr *hdr) +static bool aw_ubus_validate_hdr(struct ubus_msghdr *hdr) { - struct blob_attr *data = (struct blob_attr *) (hdr + 1); + struct blob_attr *data = (struct blob_attr *)(hdr + 1); // printf ("==> aw_ubus_validate_hdr\n"); if (hdr->version != 0) @@ -272,13 +288,14 @@ static bool aw_ubus_validate_hdr (struct ubus_msghdr *hdr) /* --------------------------------------------------------------------------- */ -static int ubus_find_notify_id (struct ubus_notify_request *n, uint32_t objid) +static int ubus_find_notify_id(struct ubus_notify_request *n, uint32_t objid) { uint32_t pending = n->pending; int i; // printf ("==> ubus_find_notify_id\n"); - for (i = 0; pending; i++, pending >>= 1) { + for (i = 0; pending; i++, pending >>= 1) + { if (!(pending & 1)) continue; @@ -291,20 +308,22 @@ static int ubus_find_notify_id (struct ubus_notify_request *n, uint32_t objid) /* --------------------------------------------------------------------------- */ -static struct ubus_request *ubus_find_request (struct ubus_sync_context *ctx, uint32_t seq, uint32_t peer, int *id) +static struct ubus_request *ubus_find_request(struct ubus_sync_context *ctx, uint32_t seq, uint32_t peer, int *id) { struct ubus_request *req; // printf ("==> ubus_find_request ctx: %p, seq: %d peer:%d\n", ctx, seq, peer); - list_for_each_entry(req, &ctx->requests, list) { + list_for_each_entry(req, &ctx->requests, list) + { // printf (". req = %p seq: %d next: %p peer: %d\n", req, req->seq, req->list.next, req->peer); struct ubus_notify_request *nreq; nreq = container_of(req, struct ubus_notify_request, req); - + if (seq != req->seq) continue; - if (req->notify) { + if (req->notify) + { if (!nreq->pending) continue; @@ -312,7 +331,8 @@ static struct ubus_request *ubus_find_request (struct ubus_sync_context *ctx, ui *id = ubus_find_notify_id(nreq, peer); if (*id < 0) continue; - } else if (peer != req->peer) + } + else if (peer != req->peer) continue; // printf ("<== ubus_find_request found: %p\n", req); @@ -324,7 +344,7 @@ static struct ubus_request *ubus_find_request (struct ubus_sync_context *ctx, ui /* --------------------------------------------------------------------------- */ -static bool aw_ubus_get_status (struct ubus_msghdr_buf *buf, int *ret) +static bool aw_ubus_get_status(struct ubus_msghdr_buf *buf, int *ret) { struct blob_attr **attrbuf = aw_ubus_parse_msg(buf->data); // printf ("==> aw_ubus_get_status\n"); @@ -338,7 +358,7 @@ static bool aw_ubus_get_status (struct ubus_msghdr_buf *buf, int *ret) /* --------------------------------------------------------------------------- */ -static void ubus_process_notify_status (struct ubus_request *req, int id, struct ubus_msghdr_buf *buf) +static void ubus_process_notify_status(struct ubus_request *req, int id, struct ubus_msghdr_buf *buf) { struct ubus_notify_request *nreq; struct blob_attr **tb; @@ -350,11 +370,14 @@ static void ubus_process_notify_status (struct ubus_request *req, int id, struct nreq = container_of(req, struct ubus_notify_request, req); nreq->pending &= ~(1 << id); - if (!id) { + if (!id) + { /* first id: ubusd's status message with a list of ids */ tb = aw_ubus_parse_msg(buf->data); - if (tb[UBUS_ATTR_SUBSCRIBERS]) { - blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem) { + if (tb[UBUS_ATTR_SUBSCRIBERS]) + { + blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem) + { if (!blob_check_type(blob_data(cur), blob_len(cur), BLOB_ATTR_INT32)) continue; @@ -366,7 +389,9 @@ static void ubus_process_notify_status (struct ubus_request *req, int id, struct break; } } - } else { + } + else + { aw_ubus_get_status(buf, &ret); if (nreq->status_cb) nreq->status_cb(nreq, id, ret); @@ -378,7 +403,7 @@ static void ubus_process_notify_status (struct ubus_request *req, int id, struct /* --------------------------------------------------------------------------- */ -static int ubus_process_req_status (struct ubus_request *req, struct ubus_msghdr_buf *buf) +static int ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr_buf *buf) { int ret = UBUS_STATUS_INVALID_ARGUMENT; // printf ("==> ubus_process_req_status\n"); @@ -392,20 +417,22 @@ static int ubus_process_req_status (struct ubus_request *req, struct ubus_msghdr /* --------------------------------------------------------------------------- */ -void ubus_process_req_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf, int fd) +void ubus_process_req_msg(struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf, int fd) { struct ubus_msghdr *hdr = &buf->hdr; struct ubus_request *req; int id = -1; // printf ("==> ubus_process_req_msg\n"); - switch(hdr->type) { + switch (hdr->type) + { case UBUS_MSG_STATUS: - // printf (" - type: UBUS_MSG_STATUS\n"); + // printf (" - type: UBUS_MSG_STATUS\n"); req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id); if (!req) break; - if (fd >= 0) { + if (fd >= 0) + { if (req->fd_cb) req->fd_cb(req, fd); else @@ -420,7 +447,7 @@ void ubus_process_req_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf break; case UBUS_MSG_DATA: - //printf (" - type: UBUS_MSG_DATA req (%p)\n", req); + //printf (" - type: UBUS_MSG_DATA req (%p)\n", req); req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id); if (req && (req->data_cb || req->raw_data_cb)) aw_ubus_process_req_data(req, buf); @@ -430,14 +457,15 @@ void ubus_process_req_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf /* --------------------------------------------------------------------------- */ -static void __ubus_process_req_data (struct ubus_request *req) +static void __ubus_process_req_data(struct ubus_request *req) { struct ubus_pending_data *data; // printf ("==> __ubus_process_req_data\n"); - while (!list_empty(&req->pending)) { + while (!list_empty(&req->pending)) + { data = list_first_entry(&req->pending, - struct ubus_pending_data, list); + struct ubus_pending_data, list); list_del(&data->list); if (!req->cancelled) req_data_cb(req, data->type, data->data); @@ -447,7 +475,7 @@ static void __ubus_process_req_data (struct ubus_request *req) /* --------------------------------------------------------------------------- */ -static void req_data_cb (struct ubus_request *req, int type, struct blob_attr *data) +static void req_data_cb(struct ubus_request *req, int type, struct blob_attr *data) { struct blob_attr **attr; // printf ("==> req_data_cb\n"); @@ -463,13 +491,14 @@ static void req_data_cb (struct ubus_request *req, int type, struct blob_attr *d /* --------------------------------------------------------------------------- */ -static void aw_ubus_process_req_data (struct ubus_request *req, struct ubus_msghdr_buf *buf) +static void aw_ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr_buf *buf) { struct ubus_pending_data *data; int len; // printf ("==> aw_ubus_process_req_data\n"); - if (!req->blocked) { + if (!req->blocked) + { req->blocked = true; req_data_cb(req, buf->hdr.type, buf->data); __ubus_process_req_data(req); @@ -493,10 +522,10 @@ static void aw_ubus_process_req_data (struct ubus_request *req, struct ubus_msgh /* --------------------------------------------------------------------------- */ -void ubus_process_obj_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf) +void ubus_process_obj_msg(struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf) { void (*cb)(struct ubus_sync_context *, struct ubus_msghdr *, - struct ubus_object *, struct blob_attr **); + struct ubus_object *, struct blob_attr **); struct ubus_msghdr *hdr = &buf->hdr; struct blob_attr **attrbuf; struct ubus_object *obj; @@ -510,31 +539,34 @@ void ubus_process_obj_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf objid = blob_get_u32(attrbuf[UBUS_ATTR_OBJID]); obj = avl_find_element(&ctx->objects, &objid, obj, avl); - switch (hdr->type) { + switch (hdr->type) + { case UBUS_MSG_INVOKE: - printf ("==> UBUS_MSG_INVOKE (TODO)\n"); + printf("==> UBUS_MSG_INVOKE (TODO)\n"); //cb = ubus_process_invoke; break; case UBUS_MSG_UNSUBSCRIBE: - printf ("==> UBUS_MSG_UNSUBSCRIBE (TODO)\n"); + printf("==> UBUS_MSG_UNSUBSCRIBE (TODO)\n"); //cb = ubus_process_unsubscribe; break; case UBUS_MSG_NOTIFY: - printf ("==> UBUS_MSG_NOTIFY (TODO)\n"); + printf("==> UBUS_MSG_NOTIFY (TODO)\n"); //cb = ubus_process_notify; break; default: return; } - if (buf == &ctx->msgbuf) { + if (buf == &ctx->msgbuf) + { prev_data = buf->data; buf->data = NULL; } //cb(ctx, hdr, obj, attrbuf); - if (prev_data) { + if (prev_data) + { if (buf->data) free(prev_data); else @@ -544,10 +576,11 @@ void ubus_process_obj_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf /* --------------------------------------------------------------------------- */ -void ubus_process_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf, int fd) +void ubus_process_msg(struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf, int fd) { // printf ("==> ubus_process_msg : %d\n", buf->hdr.type); - switch(buf->hdr.type) { + switch (buf->hdr.type) + { case UBUS_MSG_STATUS: case UBUS_MSG_DATA: ubus_process_req_msg(ctx, buf, fd); @@ -568,23 +601,24 @@ void ubus_process_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf *bu /* --------------------------------------------------------------------------- */ -static int64_t aw_get_time_msec (void) +static int64_t aw_get_time_msec(void) { struct timespec ts; int64_t val; clock_gettime(CLOCK_MONOTONIC, &ts); - val = (int64_t) ts.tv_sec * 1000LL; + val = (int64_t)ts.tv_sec * 1000LL; val += ts.tv_nsec / 1000000LL; return val; } /* --------------------------------------------------------------------------- */ -int aw_ubus_reconnect (struct ubus_sync_context *ctx, const char *path) +int aw_ubus_reconnect(struct ubus_sync_context *ctx, const char *path) { - // printf ("==> aw_ubus_reconnect\n"); - struct { + // printf ("==> aw_ubus_reconnect\n"); + struct + { struct ubus_msghdr hdr; struct blob_attr data; } hdr; @@ -628,9 +662,9 @@ int aw_ubus_reconnect (struct ubus_sync_context *ctx, const char *path) ret = UBUS_STATUS_OK; //fcntl(ctx->sock.fd, F_SETFL, fcntl(ctx->sock.fd, F_GETFL) | O_NONBLOCK | O_CLOEXEC); - // AWOX M2: Should add F_SETFD: - fcntl(ctx->fd, F_SETFL, fcntl(ctx->fd, F_GETFL) | O_NONBLOCK); - + // AWOX M2: Should add F_SETFD: + fcntl(ctx->fd, F_SETFL, fcntl(ctx->fd, F_GETFL) | O_NONBLOCK | O_CLOEXEC); + // ubus_refresh_state(ctx); out_free: @@ -644,9 +678,9 @@ out_close: /* --------------------------------------------------------------------------- */ -static int aw_ubus_connect (struct ubus_sync_context *ctx, const char *path) +static int aw_ubus_connect(struct ubus_sync_context *ctx, const char *path) { - // printf ("==> aw_ubus_connect ctx: %p\n", ctx); + // printf ("==> aw_ubus_connect ctx: %p\n", ctx); ctx->fd = -1; //ctx->sock.cb = ubus_handle_data; //ctx->connection_lost = ubus_default_connection_lost; @@ -660,7 +694,8 @@ static int aw_ubus_connect (struct ubus_sync_context *ctx, const char *path) INIT_LIST_HEAD(&ctx->requests); //INIT_LIST_HEAD(&ctx->pending); //avl_init(&ctx->objects, ubus_cmp_id, false, NULL); - if (aw_ubus_reconnect(ctx, path)) { + if (aw_ubus_reconnect(ctx, path)) + { free(ctx->msgbuf.data); return -1; } @@ -670,7 +705,7 @@ static int aw_ubus_connect (struct ubus_sync_context *ctx, const char *path) /* --------------------------------------------------------------------------- */ -struct ubus_sync_context *aw_new_ubus_connect (void) +struct ubus_sync_context *aw_new_ubus_connect(void) { struct ubus_sync_context *ctx; // printf ("==> aw_new_ubus_connect\n"); @@ -679,7 +714,8 @@ struct ubus_sync_context *aw_new_ubus_connect (void) if (!ctx) return NULL; - if (aw_ubus_connect(ctx, NULL)) { + if (aw_ubus_connect(ctx, NULL)) + { free(ctx); ctx = NULL; } @@ -689,7 +725,7 @@ struct ubus_sync_context *aw_new_ubus_connect (void) /* --------------------------------------------------------------------------- */ -void aw_ubus_free (struct ubus_sync_context *ctx) +void aw_ubus_free(struct ubus_sync_context *ctx) { // printf ("aw_ubus_free ctx: %p\n", ctx); blob_buf_free(&b); @@ -698,12 +734,11 @@ void aw_ubus_free (struct ubus_sync_context *ctx) free(ctx); } - /* --------------------------------------------------------------------------- */ -static void aw_wait_data (int fd, bool write) +static void aw_wait_data(int fd, bool write) { - struct pollfd pfd = { .fd = fd }; + struct pollfd pfd = {.fd = fd}; // printf ("==>aw_wait_data\n"); pfd.events = write ? POLLOUT : POLLIN; poll(&pfd, 1, -1); @@ -711,27 +746,28 @@ static void aw_wait_data (int fd, bool write) /* --------------------------------------------------------------------------- */ -void aw_ubus_poll_data (struct ubus_sync_context *ctx, int timeout) +void aw_ubus_poll_data(struct ubus_sync_context *ctx, int timeout) { - // printf ("==> aw_ubus_poll_data\n"); + // printf ("==> aw_ubus_poll_data\n"); struct pollfd pfd = { .fd = ctx->fd, .events = POLLIN | POLLERR, }; poll(&pfd, 1, timeout); - aw_ubus_handle_data (ctx, ULOOP_READ); + aw_ubus_handle_data(ctx, ULOOP_READ); } /* --------------------------------------------------------------------------- */ -void aw_ubus_handle_data (struct ubus_sync_context *ctx, unsigned int events) +void aw_ubus_handle_data(struct ubus_sync_context *ctx, unsigned int events) { - // printf ("==> aw_ubus_handle_data\n"); + // printf ("==> aw_ubus_handle_data\n"); // struct ubus_context *ctx = container_of(u, struct ubus_context, sock); int recv_fd = -1; - while (aw_get_next_msg(ctx, &recv_fd)) { + while (aw_get_next_msg(ctx, &recv_fd)) + { ubus_process_msg(ctx, &ctx->msgbuf, recv_fd); //if (uloop_cancelled) // break; @@ -743,7 +779,7 @@ void aw_ubus_handle_data (struct ubus_sync_context *ctx, unsigned int events) /* --------------------------------------------------------------------------- */ -static bool aw_alloc_msg_buf (struct ubus_sync_context *ctx, int len) +static bool aw_alloc_msg_buf(struct ubus_sync_context *ctx, int len) { void *ptr; int buf_len = ctx->msgbuf_data_len; @@ -779,9 +815,10 @@ static bool aw_alloc_msg_buf (struct ubus_sync_context *ctx, int len) /* --------------------------------------------------------------------------- */ -static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd) +static bool aw_get_next_msg(struct ubus_sync_context *ctx, int *recv_fd) { - struct { + struct + { struct ubus_msghdr hdr; struct blob_attr data; } hdrbuf; @@ -792,7 +829,8 @@ static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd) /* receive header + start attribute */ r = recv_retry(ctx->fd, &iov, false, recv_fd); - if (r <= 0) { + if (r <= 0) + { if (r < 0) ctx->eof = true; @@ -815,19 +853,19 @@ static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd) iov.iov_base = (char *)ctx->msgbuf.data + sizeof(hdrbuf.data); iov.iov_len = blob_len(ctx->msgbuf.data); if (iov.iov_len > 0 && - recv_retry(ctx->fd, &iov, true, NULL) <= 0) + recv_retry(ctx->fd, &iov, true, NULL) <= 0) return false; return true; } - /* --------------------------------------------------------------------------- */ -static int aw_writev_retry (int fd, struct iovec *iov, int iov_len, int sock_fd) +static int aw_writev_retry(int fd, struct iovec *iov, int iov_len, int sock_fd) { // printf ("==>aw_writev_retry\n"); - static struct { + static struct + { struct cmsghdr h; int fd; } fd_buf = { @@ -835,8 +873,7 @@ static int aw_writev_retry (int fd, struct iovec *iov, int iov_len, int sock_fd) .cmsg_len = sizeof(fd_buf), .cmsg_level = SOL_SOCKET, .cmsg_type = SCM_RIGHTS, - } - }; + }}; struct msghdr msghdr = { .msg_iov = iov, .msg_iovlen = iov_len, @@ -845,19 +882,25 @@ static int aw_writev_retry (int fd, struct iovec *iov, int iov_len, int sock_fd) }; int len = 0; - do { + do + { int cur_len; - if (sock_fd < 0) { + if (sock_fd < 0) + { msghdr.msg_control = NULL; msghdr.msg_controllen = 0; - } else { + } + else + { fd_buf.fd = sock_fd; } cur_len = sendmsg(fd, &msghdr, 0); - if (cur_len < 0) { - switch(errno) { + if (cur_len < 0) + { + switch (errno) + { case EAGAIN: aw_wait_data(fd, true); break; @@ -873,7 +916,8 @@ static int aw_writev_retry (int fd, struct iovec *iov, int iov_len, int sock_fd) sock_fd = -1; len += cur_len; - while (cur_len >= iov->iov_len) { + while (cur_len >= iov->iov_len) + { cur_len -= iov->iov_len; iov_len--; iov++; @@ -895,7 +939,8 @@ static int aw_writev_retry (int fd, struct iovec *iov, int iov_len, int sock_fd) static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd) { int bytes, total = 0; - static struct { + static struct + { struct cmsghdr h; int fd; } fd_buf = { @@ -910,14 +955,18 @@ static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd) .msg_iovlen = 1, }; - while (iov->iov_len > 0) { + while (iov->iov_len > 0) + { if (wait) aw_wait_data(fd, false); - if (recv_fd) { + if (recv_fd) + { msghdr.msg_control = &fd_buf; msghdr.msg_controllen = sizeof(fd_buf); - } else { + } + else + { msghdr.msg_control = NULL; msghdr.msg_controllen = 0; } @@ -927,7 +976,8 @@ static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd) if (!bytes) return -1; - if (bytes < 0) { + if (bytes < 0) + { bytes = 0; //if (uloop_cancelled) // return 0; @@ -956,13 +1006,12 @@ static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd) /* --------------------------------------------------------------------------- */ -int aw_ubus_send_msg (struct ubus_sync_context *ctx, uint32_t seq, - struct blob_attr *msg, int cmd, uint32_t peer, int fd) +int aw_ubus_send_msg(struct ubus_sync_context *ctx, uint32_t seq, + struct blob_attr *msg, int cmd, uint32_t peer, int fd) { struct ubus_msghdr hdr; struct iovec iov[2] = { - STATIC_IOV(hdr) - }; + STATIC_IOV(hdr)}; int ret; // printf ("==>aw_ubus_send_msg\n"); hdr.version = 0; @@ -970,12 +1019,13 @@ int aw_ubus_send_msg (struct ubus_sync_context *ctx, uint32_t seq, hdr.seq = cpu_to_be16(seq); hdr.peer = cpu_to_be32(peer); - if (!msg) { + if (!msg) + { blob_buf_init(&b, 0); msg = b.head; } - iov[1].iov_base = (char *) msg; + iov[1].iov_base = (char *)msg; iov[1].iov_len = blob_raw_len(msg); ret = aw_writev_retry(ctx->fd, iov, ARRAY_SIZE(iov), fd); @@ -990,7 +1040,7 @@ int aw_ubus_send_msg (struct ubus_sync_context *ctx, uint32_t seq, /* --------------------------------------------------------------------------- */ -void aw_ubus_complete_request_async (struct ubus_sync_context *ctx, struct ubus_request *req) +void aw_ubus_complete_request_async(struct ubus_sync_context *ctx, struct ubus_request *req) { // printf ("==> aw_ubus_complete_request_async...\n"); if (!list_empty(&req->list)) @@ -1001,7 +1051,7 @@ void aw_ubus_complete_request_async (struct ubus_sync_context *ctx, struct ubus_ /* --------------------------------------------------------------------------- */ -static void aw_ubus_req_complete_cb (struct ubus_request *req) +static void aw_ubus_req_complete_cb(struct ubus_request *req) { // printf ("==> aw_ubus_req_complete_cb\n"); ubus_complete_handler_t cb = req->complete_cb; @@ -1015,7 +1065,7 @@ static void aw_ubus_req_complete_cb (struct ubus_request *req) /* --------------------------------------------------------------------------- */ -static void aw_ubus_set_req_status (struct ubus_request *req, int ret) +static void aw_ubus_set_req_status(struct ubus_request *req, int ret) { // printf ("==> aw_ubus_set_req_status\n"); //if (!list_empty(&req->list)) @@ -1024,13 +1074,13 @@ static void aw_ubus_set_req_status (struct ubus_request *req, int ret) req->status_msg = true; req->status_code = ret; //if (!req->blocked) - aw_ubus_req_complete_cb(req); + aw_ubus_req_complete_cb(req); } /* --------------------------------------------------------------------------- */ -int aw_ubus_start_request (struct ubus_sync_context *ctx, struct ubus_request *req, - struct blob_attr *msg, int cmd, uint32_t peer) +int aw_ubus_start_request(struct ubus_sync_context *ctx, struct ubus_request *req, + struct blob_attr *msg, int cmd, uint32_t peer) { memset(req, 0, sizeof(*req)); // printf ("==> aw_ubus_start_request blob_pad_len(msg) %d\n", blob_pad_len(msg)); @@ -1049,15 +1099,15 @@ int aw_ubus_start_request (struct ubus_sync_context *ctx, struct ubus_request *r /* --------------------------------------------------------------------------- */ -int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request *req, - int req_timeout) +int aw_ubus_complete_request(struct ubus_sync_context *ctx, struct ubus_request *req, + int req_timeout) { ubus_complete_handler_t complete_cb = req->complete_cb; //bool registered = ctx->sock.registered; int status = UBUS_STATUS_NO_DATA; int64_t timeout = -1, time_end = 0; // printf ("==> aw_ubus_complete_request %p\n", req); -/* + /* if (!registered) { uloop_init(); ubus_add_uloop(ctx); @@ -1071,28 +1121,31 @@ int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request // ctx->stack_depth++; // printf ("wait response ....\n"); - while (!req->status_msg) { + while (!req->status_msg) + { bool cancelled = uloop_cancelled; uloop_cancelled = false; - if (req_timeout) { + if (req_timeout) + { timeout = time_end - aw_get_time_msec(); - if (timeout <= 0) { + if (timeout <= 0) + { aw_ubus_set_req_status(req, UBUS_STATUS_TIMEOUT); uloop_cancelled = cancelled; break; } } - aw_ubus_poll_data(ctx, (unsigned int) timeout); + aw_ubus_poll_data(ctx, (unsigned int)timeout); uloop_cancelled = cancelled; } -/* + /* ctx->stack_depth--; if (ctx->stack_depth) uloop_cancelled = true; */ - + if (req->status_msg) status = req->status_code; @@ -1101,7 +1154,7 @@ int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request if (req->complete_cb) req->complete_cb(req, status); -/* + /* if (!registered) { uloop_fd_delete(&ctx->sock); @@ -1114,13 +1167,13 @@ int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request /* --------------------------------------------------------------------------- */ -int aw_ubus_invoke_async (struct ubus_sync_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, struct ubus_request *req) +int aw_ubus_invoke_async(struct ubus_sync_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, struct ubus_request *req) { blob_buf_init(&b, 0); blob_put_int32(&b, UBUS_ATTR_OBJID, obj); blob_put_string(&b, UBUS_ATTR_METHOD, method); - // printf ("==> aw_ubus_invoke_async\n"); + // printf ("==> aw_ubus_invoke_async\n"); if (msg) blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg)); @@ -1132,7 +1185,7 @@ int aw_ubus_invoke_async (struct ubus_sync_context *ctx, uint32_t obj, const cha /* --------------------------------------------------------------------------- */ -int aw_ubus_lookup_id (struct ubus_sync_context *a_ctx, const char *a_path, uint32_t *an_id) +int aw_ubus_lookup_id(struct ubus_sync_context *a_ctx, const char *a_path, uint32_t *an_id) { struct ubus_request req; int the_ret; @@ -1159,8 +1212,8 @@ int aw_ubus_lookup_id (struct ubus_sync_context *a_ctx, const char *a_path, uint /* --------------------------------------------------------------------------- */ // ubus_data_handler_t cb, void *priv, -int aw_ubus_invoke (struct ubus_sync_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, ubus_data_handler_t cb, void *priv, int timeout) +int aw_ubus_invoke(struct ubus_sync_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, ubus_data_handler_t cb, void *priv, int timeout) { struct ubus_request req; int rc; @@ -1179,7 +1232,7 @@ int aw_ubus_invoke (struct ubus_sync_context *ctx, uint32_t obj, const char *met /* --------------------------------------------------------------------------- */ -int aw_ubus_send_event (struct ubus_sync_context *ctx, const char *id, struct blob_attr *data) +int aw_ubus_send_event(struct ubus_sync_context *ctx, const char *id, struct blob_attr *data) { struct ubus_request req; void *s; @@ -1200,71 +1253,72 @@ int aw_ubus_send_event (struct ubus_sync_context *ctx, const char *id, struct bl /* --------------------------------------------------------------------------- */ -int ubus_sync_exec (const char *a_path, const char *a_method, const char *a_parameter, ubus_data_handler_t cb, void *priv) +int ubus_sync_exec(const char *a_path, const char *a_method, const char *a_parameter, ubus_data_handler_t cb, void *priv) { uint32_t the_id; int the_ret; - - struct blob_buf the_buf = { 0 }; + + struct blob_buf the_buf = {0}; struct ubus_sync_context *the_ctx; - + blob_buf_init(&the_buf, 0); // printf ("==> ubus_exec: path:%s method:%s, parameter:%s\n", a_path, a_method, a_parameter); - if (strlen(a_parameter) != 0) { - if (!blobmsg_add_json_from_string (&the_buf, a_parameter)) { - - fprintf (stderr, "%s - Failed to parse message data\n", __PRETTY_FUNCTION__); + if (strlen(a_parameter) != 0) + { + if (!blobmsg_add_json_from_string(&the_buf, a_parameter)) + { + fprintf(stderr, "%s - Failed to parse message data\n", __PRETTY_FUNCTION__); return -1; } } - + the_ctx = aw_new_ubus_connect(); - the_ret = aw_ubus_lookup_id (the_ctx, a_path, &the_id); - if (the_ret) { - - fprintf (stderr, "%s - ubus_lookup_id error: '%d' [path: %s method: %s]\n", __PRETTY_FUNCTION__, the_ret, a_path, a_method); + the_ret = aw_ubus_lookup_id(the_ctx, a_path, &the_id); + if (the_ret) + { + fprintf(stderr, "%s - ubus_lookup_id error: '%d' [path: %s method: %s]\n", __PRETTY_FUNCTION__, the_ret, a_path, a_method); aw_ubus_free(the_ctx); - blob_buf_free (&the_buf); + blob_buf_free(&the_buf); return the_ret; } // printf ("====> ID ici: %d\n", the_id); - - the_ret = aw_ubus_invoke (the_ctx, the_id, a_method, the_buf.head, cb, priv, 5 * 1000); - + + the_ret = aw_ubus_invoke(the_ctx, the_id, a_method, the_buf.head, cb, priv, 5 * 1000); + aw_ubus_free(the_ctx); - blob_buf_free (&the_buf); + blob_buf_free(&the_buf); // printf ("<== ubus_exec:\n"); return the_ret; } /* --------------------------------------------------------------------------- */ -int ubus_sync_send_event (const char *an_event, const char *a_data) +int ubus_sync_send_event(const char *an_event, const char *a_data) { int the_ret = 0; - struct blob_buf the_buf = { 0 }; + struct blob_buf the_buf = {0}; struct ubus_sync_context *the_ctx; - + // printf("%s => (%s>\n", __PRETTY_FUNCTION__, a_data); - + the_ctx = aw_new_ubus_connect(); - - if (the_ctx == NULL) { - - fprintf (stderr ,"%s - Failed to create an ubus context.\n", __PRETTY_FUNCTION__); + + if (the_ctx == NULL) + { + fprintf(stderr, "%s - Failed to create an ubus context.\n", __PRETTY_FUNCTION__); return -1; } - + blob_buf_init(&the_buf, 0); - + blobmsg_add_json_from_string(&the_buf, a_data); - + aw_ubus_send_event(the_ctx, an_event, the_buf.head); - + blob_buf_free(&the_buf); aw_ubus_free(the_ctx); - + return the_ret; } diff --git a/src/lib/libubus-cpp/src/ubus-sync.h b/src/lib/libubus-cpp/src/ubus-sync.h index e6cd9a7f..cae61b97 100644 --- a/src/lib/libubus-cpp/src/ubus-sync.h +++ b/src/lib/libubus-cpp/src/ubus-sync.h @@ -29,9 +29,9 @@ #include // temporary for ubus_data_handler_t -double time_diff (struct timeval x , struct timeval y); +double time_diff(struct timeval x, struct timeval y); -int ubus_sync_exec (const char *a_path, const char* a_method, const char *a_parameter, ubus_data_handler_t cb, void *priv); -int ubus_sync_send_event (const char *an_event, const char *a_data); +int ubus_sync_exec(const char *a_path, const char *a_method, const char *a_parameter, ubus_data_handler_t cb, void *priv); +int ubus_sync_send_event(const char *an_event, const char *a_data); #endif /* _AW_UBUS_SYNC_H */