Update typo.

This commit is contained in:
jbnadal
2018-04-24 18:10:11 +02:00
parent 692bf86f68
commit b1b3f8742c
15 changed files with 802 additions and 708 deletions

View File

@@ -31,16 +31,18 @@ extern "C" {
#include <libubus.h>
}
namespace UBus
{
namespace UBus {
namespace detail {
namespace detail
{
/**
* simple POD vehicle for arrays
*/
template <typename T>
struct Array {
struct Array
{
T *ptr;
size_t count;
};
@@ -50,7 +52,8 @@ struct Array {
* @note : T should be a POD and each argument will be copied as is using memcpy
*/
template <typename T>
static inline Array<T> makeArray(const T& e0) {
static inline Array<T> makeArray(const T &e0)
{
Array<T> result;
result.count = 1;
result.ptr = new T[result.count]();
@@ -59,7 +62,8 @@ static inline Array<T> makeArray(const T& e0) {
}
template <typename T>
static inline Array<T> makeArray(const T& e0, const T& e1) {
static inline Array<T> makeArray(const T &e0, const T &e1)
{
Array<T> result;
result.count = 2;
result.ptr = new T[result.count]();
@@ -69,7 +73,8 @@ static inline Array<T> makeArray(const T& e0, const T& e1) {
}
template <typename T>
static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2) {
static inline Array<T> makeArray(const T &e0, const T &e1, const T &e2)
{
Array<T> result;
result.count = 3;
result.ptr = new T[result.count]();
@@ -81,7 +86,8 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2) {
template <typename T>
static inline Array<T> makeArray(const T &e0, const T &e1, const T &e2,
const T& e3) {
const T &e3)
{
Array<T> result;
result.count = 4;
result.ptr = new T[result.count]();
@@ -94,7 +100,8 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
template <typename T>
static inline Array<T> makeArray(const T &e0, const T &e1, const T &e2,
const T& e3, const T& e4) {
const T &e3, const T &e4)
{
Array<T> result;
result.count = 5;
result.ptr = new T[result.count]();
@@ -106,10 +113,10 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
return result;
}
template <typename T>
static inline Array<T> makeArray(const T &e0, const T &e1, const T &e2,
const T& e3, const T& e4, const T& e5) {
const T &e3, const T &e4, const T &e5)
{
Array<T> result;
result.count = 6;
result.ptr = new T[result.count]();
@@ -122,11 +129,11 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
return result;
}
template <typename T>
static inline Array<T> makeArray(const T &e0, const T &e1, const T &e2,
const T &e3, const T &e4, const T &e5,
const T& e6) {
const T &e6)
{
Array<T> result;
result.count = 7;
result.ptr = new T[result.count]();
@@ -140,11 +147,11 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
return result;
}
template <typename T>
static inline Array<T> 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 &e6, const T &e7)
{
Array<T> result;
result.count = 8;
result.ptr = new T[result.count]();
@@ -159,11 +166,11 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
return result;
}
template <typename T>
static inline Array<T> 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 &e6, const T &e7, const T &e8)
{
Array<T> result;
result.count = 9;
result.ptr = new T[result.count]();
@@ -183,7 +190,8 @@ template<typename T>
static inline Array<T> 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 &e9)
{
Array<T> result;
result.count = 10;
result.ptr = new T[result.count]();
@@ -204,7 +212,8 @@ template<typename T>
static inline Array<T> 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 &e9, const T &e10)
{
Array<T> result;
result.count = 11;
result.ptr = new T[result.count]();
@@ -226,7 +235,8 @@ template<typename T>
static inline Array<T> 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 &e9, const T &e10, const T &e11)
{
Array<T> result;
result.count = 12;
result.ptr = new T[result.count]();
@@ -250,7 +260,8 @@ static inline Array<T> 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 &e12)
{
Array<T> result;
result.count = 13;
result.ptr = new T[result.count]();
@@ -270,13 +281,13 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
return result;
}
template <typename T>
static inline Array<T> 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 &e12, const T &e13)
{
Array<T> result;
result.count = 14;
result.ptr = new T[result.count]();
@@ -302,7 +313,8 @@ static inline Array<T> 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 &e12, const T &e13, const T &e14)
{
Array<T> result;
result.count = 15;
result.ptr = new T[result.count]();
@@ -330,7 +342,8 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
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 &e15)
{
Array<T> result;
result.count = 16;
result.ptr = new T[result.count]();
@@ -359,7 +372,8 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
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 &e15, const T &e16)
{
Array<T> result;
result.count = 17;
result.ptr = new T[result.count]();
@@ -389,7 +403,8 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
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 &e15, const T &e16, const T &e17)
{
Array<T> result;
result.count = 18;
result.ptr = new T[result.count]();
@@ -421,7 +436,8 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
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 &e18)
{
Array<T> result;
result.count = 19;
result.ptr = new T[result.count]();
@@ -454,7 +470,8 @@ static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
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) {
const T &e18, const T &e19)
{
Array<T> result;
result.count = 20;
result.ptr = new T[result.count]();
@@ -481,11 +498,11 @@ static inline Array<T> 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) {
static inline char *copy_str(const char *str)
{
return str ? strdup(str) : 0;
}
@@ -493,13 +510,16 @@ static inline char* copy_str(const char* str) {
* generic function which copy an Array
*/
template <typename T>
static inline T* copy_array(const T* src, const size_t count, void(*copy_func)(T&, const T&)) {
if(count == 0 || src == 0) {
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) {
for (size_t i = 0; i < count; ++i)
{
copy_func(result[i], src[i]);
}
@@ -511,52 +531,63 @@ static inline T* copy_array(const T* src, const size_t count, void(*copy_func)(T
*/
template <typename T>
static inline void delete_array(T *target, const size_t count,
void(*delete_func)(T&)) {
if(count == 0 || target == 0) {
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) {
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,14 +598,16 @@ 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) {
static inline void delete_method(ubus_method &target)
{
free((char *)target.name);
delete_args((blobmsg_policy *)target.policy, target.n_policy);
}
@@ -582,75 +615,85 @@ static inline void delete_method(ubus_method& target) {
/**
* 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 {
class ObjectType : public ubus_object_type
{
public:
ObjectType(const char* name_, const detail::_Method& m0) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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));
}
@@ -658,7 +701,8 @@ public:
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 &m11)
{
Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11));
}
@@ -666,7 +710,8 @@ public:
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 &m11, const detail::_Method &m12)
{
Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12));
}
@@ -674,7 +719,8 @@ public:
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 &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));
}
@@ -684,7 +730,8 @@ public:
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 &m14)
{
Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12,
m13, m14));
}
@@ -694,7 +741,8 @@ public:
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 &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));
}
@@ -704,7 +752,8 @@ public:
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 &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));
}
@@ -715,7 +764,8 @@ public:
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 &m17)
{
Init(name_, detail::makeArray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12,
m13, m14, m15, m16, m17));
}
@@ -726,7 +776,8 @@ public:
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 &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));
}
@@ -737,35 +788,39 @@ public:
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) {
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<detail::_Method> m) {
ObjectType(const char *name_, detail::Array<detail::_Method> m)
{
Init(name_, m);
}
ObjectType(const ObjectType& other) {
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() {
~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));
@@ -773,7 +828,8 @@ public:
private:
// delegate constructor ...
void Init(const char* name_, detail::Array<detail::_Method> m) {
void Init(const char *name_, detail::Array<detail::_Method> 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;
@@ -800,7 +856,8 @@ 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<detail::Arg> args) {
detail::Array<detail::Arg> args)
{
detail::_Method result;
result.name = detail::copy_str(name);
result.handler = handler;
@@ -814,38 +871,44 @@ static inline detail::_Method Method(const char* name, ubus_handler_t handler,
* 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) {
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) {
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) {
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) {
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) {
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) {
const detail::Arg &arg4, const detail::Arg &arg5)
{
return Method(name, handler, detail::makeArray(arg0, arg1, arg2, arg3, arg4, arg5));
}
@@ -853,75 +916,83 @@ 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 &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) {
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) {
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
/**
@@ -936,8 +1007,7 @@ static inline detail::Arg BoolArg(const char* name) {
* int(struct ubus_context *ctx, struct ubus_request_data *req, struct blob_attr *msg)
*/
template <typename ObjectType,
int (ObjectType::*Method)(struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
>
int (ObjectType::*Method)(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)>
static int ubus_hook(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)

View File

@@ -38,8 +38,8 @@ struct ubus_context;
/*--------------------------------- CLASS ----------------------------------*/
class UBusEventReceiver : public ubus_event_handler {
class UBusEventReceiver : public ubus_event_handler
{
public:
UBusEventReceiver(void);
virtual ~UBusEventReceiver(void);

View File

@@ -39,8 +39,8 @@ struct ubus_event_handler;
/*--------------------------------- CLASS ----------------------------------*/
class UBusEvent {
class UBusEvent
{
public:
UBusEvent(void);
virtual ~UBusEvent(void);

View File

@@ -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,8 +34,8 @@ extern "C" {
/*--------------------------------- CLASS ----------------------------------*/
class UBusExecReceiver : public ubus_request {
class UBusExecReceiver : public ubus_request
{
public:
UBusExecReceiver(void);
virtual ~UBusExecReceiver(void);
@@ -57,4 +56,4 @@ private:
int m_result;
};
#endif /* _UBUS_EXEC_RECIVER_H */
#endif /* _UBUS_EXEC_RECEIVER_H */

View File

@@ -30,12 +30,11 @@
/*----------------------------- Dependencies --------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class UBusObject : public ubus_object {
// Disable copy construction and copy assignement
class UBusObject : public ubus_object
{
// Disable copy construction and copy assignment
UBusObject(const UBusObject &);
UBusObject &operator=(const UBusObject &);
@@ -46,5 +45,4 @@ public:
~UBusObject(void);
};
#endif /* _UBUS_OBJECT_H */

View File

@@ -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 &);

View File

@@ -64,12 +64,10 @@ 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
*
@@ -85,7 +83,8 @@ int UBusCall::exec (const std::string &a_path, const std::string &a_method,
#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,7 +98,7 @@ 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)
{
@@ -112,8 +111,8 @@ int UBusCall::exec_async (struct ubus_context *a_ctx, uint32_t an_object, const
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)) {
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;
}

View File

@@ -34,7 +34,6 @@ extern "C" {
/*--------------------------------- DEFINES ---------------------------------*/
/*! ----------------------------------------------------------------------------
* @fn receive_event
*
@@ -52,7 +51,6 @@ static void receive_event (struct ubus_context *a_ctx, struct ubus_event_handler
free(the_string);
}
/*! ----------------------------------------------------------------------------
* @fn UBusEventReceiver
*
@@ -64,7 +62,6 @@ UBusEventReceiver::UBusEventReceiver (void)
cb = receive_event;
}
/*! ----------------------------------------------------------------------------
* @fn ~UBusEventReceiver
*
@@ -74,7 +71,6 @@ UBusEventReceiver::~UBusEventReceiver (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn register_event
*
@@ -82,10 +78,9 @@ UBusEventReceiver::~UBusEventReceiver (void)
*/
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
*

View File

@@ -26,7 +26,6 @@ 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)
{
@@ -40,7 +39,6 @@ static void receive_event (struct ubus_context *a_ctx, struct ubus_event_handler
free(the_str);
}
/*! ----------------------------------------------------------------------------
* @fn UBusEvent
*
@@ -50,7 +48,6 @@ UBusEvent::UBusEvent (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~UBusEvent
*
@@ -58,14 +55,13 @@ 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
*
@@ -87,7 +83,6 @@ 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
*
@@ -97,7 +92,6 @@ void UBusEvent::handle_event (const char *a_type, const char *a_json_msg)
{
}
/*! ----------------------------------------------------------------------------
* @fn send
*

View File

@@ -20,12 +20,10 @@
* @Date: 04/05/2017
*/
/*-------------------------------- INCLUDES ---------------------------------*/
#include "ubus-cpp/ubus-exec-receiver.h"
/*! ----------------------------------------------------------------------------
* @fn handle_data_request
*
@@ -43,7 +41,6 @@ static void handle_data_request (struct ubus_request *a_req, int, struct blob_at
free(the_string);
}
/*! ----------------------------------------------------------------------------
* @fn handle_complete_request
*
@@ -58,7 +55,6 @@ static void handle_complete_request (struct ubus_request *a_req, int a_ret)
the_receiver->complete();
}
/*! ----------------------------------------------------------------------------
* @fn UBusExecReceiver
*
@@ -89,7 +85,6 @@ UBusExecReceiver::UBusExecReceiver (void)
m_result = -1;
}
/*! ----------------------------------------------------------------------------
* @fn ~UBusExecReceiver
*
@@ -99,7 +94,6 @@ UBusExecReceiver::~UBusExecReceiver (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn abort
*
@@ -112,7 +106,6 @@ int UBusExecReceiver::abort (struct ubus_context *a_ctx)
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn complete_request_async
*
@@ -128,7 +121,6 @@ int UBusExecReceiver::complete_request_async (struct ubus_context *a_ctx)
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn add_data
*
@@ -139,7 +131,6 @@ void UBusExecReceiver::add_data (std::string a_data)
m_data += a_data;
}
/*! ----------------------------------------------------------------------------
* @fn get_data
*
@@ -150,7 +141,6 @@ const std::string &UBusExecReceiver::get_data (void)
return m_data;
}
/*! ----------------------------------------------------------------------------
* @fn get_data
*
@@ -161,7 +151,6 @@ void UBusExecReceiver::add_result (int a_result)
m_result = a_result;
}
/*! ----------------------------------------------------------------------------
* @fn get_result
*

View File

@@ -22,7 +22,6 @@
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include "ubus-cpp/ubus-object.h"
@@ -31,15 +30,13 @@
/*--------------------------------- 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
@@ -62,7 +59,6 @@ UBusObject::UBusObject (ubus_object_type &anObjType, const char *AnObjName, int
has_subscribers = false;
}
/*! ----------------------------------------------------------------------------
* @fn ~UBusObject
*

View File

@@ -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,7 +56,10 @@ 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 = {};
@@ -72,7 +75,8 @@ static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = {
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[];
@@ -90,7 +94,6 @@ static void req_data_cb (struct ubus_request *req, int type, struct blob_attr *d
/* --------------------------------------------------------------------------- */
double time_diff(struct timeval x, struct timeval y)
{
double x_ms, y_ms, diff;
@@ -112,8 +115,10 @@ 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,7 +126,6 @@ int rows_eq (int *a, int *b)
return 1;
}
/*! ----------------------------------------------------------------------------
* @fn dump_row
*
@@ -133,26 +137,34 @@ void dump_row (long a_count, int a_numinrow, int *a_chs)
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,7 +172,6 @@ void dump_row (long a_count, int a_numinrow, int *a_chs)
printf("\n");
}
/*! ----------------------------------------------------------------------------
* @fn dump
*
@@ -176,24 +187,30 @@ void dump (void const *a_buffer, size_t a_len)
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,7 +223,8 @@ 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);
}
}
@@ -222,7 +240,6 @@ 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)
@@ -250,7 +267,6 @@ 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)
@@ -278,7 +294,8 @@ static int ubus_find_notify_id (struct ubus_notify_request *n, uint32_t objid)
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;
@@ -296,7 +313,8 @@ static struct ubus_request *ubus_find_request (struct ubus_sync_context *ctx, ui
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);
@@ -304,7 +322,8 @@ static struct ubus_request *ubus_find_request (struct ubus_sync_context *ctx, ui
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);
@@ -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);
@@ -398,14 +423,16 @@ void ubus_process_req_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf
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");
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
@@ -435,7 +462,8 @@ 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);
list_del(&data->list);
@@ -469,7 +497,8 @@ static void aw_ubus_process_req_data (struct ubus_request *req, struct ubus_msgh
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);
@@ -510,7 +539,8 @@ 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");
//cb = ubus_process_invoke;
@@ -527,14 +557,16 @@ void ubus_process_obj_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf
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
@@ -547,7 +579,8 @@ 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)
{
// 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);
@@ -584,7 +617,8 @@ static int64_t aw_get_time_msec (void)
int aw_ubus_reconnect(struct ubus_sync_context *ctx, const char *path)
{
// printf ("==> aw_ubus_reconnect\n");
struct {
struct
{
struct ubus_msghdr hdr;
struct blob_attr data;
} hdr;
@@ -629,7 +663,7 @@ 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);
fcntl(ctx->fd, F_SETFL, fcntl(ctx->fd, F_GETFL) | O_NONBLOCK | O_CLOEXEC);
// ubus_refresh_state(ctx);
@@ -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;
}
@@ -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;
}
@@ -698,7 +734,6 @@ void aw_ubus_free (struct ubus_sync_context *ctx)
free(ctx);
}
/* --------------------------------------------------------------------------- */
static void aw_wait_data(int fd, bool write)
@@ -731,7 +766,8 @@ void aw_ubus_handle_data (struct ubus_sync_context *ctx, unsigned int events)
// 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;
@@ -781,7 +817,8 @@ 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)
{
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;
@@ -821,13 +859,13 @@ static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd)
return true;
}
/* --------------------------------------------------------------------------- */
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;
@@ -961,8 +1011,7 @@ int aw_ubus_send_msg (struct ubus_sync_context *ctx, uint32_t seq,
{
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,7 +1019,8 @@ 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;
}
@@ -1071,13 +1121,16 @@ 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;
@@ -1210,9 +1263,10 @@ int ubus_sync_exec (const char *a_path, const char *a_method, const char *a_par
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)) {
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;
}
@@ -1221,8 +1275,8 @@ int ubus_sync_exec (const char *a_path, const char *a_method, const char *a_par
the_ctx = aw_new_ubus_connect();
the_ret = aw_ubus_lookup_id(the_ctx, a_path, &the_id);
if (the_ret) {
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);
@@ -1250,8 +1304,8 @@ int ubus_sync_send_event (const char *an_event, const char *a_data)
the_ctx = aw_new_ubus_connect();
if (the_ctx == NULL) {
if (the_ctx == NULL)
{
fprintf(stderr, "%s - Failed to create an ubus context.\n", __PRETTY_FUNCTION__);
return -1;
}