backport ubuscpp, chacond, and sprinklersd

This commit is contained in:
2017-04-21 22:48:42 +02:00
parent ad868bda8e
commit 3201fb4735
27 changed files with 0 additions and 0 deletions

View File

@@ -1,28 +0,0 @@
cmake_minimum_required(VERSION 2.8.11)
include (libubus)
include (libubox)
include (libubuscpp)
project (libubuscpp)
file(
GLOB_RECURSE
source_files
../../src/UBusCall.cpp
../../src/UBusObject.cpp
../../src/UBusTimer.cpp
)
add_library(
ubuscpp
SHARED
${source_files}
)
target_link_libraries (ubuscpp
LINK_PUBLIC
ubus
)
target_include_directories (ubuscpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -1,52 +0,0 @@
/*!
* UbusCall.h
*
* Copyright (c) 2015, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 21/03/2015
*
*/
#ifndef _UBUS_CALL_H
#define _UBUS_CALL_H
/*-------------------------------- INCLUDES ---------------------------------*/
#include <string>
/*---------------------------------- CLASS ----------------------------------*/
class UBusCall
{
public:
UBusCall (void);
int Exec (const std::string &aPath, const std::string &aMethod,
const std::string &aParameter, std::string &aResult);
int SetTimeout (int aTimeout);
int SetResult (const std::string &aResult);
private:
int mTimeout;
std::string mData;
};
#endif /* _UBUS_CALL_H */

View File

@@ -1,957 +0,0 @@
/*!
* UbusCall.h
*
* Copyright (c) 2015, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 21/03/2015
*
*/
#ifndef _UBUS_CPP_H
#define _UBUS_CPP_H
/*------------------------------- INCLUDES ----------------------------------*/
extern "C" {
#include <ubus/libubus.h>
}
namespace UBus {
namespace detail {
/**
* simple POD vehicle for arrays
*/
template<typename T>
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<typename T>
static inline Array<T> makeArray(const T& e0) {
Array<T> result;
result.count = 1;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
return result;
}
template<typename T>
static inline Array<T> makeArray(const T& e0, const T& e1) {
Array<T> result;
result.count = 2;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
return result;
}
template<typename T>
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]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
return result;
}
template<typename T>
static inline Array<T> makeArray(const T& e0, const T& e1, const T& e2,
const T& e3) {
Array<T> result;
result.count = 4;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
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) {
Array<T> result;
result.count = 5;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
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) {
Array<T> result;
result.count = 6;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
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) {
Array<T> result;
result.count = 7;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
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) {
Array<T> result;
result.count = 8;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
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) {
Array<T> result;
result.count = 9;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
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) {
Array<T> result;
result.count = 10;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
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) {
Array<T> result;
result.count = 11;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
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) {
Array<T> result;
result.count = 12;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
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) {
Array<T> result;
result.count = 13;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
memcpy(&result.ptr[12], &e12, sizeof(T));
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) {
Array<T> result;
result.count = 14;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
memcpy(&result.ptr[12], &e12, sizeof(T));
memcpy(&result.ptr[13], &e13, sizeof(T));
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& e14) {
Array<T> result;
result.count = 15;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
memcpy(&result.ptr[12], &e12, sizeof(T));
memcpy(&result.ptr[13], &e13, sizeof(T));
memcpy(&result.ptr[14], &e14, sizeof(T));
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& e14,
const T& e15) {
Array<T> result;
result.count = 16;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
memcpy(&result.ptr[12], &e12, sizeof(T));
memcpy(&result.ptr[13], &e13, sizeof(T));
memcpy(&result.ptr[14], &e14, sizeof(T));
memcpy(&result.ptr[15], &e15, sizeof(T));
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& e14,
const T& e15, const T& e16) {
Array<T> result;
result.count = 17;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
memcpy(&result.ptr[12], &e12, sizeof(T));
memcpy(&result.ptr[13], &e13, sizeof(T));
memcpy(&result.ptr[14], &e14, sizeof(T));
memcpy(&result.ptr[15], &e15, sizeof(T));
memcpy(&result.ptr[16], &e16, sizeof(T));
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& e14,
const T& e15, const T& e16, const T& e17) {
Array<T> result;
result.count = 18;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
memcpy(&result.ptr[12], &e12, sizeof(T));
memcpy(&result.ptr[13], &e13, sizeof(T));
memcpy(&result.ptr[14], &e14, sizeof(T));
memcpy(&result.ptr[15], &e15, sizeof(T));
memcpy(&result.ptr[16], &e16, sizeof(T));
memcpy(&result.ptr[17], &e17, sizeof(T));
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& e14,
const T& e15, const T& e16, const T& e17,
const T& e18) {
Array<T> result;
result.count = 19;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
memcpy(&result.ptr[12], &e12, sizeof(T));
memcpy(&result.ptr[13], &e13, sizeof(T));
memcpy(&result.ptr[14], &e14, sizeof(T));
memcpy(&result.ptr[15], &e15, sizeof(T));
memcpy(&result.ptr[16], &e16, sizeof(T));
memcpy(&result.ptr[17], &e17, sizeof(T));
memcpy(&result.ptr[18], &e18, sizeof(T));
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& e14,
const T& e15, const T& e16, const T& e17,
const T& e18, const T& e19) {
Array<T> result;
result.count = 20;
result.ptr = new T[result.count]();
memcpy(&result.ptr[0], &e0, sizeof(T));
memcpy(&result.ptr[1], &e1, sizeof(T));
memcpy(&result.ptr[2], &e2, sizeof(T));
memcpy(&result.ptr[3], &e3, sizeof(T));
memcpy(&result.ptr[4], &e4, sizeof(T));
memcpy(&result.ptr[5], &e5, sizeof(T));
memcpy(&result.ptr[6], &e6, sizeof(T));
memcpy(&result.ptr[7], &e7, sizeof(T));
memcpy(&result.ptr[8], &e8, sizeof(T));
memcpy(&result.ptr[9], &e9, sizeof(T));
memcpy(&result.ptr[10], &e10, sizeof(T));
memcpy(&result.ptr[11], &e11, sizeof(T));
memcpy(&result.ptr[12], &e12, sizeof(T));
memcpy(&result.ptr[13], &e13, sizeof(T));
memcpy(&result.ptr[14], &e14, sizeof(T));
memcpy(&result.ptr[15], &e15, sizeof(T));
memcpy(&result.ptr[16], &e16, sizeof(T));
memcpy(&result.ptr[17], &e17, sizeof(T));
memcpy(&result.ptr[18], &e18, sizeof(T));
memcpy(&result.ptr[19], &e19, sizeof(T));
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;
}
/**
* 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) {
return 0;
}
T* result = new T[count];
for(size_t i = 0; i < count; ++i) {
copy_func(result[i], src[i]);
}
return result;
}
/**
* generic function which delete an array
*/
template<typename T>
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) {
delete_func(target[i]);
}
delete[] target;
}
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) {
dest.name = copy_str(src.name);
dest.type = src.type;
}
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_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 { };
/**
* copy a Method
* @important : does not delete the prpevious content !!!
*/
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;
dest.policy = copy_args(src.policy, src.n_policy);
dest.n_policy = src.n_policy;
}
/**
* copy an array of Method
*/
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);
}
/**
* delete an array of Method
*/
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) {
Init(name_, detail::makeArray(m0));
}
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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,
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, 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, 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_, detail::Array<detail::_Method> 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);
n_methods = other.n_methods;
}
~ObjectType() {
free((char*)name);
detail::delete_methods((ubus_method*) methods, n_methods);
}
ObjectType& operator=(ObjectType other) {
Swap(other);
return *this;
}
void Swap(ObjectType& other) {
ubus_object_type tmp = other;
memcpy(&other, this, sizeof(*this));
memcpy(this, &tmp, sizeof(*this));
}
private:
// delegate constructor ...
void Init(const char* name_, detail::Array<detail::_Method> m) {
name = detail::copy_str(name_);
id = 0;
methods = m.ptr;
n_methods = m.count;
}
};
/**
* generate an ubus_method without arg
*/
static inline detail::_Method Method(const char* name, ubus_handler_t handler) {
detail::_Method result;
result.name = detail::copy_str(name);
result.handler = handler;
result.mask = 0;
result.policy = 0;
result.n_policy = 0;
return result;
}
/**
* 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::_Method result;
result.name = detail::copy_str(name);
result.handler = handler;
result.mask = 0;
result.policy = args.ptr;
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
detail::Arg res;
res.name = detail::copy_str(name);
res.type = type;
return res;
}
static inline detail::Arg UnspecArg(const char* name) {
return Arg(name, BLOBMSG_TYPE_UNSPEC);
}
static inline detail::Arg ArrayArg(const char* name) {
return Arg(name, BLOBMSG_TYPE_ARRAY);
}
static inline detail::Arg TableArg(const char* name) {
return Arg(name, BLOBMSG_TYPE_TABLE);
}
static inline detail::Arg StringArg(const char* name) {
return Arg(name, BLOBMSG_TYPE_STRING);
}
static inline detail::Arg Int64Arg(const char* name) {
return Arg(name, BLOBMSG_TYPE_INT64);
}
static inline detail::Arg Int32Arg(const char* name) {
return Arg(name, BLOBMSG_TYPE_INT32);
}
static inline detail::Arg Int16Arg(const char* name) {
return Arg(name, BLOBMSG_TYPE_INT16);
}
static inline detail::Arg Int8Arg(const char* name) {
return Arg(name, BLOBMSG_TYPE_INT8);
}
static inline detail::Arg BoolArg(const char* name) {
return Arg(name, BLOBMSG_TYPE_BOOL);
}
} // namespace UBus
/**
* Generate a function which dispatch a ubus method call to the appropriate
* method of a aw_ubus_object.
*
* This template generate a function compatible with ubus_handler
*
* @tparam ObjectType : the type of the object containing the method to call
* @tparam Method : the member function of ObjectType to call, this member function
* has the signature :
* 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*)
>
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<ObjectType*>(obj)->*Method)(ctx, req, msg);
}
/**
* Declare a ubus trampoline function which map call the right method of an ubus object
* @param CLASS : class name of the instance object targeted by the trampoline
* @param METHOD : method name targeted by the trampoline
* @return a ubus_handler_t
*/
#define UBUS_CPP(CLASS, METHOD) &ubus_hook<CLASS, &CLASS::METHOD>
#endif /* _UBUS_CPP_H */

