Update libubus-cpp.
This commit is contained in:
@@ -7,15 +7,14 @@ set (CMAKE_CXX_STANDARD 11)
|
|||||||
|
|
||||||
include (br)
|
include (br)
|
||||||
|
|
||||||
include_directories ($ENV{SRC_DIR}/src/lib/libubus-cpp/include/)
|
include_directories (${workspaceRoot}/src/lib/libubus-cpp/include/)
|
||||||
|
|
||||||
file(
|
file(
|
||||||
GLOB_RECURSE
|
GLOB_RECURSE
|
||||||
source_files
|
source_files
|
||||||
|
${workspaceRoot}/src/lib/libubus-cpp/src/ubus-call.cpp
|
||||||
$ENV{SRC_DIR}/src/lib/libubus-cpp/src/UBusCall.cpp
|
${workspaceRoot}/src/lib/libubus-cpp/src/ubus-object.cpp
|
||||||
$ENV{SRC_DIR}/src/lib/libubus-cpp/src/UBusObject.cpp
|
${workspaceRoot}/src/lib/libubus-cpp/src/ubus-timer.cpp
|
||||||
$ENV{SRC_DIR}/src/lib/libubus-cpp/src/UBusTimer.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(
|
add_library(
|
||||||
|
|||||||
@@ -37,16 +37,15 @@ class UBusCall
|
|||||||
public:
|
public:
|
||||||
UBusCall (void);
|
UBusCall (void);
|
||||||
|
|
||||||
int Exec (const std::string &aPath, const std::string &aMethod,
|
int exec (const std::string &a_path, const std::string &a_method,
|
||||||
const std::string &aParameter, std::string &aResult);
|
const std::string &a_parameter, std::string &a_result);
|
||||||
|
|
||||||
int SetTimeout (int aTimeout);
|
int set_timeout (int a_timeout);
|
||||||
int SetResult (const std::string &aResult);
|
int set_result (const std::string &a_result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mTimeout;
|
int m_timeout;
|
||||||
std::string mData;
|
std::string m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* _UBUS_CALL_H */
|
#endif /* _UBUS_CALL_H */
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
#include "ubus-cpp/UBusCpp.h"
|
#include "ubus-cpp/ubus-cpp.h"
|
||||||
|
|
||||||
/*----------------------------- Dependencies --------------------------------*/
|
/*----------------------------- Dependencies --------------------------------*/
|
||||||
|
|
||||||
@@ -32,85 +32,85 @@ extern "C" {
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include "ubus-cpp/UBusCall.h"
|
#include "ubus-cpp/ubus-call.h"
|
||||||
|
|
||||||
#define kDefaultTimeoutInSecond 5
|
#define kDefaultTimeoutInSecond 5
|
||||||
|
|
||||||
static void receive_call_result_data (struct ubus_request *aReq, int aType, struct blob_attr *aMsg);
|
static void receive_call_result_data (struct ubus_request *aReq, int aType, struct blob_attr *aMsg);
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn UBusCall
|
* @fn UBusCall
|
||||||
*
|
*
|
||||||
* @brief Constructor of the UBus Handler.
|
* @brief Constructor of the UBus Call Command.
|
||||||
*/
|
*/
|
||||||
UBusCall::UBusCall (void):
|
UBusCall::UBusCall (void):
|
||||||
mTimeout (kDefaultTimeoutInSecond)
|
m_timeout(kDefaultTimeoutInSecond)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn Exec
|
* @fn exec
|
||||||
*
|
*
|
||||||
* @brief execute a.
|
* @brief execute a.
|
||||||
*/
|
*/
|
||||||
int UBusCall::Exec (const std::string &aPath, const std::string &aMethod,
|
int UBusCall::exec (const std::string &a_path, const std::string &a_method,
|
||||||
const std::string &aParameter, std::string &aResult)
|
const std::string &a_parameter, std::string &a_result)
|
||||||
{
|
{
|
||||||
int theRet = 0;
|
int the_ret = 0;
|
||||||
uint32_t theId;
|
uint32_t the_id;
|
||||||
|
|
||||||
struct blob_buf theBuf = {0};
|
struct blob_buf the_buf = { 0 };
|
||||||
struct ubus_context *theCtx = ubus_connect (NULL);
|
struct ubus_context *the_ctx = ubus_connect(NULL);
|
||||||
|
|
||||||
if (theCtx == NULL) {
|
if (the_ctx == NULL) {
|
||||||
|
|
||||||
fprintf (stderr, "%s - Failed to create an ubus context.\n", __PRETTY_FUNCTION__);
|
fprintf(stderr, "%s - Failed to create an ubus context.\n", __PRETTY_FUNCTION__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
blob_buf_init (&theBuf, 0);
|
blob_buf_init(&the_buf, 0);
|
||||||
|
|
||||||
if (!aParameter.empty()) {
|
if (!a_parameter.empty()) {
|
||||||
|
|
||||||
if (!blobmsg_add_json_from_string (&theBuf, aParameter.c_str())) {
|
if (!blobmsg_add_json_from_string(&the_buf, a_parameter.c_str())) {
|
||||||
|
|
||||||
fprintf (stderr, "%s - Failed to parse message data\n", __PRETTY_FUNCTION__);
|
fprintf(stderr, "%s - Failed to parse message data\n", __PRETTY_FUNCTION__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
theRet = ubus_lookup_id (theCtx, aPath.c_str(), &theId);
|
the_ret = ubus_lookup_id(the_ctx, a_path.c_str(), &the_id);
|
||||||
if (theRet) {
|
if (the_ret) {
|
||||||
|
|
||||||
fprintf (stderr, "%s - ubus_lookup_id error = '%d'\n", __PRETTY_FUNCTION__, theRet);
|
fprintf(stderr, "%s - ubus_lookup_id error = '%d'\n", __PRETTY_FUNCTION__, the_ret);
|
||||||
ubus_free (theCtx);
|
ubus_free(the_ctx);
|
||||||
blob_buf_free (&theBuf);
|
blob_buf_free(&the_buf);
|
||||||
return theRet;
|
return the_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
theRet = ubus_invoke (theCtx, theId, aMethod.c_str(), theBuf.head, receive_call_result_data, this, mTimeout * 1000);
|
the_ret = ubus_invoke(the_ctx, the_id, a_method.c_str(), the_buf.head, receive_call_result_data, this, m_timeout * 1000);
|
||||||
|
|
||||||
ubus_free (theCtx);
|
ubus_free(the_ctx);
|
||||||
blob_buf_free (&theBuf);
|
blob_buf_free(&the_buf);
|
||||||
|
|
||||||
if (!mData.empty()) {
|
if (!m_data.empty()) {
|
||||||
|
|
||||||
aResult = mData;
|
a_result = m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return theRet;
|
return the_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn SetResult
|
* @fn set_result
|
||||||
*
|
*
|
||||||
* @brief Save the Result received by UBus.
|
* @brief Save the Result received by UBus.
|
||||||
*/
|
*/
|
||||||
int UBusCall::SetResult (const std::string &aResult)
|
int UBusCall::set_result (const std::string &a_result)
|
||||||
{
|
{
|
||||||
mData = aResult;
|
m_data = a_result;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,11 +123,11 @@ int UBusCall::SetResult (const std::string &aResult)
|
|||||||
static void receive_call_result_data (struct ubus_request *aReq, int aType, struct blob_attr *aMsg)
|
static void receive_call_result_data (struct ubus_request *aReq, int aType, struct blob_attr *aMsg)
|
||||||
{
|
{
|
||||||
UNUSED_PARAMETER (aType);
|
UNUSED_PARAMETER (aType);
|
||||||
char *theStr;
|
char *the_str;
|
||||||
UBusCall *anUBusObject = static_cast<UBusCall*>(aReq->priv);
|
UBusCall *anUBusObject = static_cast<UBusCall*>(aReq->priv);
|
||||||
theStr = blobmsg_format_json (aMsg, true);
|
the_str = blobmsg_format_json(aMsg, true);
|
||||||
|
|
||||||
anUBusObject->SetResult (std::string (theStr));
|
anUBusObject->set_result(std::string(the_str));
|
||||||
|
|
||||||
free (theStr);
|
free(the_str);
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
#include "ubus-cpp/UBusObject.h"
|
#include "ubus-cpp/ubus-object.h"
|
||||||
|
|
||||||
/*------------------------------- GLOBALS ----------------------------------*/
|
/*------------------------------- GLOBALS ----------------------------------*/
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include "ubus-cpp/UBusTimer.h"
|
#include "ubus-cpp/ubus-timer.h"
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
Reference in New Issue
Block a user