View File

@@ -1,51 +0,0 @@
/*!
* UbusCall.h
*
* Copyright (c) 2015, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 21/03/2015
*
*/
#ifndef _UBUS_OBJECT_H
#define _UBUS_OBJECT_H
/*------------------------------- INCLUDES ----------------------------------*/
#include "ubuscpp/UBusCpp.h"
/*----------------------------- 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);
virtual ~UBusObject (void);
};
#endif /* _UBUS_OBJECT_H */

View File

@@ -1,61 +0,0 @@
/*!
* UbusTimer.h
*
* Copyright (c) 2016, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 17/05/2016
*
*/
#ifndef _UBUS_TIMER_H
#define _UBUS_TIMER_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
extern "C" {
#include <libubox/uloop.h>
}
/*----------------------------- Dependencies --------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class UBusTimer : public uloop_timeout {
// Disable copy construction and copy assignement
UBusTimer (const UBusTimer&);
UBusTimer &operator=(const UBusTimer&);
public:
UBusTimer (void);
virtual ~UBusTimer (void);
virtual int Expire (void);
int Start (unsigned int aTimerValue, bool aRepeat = false);
int Tick (void);
private:
bool mRepeat;
uint16_t mTimerValue;
};
#endif /* _UBUS_TIMER_H */

View File

@@ -1,133 +0,0 @@
/*!
* UbusCall.cpp
*
* Copyright (c) 2015, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 21/03/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
extern "C" {
#include <libubus.h>
#include <libubox/blobmsg_json.h>
}
#include "common.h"
#include "ubuscpp/UBusCall.h"
#define kDefaultTimeoutInSecond 5
static void receive_call_result_data (struct ubus_request *aReq, int aType, struct blob_attr *aMsg);
/*! ----------------------------------------------------------------------------
* @fn UBusCall
*
* @brief Constructor of the UBus Handler.
*/
UBusCall::UBusCall (void):
mTimeout (kDefaultTimeoutInSecond)
{
}
/*! ----------------------------------------------------------------------------
* @fn Exec
*
* @brief execute a.
*/
int UBusCall::Exec (const std::string &aPath, const std::string &aMethod,
const std::string &aParameter, std::string &aResult)
{
int theRet = 0;
uint32_t theId;
struct blob_buf theBuf = {0};
struct ubus_context *theCtx = ubus_connect (NULL);
if (theCtx == NULL) {
fprintf (stderr, "%s - Failed to create an ubus context.\n", __PRETTY_FUNCTION__);
return -1;
}
blob_buf_init (&theBuf, 0);
if (!aParameter.empty()) {
if (!blobmsg_add_json_from_string (&theBuf, aParameter.c_str())) {
fprintf (stderr, "%s - Failed to parse message data\n", __PRETTY_FUNCTION__);
return -1;
}
}
theRet = ubus_lookup_id (theCtx, aPath.c_str(), &theId);
if (theRet) {
fprintf (stderr, "%s - ubus_lookup_id error = '%d'\n", __PRETTY_FUNCTION__, theRet);
ubus_free (theCtx);
blob_buf_free (&theBuf);
return theRet;
}
theRet = ubus_invoke (theCtx, theId, aMethod.c_str(), theBuf.head, receive_call_result_data, this, mTimeout * 1000);
ubus_free (theCtx);
blob_buf_free (&theBuf);
if (!mData.empty()) {
aResult = mData;
}
return theRet;
}
/*! ----------------------------------------------------------------------------
* @fn SetResult
*
* @brief Save the Result received by UBus.
*/
int UBusCall::SetResult (const std::string &aResult)
{
mData = aResult;
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn receive_call_result_data
*
* @brief UBus received call back.
*/
static void receive_call_result_data (struct ubus_request *aReq, int aType, struct blob_attr *aMsg)
{
UNUSED_PARAMETER (aType);
char *theStr;
UBusCall *anUBusObject = static_cast<UBusCall*>(aReq->priv);
theStr = blobmsg_format_json (aMsg, true);
anUBusObject->SetResult (std::string (theStr));
free (theStr);
}

View File

@@ -1,61 +0,0 @@
/*!
* (C) Copyright 2003-2015 Awox SA. All rights reserved.
* This work contains confidential trade secrets of Awox.
* Use, examination, copying, transfer and disclosure to others
* are prohibited, except with the express written agreement of Awox.
*
* @Author: Awox
* @Date: 06/10/2014
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include "ubuscpp/UBusObject.h"
/*------------------------------- GLOBALS ----------------------------------*/
/*--------------------------------- DEFINES ---------------------------------*/
/*! ----------------------------------------------------------------------------
* @fn awUBusObject
*
* @brief Construct a new awUBusObject, 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 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)
{
name = AnObjName ? strdup (AnObjName) : 0;
id = anObjID;
path = anObjPath ? strdup (anObjPath) : 0;
type = &anObjType;
methods = anObjType.methods;
n_methods = anObjType.n_methods;
// nullify last fields
subscribe_cb = 0;
has_subscribers = false;
}
/*! ----------------------------------------------------------------------------
* @fn ~UBusObject
*
* @brief Destructor of the UBusObject
*/
UBusObject::~UBusObject (void)
{
free ((char*)name);
free ((char*)path);
}

View File

@@ -1,113 +0,0 @@
/*!
* UbusTimer.cpp
*
* Copyright (c) 2016, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 17/05/2016
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
#include <cstdio>
#include "ubuscpp/UBusTimer.h"
/*! ----------------------------------------------------------------------------
* @fn timer_callback
*
* @brief Callback used when a Timer has expired.
*/
static void timer_callback (struct uloop_timeout *aTimeout)
{
UBusTimer *aTmp = static_cast<UBusTimer *>(aTimeout);
aTmp->Tick();
}
/*! ----------------------------------------------------------------------------
* @fn UBusTimer
*
* @brief Constructor of the Timer UBUS Object.
*/
UBusTimer::UBusTimer (void)
{
// Uloop Timer Init.
cb = timer_callback;
pending = 0;
// UBus Timer.
mRepeat = false;
mTimerValue = 0;
}
/*! ----------------------------------------------------------------------------
* @fn ~UBusTimer
*
* @brief Destructor of the Timer UBUS Object.
*/
UBusTimer::~UBusTimer (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Start the Timer
*
* @brief Start the Timer object.
*/
int UBusTimer::Start (unsigned int aTimerValue, bool aRepeat)
{
mTimerValue = aTimerValue;
mRepeat = aRepeat;
return uloop_timeout_set (this, mTimerValue);
}
/*! ----------------------------------------------------------------------------
* @fn Expire
*
* @brief Method Should be overrided.
*/
int UBusTimer::Expire (void)
{
//fprintf (stderr, "UBusTimer::Expire\n");
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn Tick
*
* @brief Method called when the Timer has expired.
*/
int UBusTimer::Tick (void)
{
//fprintf (stderr, "UBusTimer::Tick\n");
Expire ();
if (mRepeat == true)
uloop_timeout_set (this, mTimerValue);
return 0;
}

View File

@@ -1,33 +0,0 @@
/*!
* UbusCall.cpp
*
* Copyright (c) 2015, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 21/03/2015
*
*/
#ifndef _UBUS_COMMON_H
#define _UBUS_COMMON_H
#ifndef UNUSED_PARAMETER
#define UNUSED_PARAMETER(x) (void)(x)
#endif
#endif /* _UBUS_COMMON_H */