Update typo.
This commit is contained in:
@@ -43,18 +43,18 @@ class UBusExecReceiver;
|
|||||||
|
|
||||||
class UBusCall
|
class UBusCall
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UBusCall (void);
|
UBusCall(void);
|
||||||
|
|
||||||
int exec (const std::string &a_path, const std::string &a_method,
|
int exec(const std::string &a_path, const std::string &a_method,
|
||||||
const std::string &a_parameter, std::string &a_result);
|
const std::string &a_parameter, std::string &a_result);
|
||||||
|
|
||||||
int exec_async (struct ubus_context *a_ctx, uint32_t an_object, const std::string &a_method, const std::string &a_parameter, UBusExecReceiver *a_receiver);
|
int exec_async(struct ubus_context *a_ctx, uint32_t an_object, const std::string &a_method, const std::string &a_parameter, UBusExecReceiver *a_receiver);
|
||||||
|
|
||||||
int set_timeout (int a_timeout);
|
int set_timeout(int a_timeout);
|
||||||
int set_result (const std::string &a_result);
|
int set_result(const std::string &a_result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_timeout;
|
int m_timeout;
|
||||||
std::string m_data;
|
std::string m_data;
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -38,16 +38,16 @@ struct ubus_context;
|
|||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class UBusEventReceiver : public ubus_event_handler {
|
class UBusEventReceiver : public ubus_event_handler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UBusEventReceiver(void);
|
||||||
|
virtual ~UBusEventReceiver(void);
|
||||||
|
|
||||||
public:
|
int register_event(struct ubus_context *a_ctx, const std::string &an_event);
|
||||||
UBusEventReceiver (void);
|
int unregister_event(struct ubus_context *a_ctx);
|
||||||
virtual ~UBusEventReceiver (void);
|
|
||||||
|
|
||||||
int register_event (struct ubus_context *a_ctx, const std::string &an_event);
|
virtual void handle_event(const char *a_type, const char *a_json_msg) = 0;
|
||||||
int unregister_event (struct ubus_context *a_ctx);
|
|
||||||
|
|
||||||
virtual void handle_event (const char *a_type, const char *a_json_msg) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _UBUS_EVENT_RECEIVER_H */
|
#endif /* _UBUS_EVENT_RECEIVER_H */
|
||||||
|
|||||||
@@ -39,18 +39,18 @@ struct ubus_event_handler;
|
|||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class UBusEvent {
|
class UBusEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UBusEvent(void);
|
||||||
|
virtual ~UBusEvent(void);
|
||||||
|
|
||||||
public:
|
int listen(struct ubus_context *a_ctx, const std::string &an_event);
|
||||||
UBusEvent (void);
|
virtual void handle_event(const char *a_type, const char *a_json_msg);
|
||||||
virtual ~UBusEvent (void);
|
static int send(const std::string &an_event, const std::string &a_data);
|
||||||
|
|
||||||
int listen (struct ubus_context *a_ctx, const std::string &an_event);
|
private:
|
||||||
virtual void handle_event (const char *a_type, const char *a_json_msg);
|
std::list<struct ubus_event_handler *> m_listeners;
|
||||||
static int send (const std::string &an_event, const std::string &a_data);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::list <struct ubus_event_handler *> m_listeners;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _UBUS_EVENT_H */
|
#endif /* _UBUS_EVENT_H */
|
||||||
|
|||||||
@@ -20,9 +20,8 @@
|
|||||||
* @Date: 04/05/2017
|
* @Date: 04/05/2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _UBUS_EXEC_RECIVER_H
|
#ifndef _UBUS_EXEC_RECEIVER_H
|
||||||
#define _UBUS_EXEC_RECIVER_H
|
#define _UBUS_EXEC_RECEIVER_H
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
@@ -35,26 +34,26 @@ extern "C" {
|
|||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class UBusExecReceiver : public ubus_request {
|
class UBusExecReceiver : public ubus_request
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UBusExecReceiver(void);
|
||||||
|
virtual ~UBusExecReceiver(void);
|
||||||
|
|
||||||
public:
|
int abort(struct ubus_context *a_ctx);
|
||||||
UBusExecReceiver (void);
|
int complete_request_async(struct ubus_context *a_ctx);
|
||||||
virtual ~UBusExecReceiver (void);
|
|
||||||
|
|
||||||
int abort (struct ubus_context *a_ctx);
|
void add_data(std::string a_data);
|
||||||
int complete_request_async (struct ubus_context *a_ctx);
|
const std::string &get_data(void);
|
||||||
|
|
||||||
void add_data (std::string a_data);
|
void add_result(int a_result);
|
||||||
const std::string &get_data (void);
|
int get_result(void);
|
||||||
|
|
||||||
void add_result (int a_result);
|
virtual void complete(void) = 0;
|
||||||
int get_result (void);
|
|
||||||
|
|
||||||
virtual void complete (void) = 0;
|
private:
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_data;
|
std::string m_data;
|
||||||
int m_result;
|
int m_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _UBUS_EXEC_RECIVER_H */
|
#endif /* _UBUS_EXEC_RECEIVER_H */
|
||||||
|
|||||||
@@ -30,21 +30,19 @@
|
|||||||
|
|
||||||
/*----------------------------- Dependencies --------------------------------*/
|
/*----------------------------- Dependencies --------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class UBusObject : public ubus_object {
|
class UBusObject : public ubus_object
|
||||||
|
{
|
||||||
|
// Disable copy construction and copy assignment
|
||||||
|
UBusObject(const UBusObject &);
|
||||||
|
UBusObject &operator=(const UBusObject &);
|
||||||
|
|
||||||
// Disable copy construction and copy assignement
|
public:
|
||||||
UBusObject (const UBusObject&);
|
UBusObject(ubus_object_type &anObjType, const char *AnObjName, int anObjID = 0,
|
||||||
UBusObject &operator=(const UBusObject&);
|
|
||||||
|
|
||||||
public:
|
|
||||||
UBusObject (ubus_object_type &anObjType, const char *AnObjName, int anObjID = 0,
|
|
||||||
const char *anObjPath = 0);
|
const char *anObjPath = 0);
|
||||||
//SHOULD virtual ~UBusObject (void);
|
//SHOULD virtual ~UBusObject (void);
|
||||||
~UBusObject (void);
|
~UBusObject(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* _UBUS_OBJECT_H */
|
#endif /* _UBUS_OBJECT_H */
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ extern "C" {
|
|||||||
|
|
||||||
class ULoopTimer : public uloop_timeout
|
class ULoopTimer : public uloop_timeout
|
||||||
{
|
{
|
||||||
// Disable copy construction and copy assignement
|
// Disable copy construction and copy assignment
|
||||||
ULoopTimer(const ULoopTimer &);
|
ULoopTimer(const ULoopTimer &);
|
||||||
ULoopTimer &operator=(const ULoopTimer &);
|
ULoopTimer &operator=(const ULoopTimer &);
|
||||||
|
|
||||||
|
|||||||
@@ -30,4 +30,4 @@
|
|||||||
#define UNUSED_PARAMETER(x) (void)(x)
|
#define UNUSED_PARAMETER(x) (void)(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _UBUS_COMMON_H */
|
#endif /* _UBUS_COMMON_H */
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ extern "C" {
|
|||||||
*
|
*
|
||||||
* @brief callback of result.
|
* @brief callback of result.
|
||||||
*/
|
*/
|
||||||
static void receive_call_result_data (struct ubus_request *a_req, int a_type, struct blob_attr *a_msg)
|
static void receive_call_result_data(struct ubus_request *a_req, int a_type, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
char *the_str;
|
char *the_str;
|
||||||
UBusCall *a_caller = static_cast<UBusCall*>(a_req->priv);
|
UBusCall *a_caller = static_cast<UBusCall *>(a_req->priv);
|
||||||
|
|
||||||
the_str = blobmsg_format_json(a_msg, true);
|
the_str = blobmsg_format_json(a_msg, true);
|
||||||
|
|
||||||
@@ -64,18 +64,16 @@ static void receive_call_result_data (struct ubus_request *a_req, int a_type, st
|
|||||||
*
|
*
|
||||||
* @brief Constructor of the UBus Call Command.
|
* @brief Constructor of the UBus Call Command.
|
||||||
*/
|
*/
|
||||||
UBusCall::UBusCall (void):
|
UBusCall::UBusCall(void) : m_timeout(kDefaultTimeoutInSecond)
|
||||||
m_timeout(kDefaultTimeoutInSecond)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn exec
|
* @fn exec
|
||||||
*
|
*
|
||||||
* @brief execute a.
|
* @brief execute a.
|
||||||
*/
|
*/
|
||||||
int UBusCall::exec (const std::string &a_path, const std::string &a_method,
|
int UBusCall::exec(const std::string &a_path, const std::string &a_method,
|
||||||
const std::string &a_parameter, std::string &a_result)
|
const std::string &a_parameter, std::string &a_result)
|
||||||
{
|
{
|
||||||
int the_ret = 0;
|
int the_ret = 0;
|
||||||
@@ -85,7 +83,8 @@ int UBusCall::exec (const std::string &a_path, const std::string &a_method,
|
|||||||
#endif
|
#endif
|
||||||
the_ret = ubus_sync_exec(a_path.c_str(), a_method.c_str(), a_parameter.c_str(), receive_call_result_data, this);
|
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();
|
a_result = m_data.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,26 +98,26 @@ int UBusCall::exec (const std::string &a_path, const std::string &a_method,
|
|||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn exec-async
|
* @fn exec-async
|
||||||
*
|
*
|
||||||
* @brief Execute an UBus Method Asynchrously;
|
* @brief Execute an UBus Method Asynchronously;
|
||||||
*/
|
*/
|
||||||
int UBusCall::exec_async (struct ubus_context *a_ctx, uint32_t an_object, const std::string &a_method, const std::string &a_parameter, UBusExecReceiver *a_receiver)
|
int UBusCall::exec_async(struct ubus_context *a_ctx, uint32_t an_object, const std::string &a_method, const std::string &a_parameter, UBusExecReceiver *a_receiver)
|
||||||
{
|
{
|
||||||
int the_return = -1;
|
int the_return = -1;
|
||||||
struct blob_buf the_parameter = { 0 };
|
struct blob_buf the_parameter = {0};
|
||||||
a_receiver->abort (a_ctx);
|
a_receiver->abort(a_ctx);
|
||||||
|
|
||||||
blob_buf_init (&the_parameter, 0);
|
blob_buf_init(&the_parameter, 0);
|
||||||
|
|
||||||
if (!a_parameter.empty())
|
if (!a_parameter.empty())
|
||||||
blobmsg_add_json_from_string (&the_parameter, a_parameter.c_str());
|
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);
|
a_receiver->complete_request_async(a_ctx);
|
||||||
the_return = 0;
|
the_return = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
blob_buf_free (&the_parameter);
|
blob_buf_free(&the_parameter);
|
||||||
|
|
||||||
return the_return;
|
return the_return;
|
||||||
}
|
}
|
||||||
@@ -128,7 +127,7 @@ int UBusCall::exec_async (struct ubus_context *a_ctx, uint32_t an_object, const
|
|||||||
*
|
*
|
||||||
* @brief Save the Result received by UBus.
|
* @brief Save the Result received by UBus.
|
||||||
*/
|
*/
|
||||||
int UBusCall::set_result (const std::string &a_result)
|
int UBusCall::set_result(const std::string &a_result)
|
||||||
{
|
{
|
||||||
m_data = a_result;
|
m_data = a_result;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -34,64 +34,59 @@ extern "C" {
|
|||||||
|
|
||||||
/*--------------------------------- DEFINES ---------------------------------*/
|
/*--------------------------------- DEFINES ---------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn receive_event
|
* @fn receive_event
|
||||||
*
|
*
|
||||||
* @brief callback called when the event arrive.
|
* @brief callback called when the event arrive.
|
||||||
*/
|
*/
|
||||||
static void receive_event (struct ubus_context *a_ctx, struct ubus_event_handler *an_ev,
|
static void receive_event(struct ubus_context *a_ctx, struct ubus_event_handler *an_ev,
|
||||||
const char *a_type, struct blob_attr *a_msg)
|
const char *a_type, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
char *the_string;
|
char *the_string;
|
||||||
UBusEventReceiver *the_receiver = static_cast<UBusEventReceiver *>(an_ev);
|
UBusEventReceiver *the_receiver = static_cast<UBusEventReceiver *>(an_ev);
|
||||||
the_string = blobmsg_format_json (a_msg, true);
|
the_string = blobmsg_format_json(a_msg, true);
|
||||||
|
|
||||||
the_receiver->handle_event (a_type, the_string);
|
the_receiver->handle_event(a_type, the_string);
|
||||||
|
|
||||||
free (the_string);
|
free(the_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn UBusEventReceiver
|
* @fn UBusEventReceiver
|
||||||
*
|
*
|
||||||
* @brief Constructor of the UBus Event Receiver
|
* @brief Constructor of the UBus Event Receiver
|
||||||
*/
|
*/
|
||||||
UBusEventReceiver::UBusEventReceiver (void)
|
UBusEventReceiver::UBusEventReceiver(void)
|
||||||
{
|
{
|
||||||
obj = { 0 };
|
obj = {0};
|
||||||
cb = receive_event;
|
cb = receive_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn ~UBusEventReceiver
|
* @fn ~UBusEventReceiver
|
||||||
*
|
*
|
||||||
* @brief Destructor of of the UBus Event Receiver
|
* @brief Destructor of of the UBus Event Receiver
|
||||||
*/
|
*/
|
||||||
UBusEventReceiver::~UBusEventReceiver (void)
|
UBusEventReceiver::~UBusEventReceiver(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn register_event
|
* @fn register_event
|
||||||
*
|
*
|
||||||
* @brief register to an ubus event type.
|
* @brief register to an ubus event type.
|
||||||
*/
|
*/
|
||||||
int UBusEventReceiver::register_event (struct ubus_context *a_ctx, const std::string &an_event)
|
int UBusEventReceiver::register_event(struct ubus_context *a_ctx, const std::string &an_event)
|
||||||
{
|
{
|
||||||
return ubus_register_event_handler (a_ctx, this, an_event.c_str());;
|
return ubus_register_event_handler(a_ctx, this, an_event.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn unregister_event
|
* @fn unregister_event
|
||||||
*
|
*
|
||||||
* @brief un register to an ubus event type.
|
* @brief un register to an ubus event type.
|
||||||
*/
|
*/
|
||||||
int UBusEventReceiver::unregister_event (struct ubus_context *a_ctx)
|
int UBusEventReceiver::unregister_event(struct ubus_context *a_ctx)
|
||||||
{
|
{
|
||||||
return ubus_unregister_event_handler (a_ctx, this);
|
return ubus_unregister_event_handler(a_ctx, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,11 @@ extern "C" {
|
|||||||
|
|
||||||
// #define UBUS_PROFILE 1
|
// #define UBUS_PROFILE 1
|
||||||
|
|
||||||
|
static void receive_event(struct ubus_context *a_ctx, struct ubus_event_handler *an_ev,
|
||||||
static void receive_event (struct ubus_context *a_ctx, struct ubus_event_handler *an_ev,
|
|
||||||
const char *a_type, struct blob_attr *a_msg)
|
const char *a_type, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
char *the_str;
|
char *the_str;
|
||||||
UBusEvent *a_caller = static_cast<UBusEvent*>(an_ev->priv);
|
UBusEvent *a_caller = static_cast<UBusEvent *>(an_ev->priv);
|
||||||
|
|
||||||
the_str = blobmsg_format_json(a_msg, true);
|
the_str = blobmsg_format_json(a_msg, true);
|
||||||
|
|
||||||
@@ -40,45 +39,42 @@ static void receive_event (struct ubus_context *a_ctx, struct ubus_event_handler
|
|||||||
free(the_str);
|
free(the_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn UBusEvent
|
* @fn UBusEvent
|
||||||
*
|
*
|
||||||
* @brief Constructor of the UBusEvent
|
* @brief Constructor of the UBusEvent
|
||||||
*/
|
*/
|
||||||
UBusEvent::UBusEvent (void)
|
UBusEvent::UBusEvent(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn ~UBusEvent
|
* @fn ~UBusEvent
|
||||||
*
|
*
|
||||||
* @brief Destructor of the UBusEvent
|
* @brief Destructor of the UBusEvent
|
||||||
*/
|
*/
|
||||||
UBusEvent::~UBusEvent (void)
|
UBusEvent::~UBusEvent(void)
|
||||||
{
|
{
|
||||||
while (!m_listeners.empty()) {
|
while (!m_listeners.empty())
|
||||||
|
{
|
||||||
delete *(m_listeners.begin());
|
delete *(m_listeners.begin());
|
||||||
m_listeners.erase(m_listeners.begin());
|
m_listeners.erase(m_listeners.begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn listen
|
* @fn listen
|
||||||
*
|
*
|
||||||
* @brief Handle an UBUS Event.
|
* @brief Handle an UBUS Event.
|
||||||
*/
|
*/
|
||||||
int UBusEvent::listen (struct ubus_context *a_ctx, const std::string &an_event)
|
int UBusEvent::listen(struct ubus_context *a_ctx, const std::string &an_event)
|
||||||
{
|
{
|
||||||
//static struct ubus_event_handler theListener;
|
//static struct ubus_event_handler theListener;
|
||||||
//fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
|
//fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
struct ubus_event_handler *the_evt_listener = new ubus_event_handler;
|
struct ubus_event_handler *the_evt_listener = new ubus_event_handler;
|
||||||
|
|
||||||
memset (the_evt_listener, 0, sizeof (struct ubus_event_handler));
|
memset(the_evt_listener, 0, sizeof(struct ubus_event_handler));
|
||||||
the_evt_listener->cb = receive_event;
|
the_evt_listener->cb = receive_event;
|
||||||
the_evt_listener->priv = this;
|
the_evt_listener->priv = this;
|
||||||
|
|
||||||
@@ -87,23 +83,21 @@ int UBusEvent::listen (struct ubus_context *a_ctx, const std::string &an_event)
|
|||||||
return ubus_register_event_handler(a_ctx, the_evt_listener, an_event.c_str());
|
return ubus_register_event_handler(a_ctx, the_evt_listener, an_event.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn handle_event
|
* @fn handle_event
|
||||||
*
|
*
|
||||||
* @brief Handle an UBUS Event.
|
* @brief Handle an UBUS Event.
|
||||||
*/
|
*/
|
||||||
void UBusEvent::handle_event (const char *a_type, const char *a_json_msg)
|
void UBusEvent::handle_event(const char *a_type, const char *a_json_msg)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn send
|
* @fn send
|
||||||
*
|
*
|
||||||
* @brief Send an UBus Method
|
* @brief Send an UBus Method
|
||||||
*/
|
*/
|
||||||
int UBusEvent::send (const std::string &an_event, const std::string &a_data)
|
int UBusEvent::send(const std::string &an_event, const std::string &a_data)
|
||||||
{
|
{
|
||||||
int the_result;
|
int the_result;
|
||||||
#ifdef UBUS_PROFILE
|
#ifdef UBUS_PROFILE
|
||||||
@@ -115,7 +109,7 @@ int UBusEvent::send (const std::string &an_event, const std::string &a_data)
|
|||||||
|
|
||||||
#ifdef UBUS_PROFILE
|
#ifdef UBUS_PROFILE
|
||||||
gettimeofday(&the_current_timeval, NULL);
|
gettimeofday(&the_current_timeval, NULL);
|
||||||
printf ("ubus_event [%s] duree: %.0lf ms\n", an_event.c_str(), time_diff(the_start_request, the_current_timeval) / 1000);
|
printf("ubus_event [%s] duree: %.0lf ms\n", an_event.c_str(), time_diff(the_start_request, the_current_timeval) / 1000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return the_result;
|
return the_result;
|
||||||
|
|||||||
@@ -20,55 +20,51 @@
|
|||||||
* @Date: 04/05/2017
|
* @Date: 04/05/2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||||
|
|
||||||
#include "ubus-cpp/ubus-exec-receiver.h"
|
#include "ubus-cpp/ubus-exec-receiver.h"
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn handle_data_request
|
* @fn handle_data_request
|
||||||
*
|
*
|
||||||
* @brief callback called when data arrive.
|
* @brief callback called when data arrive.
|
||||||
*/
|
*/
|
||||||
static void handle_data_request (struct ubus_request *a_req, int, struct blob_attr *a_msg)
|
static void handle_data_request(struct ubus_request *a_req, int, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
char *the_string;
|
char *the_string;
|
||||||
UBusExecReceiver *the_receiver = static_cast<UBusExecReceiver *>(a_req);
|
UBusExecReceiver *the_receiver = static_cast<UBusExecReceiver *>(a_req);
|
||||||
//printf ("handle_data_request\n");
|
//printf ("handle_data_request\n");
|
||||||
|
|
||||||
the_string = blobmsg_format_json (a_msg, true);
|
the_string = blobmsg_format_json(a_msg, true);
|
||||||
the_receiver->add_data (the_string);
|
the_receiver->add_data(the_string);
|
||||||
|
|
||||||
free (the_string);
|
free(the_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn handle_complete_request
|
* @fn handle_complete_request
|
||||||
*
|
*
|
||||||
* @brief callback called when the request is complete.
|
* @brief callback called when the request is complete.
|
||||||
*/
|
*/
|
||||||
static void handle_complete_request (struct ubus_request *a_req, int a_ret)
|
static void handle_complete_request(struct ubus_request *a_req, int a_ret)
|
||||||
{
|
{
|
||||||
UBusExecReceiver *the_receiver = static_cast<UBusExecReceiver *>(a_req);
|
UBusExecReceiver *the_receiver = static_cast<UBusExecReceiver *>(a_req);
|
||||||
//printf ("handle_complete_request (%d)\n", a_ret);
|
//printf ("handle_complete_request (%d)\n", a_ret);
|
||||||
|
|
||||||
the_receiver->add_result (a_ret);
|
the_receiver->add_result(a_ret);
|
||||||
the_receiver->complete ();
|
the_receiver->complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn UBusExecReceiver
|
* @fn UBusExecReceiver
|
||||||
*
|
*
|
||||||
* @brief Constructor of the Ubus Exec Receiver
|
* @brief Constructor of the Ubus Exec Receiver
|
||||||
*/
|
*/
|
||||||
UBusExecReceiver::UBusExecReceiver (void)
|
UBusExecReceiver::UBusExecReceiver(void)
|
||||||
{
|
{
|
||||||
list = LIST_HEAD_INIT (list);
|
list = LIST_HEAD_INIT(list);
|
||||||
|
|
||||||
pending = { 0 };
|
pending = {0};
|
||||||
status_code = 0;
|
status_code = 0;
|
||||||
status_msg = 0;
|
status_msg = 0;
|
||||||
blocked = 0;
|
blocked = 0;
|
||||||
@@ -89,85 +85,78 @@ UBusExecReceiver::UBusExecReceiver (void)
|
|||||||
m_result = -1;
|
m_result = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn ~UBusExecReceiver
|
* @fn ~UBusExecReceiver
|
||||||
*
|
*
|
||||||
* @brief Destructor of the Ubus Exec Receiver
|
* @brief Destructor of the Ubus Exec Receiver
|
||||||
*/
|
*/
|
||||||
UBusExecReceiver::~UBusExecReceiver (void)
|
UBusExecReceiver::~UBusExecReceiver(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn abort
|
* @fn abort
|
||||||
*
|
*
|
||||||
* @brief abort the current exec command.
|
* @brief abort the current exec command.
|
||||||
*/
|
*/
|
||||||
int UBusExecReceiver::abort (struct ubus_context *a_ctx)
|
int UBusExecReceiver::abort(struct ubus_context *a_ctx)
|
||||||
{
|
{
|
||||||
ubus_abort_request (a_ctx, this);
|
ubus_abort_request(a_ctx, this);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn complete_request_async
|
* @fn complete_request_async
|
||||||
*
|
*
|
||||||
* @brief launch the registered async request.
|
* @brief launch the registered async request.
|
||||||
*/
|
*/
|
||||||
int UBusExecReceiver::complete_request_async (struct ubus_context *a_ctx)
|
int UBusExecReceiver::complete_request_async(struct ubus_context *a_ctx)
|
||||||
{
|
{
|
||||||
data_cb = handle_data_request;
|
data_cb = handle_data_request;
|
||||||
complete_cb = handle_complete_request;
|
complete_cb = handle_complete_request;
|
||||||
|
|
||||||
ubus_complete_request_async (a_ctx, this);
|
ubus_complete_request_async(a_ctx, this);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn add_data
|
* @fn add_data
|
||||||
*
|
*
|
||||||
* @brief add data from the receiver.
|
* @brief add data from the receiver.
|
||||||
*/
|
*/
|
||||||
void UBusExecReceiver::add_data (std::string a_data)
|
void UBusExecReceiver::add_data(std::string a_data)
|
||||||
{
|
{
|
||||||
m_data += a_data;
|
m_data += a_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn get_data
|
* @fn get_data
|
||||||
*
|
*
|
||||||
* @brief return the data received from the command.
|
* @brief return the data received from the command.
|
||||||
*/
|
*/
|
||||||
const std::string &UBusExecReceiver::get_data (void)
|
const std::string &UBusExecReceiver::get_data(void)
|
||||||
{
|
{
|
||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn get_data
|
* @fn get_data
|
||||||
*
|
*
|
||||||
* @brief save the result of the request.
|
* @brief save the result of the request.
|
||||||
*/
|
*/
|
||||||
void UBusExecReceiver::add_result (int a_result)
|
void UBusExecReceiver::add_result(int a_result)
|
||||||
{
|
{
|
||||||
m_result = a_result;
|
m_result = a_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn get_result
|
* @fn get_result
|
||||||
*
|
*
|
||||||
* @brief return the result of the request.
|
* @brief return the result of the request.
|
||||||
*/
|
*/
|
||||||
int UBusExecReceiver::get_result (void)
|
int UBusExecReceiver::get_result(void)
|
||||||
{
|
{
|
||||||
return m_result;
|
return m_result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
#include "ubus-cpp/ubus-object.h"
|
#include "ubus-cpp/ubus-object.h"
|
||||||
@@ -31,27 +30,25 @@
|
|||||||
|
|
||||||
/*--------------------------------- DEFINES ---------------------------------*/
|
/*--------------------------------- 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
|
* 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 AnObjName : the name of the object
|
||||||
* @param anObjID : TO BE DEFINED
|
* @param anObjID : TO BE DEFINED
|
||||||
* @param anObjPath : TO BE DEFINED
|
* @param anObjPath : TO BE DEFINED
|
||||||
*
|
*
|
||||||
* @important : the parameter anObjType should not be a temporary !!!
|
* @important : the parameter anObjType should not be a temporary !!!
|
||||||
*/
|
*/
|
||||||
UBusObject::UBusObject (ubus_object_type &anObjType, const char *AnObjName, int anObjID,
|
UBusObject::UBusObject(ubus_object_type &anObjType, const char *AnObjName, int anObjID,
|
||||||
const char *anObjPath)
|
const char *anObjPath)
|
||||||
{
|
{
|
||||||
name = AnObjName ? strdup (AnObjName) : 0;
|
name = AnObjName ? strdup(AnObjName) : 0;
|
||||||
id = anObjID;
|
id = anObjID;
|
||||||
path = anObjPath ? strdup (anObjPath) : 0;
|
path = anObjPath ? strdup(anObjPath) : 0;
|
||||||
|
|
||||||
type = &anObjType;
|
type = &anObjType;
|
||||||
methods = anObjType.methods;
|
methods = anObjType.methods;
|
||||||
@@ -62,14 +59,13 @@ UBusObject::UBusObject (ubus_object_type &anObjType, const char *AnObjName, int
|
|||||||
has_subscribers = false;
|
has_subscribers = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn ~UBusObject
|
* @fn ~UBusObject
|
||||||
*
|
*
|
||||||
* @brief Destructor of the UBusObject
|
* @brief Destructor of the UBusObject
|
||||||
*/
|
*/
|
||||||
UBusObject::~UBusObject (void)
|
UBusObject::~UBusObject(void)
|
||||||
{
|
{
|
||||||
free ((char*)name);
|
free((char *)name);
|
||||||
free ((char*)path);
|
free((char *)path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,8 @@
|
|||||||
|
|
||||||
#include "ubus-sync.h"
|
#include "ubus-sync.h"
|
||||||
|
|
||||||
|
struct ubus_sync_context
|
||||||
struct ubus_sync_context {
|
{
|
||||||
uint16_t request_seq;
|
uint16_t request_seq;
|
||||||
int fd;
|
int fd;
|
||||||
bool eof;
|
bool eof;
|
||||||
@@ -56,23 +56,27 @@ struct ubus_sync_context {
|
|||||||
struct avl_tree objects;
|
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 = {};
|
struct blob_buf b = {};
|
||||||
|
|
||||||
static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = {
|
static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = {
|
||||||
[UBUS_ATTR_STATUS] = { .type = BLOB_ATTR_INT32 },
|
[UBUS_ATTR_STATUS] = {.type = BLOB_ATTR_INT32},
|
||||||
[UBUS_ATTR_OBJID] = { .type = BLOB_ATTR_INT32 },
|
[UBUS_ATTR_OBJID] = {.type = BLOB_ATTR_INT32},
|
||||||
[UBUS_ATTR_OBJPATH] = { .type = BLOB_ATTR_STRING },
|
[UBUS_ATTR_OBJPATH] = {.type = BLOB_ATTR_STRING},
|
||||||
[UBUS_ATTR_METHOD] = { .type = BLOB_ATTR_STRING },
|
[UBUS_ATTR_METHOD] = {.type = BLOB_ATTR_STRING},
|
||||||
[UBUS_ATTR_ACTIVE] = { .type = BLOB_ATTR_INT8 },
|
[UBUS_ATTR_ACTIVE] = {.type = BLOB_ATTR_INT8},
|
||||||
[UBUS_ATTR_NO_REPLY] = { .type = BLOB_ATTR_INT8 },
|
[UBUS_ATTR_NO_REPLY] = {.type = BLOB_ATTR_INT8},
|
||||||
[UBUS_ATTR_SUBSCRIBERS] = { .type = BLOB_ATTR_NESTED },
|
[UBUS_ATTR_SUBSCRIBERS] = {.type = BLOB_ATTR_NESTED},
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct blob_attr *attrbuf[UBUS_ATTR_MAX];
|
static struct blob_attr *attrbuf[UBUS_ATTR_MAX];
|
||||||
|
|
||||||
struct ubus_pending_data {
|
struct ubus_pending_data
|
||||||
|
{
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
int type;
|
int type;
|
||||||
struct blob_attr data[];
|
struct blob_attr data[];
|
||||||
@@ -80,23 +84,22 @@ struct ubus_pending_data {
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void aw_ubus_handle_data (struct ubus_sync_context *ctx, unsigned int events);
|
void aw_ubus_handle_data(struct ubus_sync_context *ctx, unsigned int events);
|
||||||
static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd);
|
static bool aw_get_next_msg(struct ubus_sync_context *ctx, int *recv_fd);
|
||||||
static int recv_retry (int fd, struct iovec *iov, bool wait, int *recv_fd);
|
static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd);
|
||||||
static void aw_ubus_set_req_status (struct ubus_request *req, int ret);
|
static void aw_ubus_set_req_status(struct ubus_request *req, int ret);
|
||||||
static void aw_ubus_process_req_data (struct ubus_request *req, struct ubus_msghdr_buf *buf);
|
static void aw_ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr_buf *buf);
|
||||||
static void aw_ubus_req_complete_cb (struct ubus_request *req);
|
static void aw_ubus_req_complete_cb(struct ubus_request *req);
|
||||||
static void req_data_cb (struct ubus_request *req, int type, struct blob_attr *data);
|
static void req_data_cb(struct ubus_request *req, int type, struct blob_attr *data);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
double time_diff(struct timeval x, struct timeval y)
|
||||||
double time_diff(struct timeval x , struct timeval y)
|
|
||||||
{
|
{
|
||||||
double x_ms , y_ms , diff;
|
double x_ms, y_ms, diff;
|
||||||
|
|
||||||
x_ms = (double)x.tv_sec*1000000 + (double)x.tv_usec;
|
x_ms = (double)x.tv_sec * 1000000 + (double)x.tv_usec;
|
||||||
y_ms = (double)y.tv_sec*1000000 + (double)y.tv_usec;
|
y_ms = (double)y.tv_sec * 1000000 + (double)y.tv_usec;
|
||||||
|
|
||||||
diff = (double)y_ms - (double)x_ms;
|
diff = (double)y_ms - (double)x_ms;
|
||||||
|
|
||||||
@@ -108,12 +111,14 @@ double time_diff(struct timeval x , struct timeval y)
|
|||||||
*
|
*
|
||||||
* @brief check if a row is eq or not.
|
* @brief check if a row is eq or not.
|
||||||
*/
|
*/
|
||||||
int rows_eq (int *a, int *b)
|
int rows_eq(int *a, int *b)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0; i<16; i++) {
|
for (i = 0; i < 16; i++)
|
||||||
if (a[i] != b[i]) {
|
{
|
||||||
|
if (a[i] != b[i])
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,38 +126,45 @@ int rows_eq (int *a, int *b)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn dump_row
|
* @fn dump_row
|
||||||
*
|
*
|
||||||
* @brief dump row
|
* @brief dump row
|
||||||
*/
|
*/
|
||||||
void dump_row (long a_count, int a_numinrow, int *a_chs)
|
void dump_row(long a_count, int a_numinrow, int *a_chs)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("%08lX:", a_count - a_numinrow);
|
printf("%08lX:", a_count - a_numinrow);
|
||||||
|
|
||||||
if (a_numinrow > 0) {
|
if (a_numinrow > 0)
|
||||||
|
{
|
||||||
for (i = 0; i < a_numinrow; i++) {
|
for (i = 0; i < a_numinrow; i++)
|
||||||
if (i == 8) {
|
{
|
||||||
|
if (i == 8)
|
||||||
|
{
|
||||||
printf(" :");
|
printf(" :");
|
||||||
}
|
}
|
||||||
printf(" %02X", a_chs[i]);
|
printf(" %02X", a_chs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = a_numinrow; i < 16; i++) {
|
for (i = a_numinrow; i < 16; i++)
|
||||||
if (i == 8) {
|
{
|
||||||
|
if (i == 8)
|
||||||
|
{
|
||||||
printf(" :");
|
printf(" :");
|
||||||
}
|
}
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
printf(" ");
|
printf(" ");
|
||||||
for (i = 0; i < a_numinrow; i++) {
|
for (i = 0; i < a_numinrow; i++)
|
||||||
if (isprint(a_chs[i])) {
|
{
|
||||||
|
if (isprint(a_chs[i]))
|
||||||
|
{
|
||||||
printf("%c", a_chs[i]);
|
printf("%c", a_chs[i]);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf(".");
|
printf(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,40 +172,45 @@ void dump_row (long a_count, int a_numinrow, int *a_chs)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn dump
|
* @fn dump
|
||||||
*
|
*
|
||||||
* @brief dump on the console a memory block.
|
* @brief dump on the console a memory block.
|
||||||
*/
|
*/
|
||||||
void dump (void const *a_buffer, size_t a_len)
|
void dump(void const *a_buffer, size_t a_len)
|
||||||
{
|
{
|
||||||
unsigned char *the_buf = (unsigned char *) a_buffer;
|
unsigned char *the_buf = (unsigned char *)a_buffer;
|
||||||
long the_count = 0;
|
long the_count = 0;
|
||||||
int the_numinrow = 0;
|
int the_numinrow = 0;
|
||||||
int the_chs[16];
|
int the_chs[16];
|
||||||
int the_oldchs[16] = { 0 };
|
int the_oldchs[16] = {0};
|
||||||
int the_showed_dots = 0;
|
int the_showed_dots = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < a_len; i++) {
|
for (i = 0; i < a_len; i++)
|
||||||
|
{
|
||||||
int the_ch = the_buf[i];
|
int the_ch = the_buf[i];
|
||||||
|
|
||||||
if (the_numinrow == 16) {
|
if (the_numinrow == 16)
|
||||||
|
{
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
if (rows_eq(the_oldchs, the_chs)) {
|
if (rows_eq(the_oldchs, the_chs))
|
||||||
if (!the_showed_dots) {
|
{
|
||||||
|
if (!the_showed_dots)
|
||||||
|
{
|
||||||
the_showed_dots = 1;
|
the_showed_dots = 1;
|
||||||
printf(" .. .. .. .. .. .. .. .. : .. .. .. .. .. .. .. ..\n");
|
printf(" .. .. .. .. .. .. .. .. : .. .. .. .. .. .. .. ..\n");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
the_showed_dots = 0;
|
the_showed_dots = 0;
|
||||||
dump_row(the_count, the_numinrow, the_chs);
|
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];
|
the_oldchs[j] = the_chs[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,14 +223,15 @@ void dump (void const *a_buffer, size_t a_len)
|
|||||||
|
|
||||||
dump_row(the_count, the_numinrow, the_chs);
|
dump_row(the_count, the_numinrow, the_chs);
|
||||||
|
|
||||||
if (the_numinrow != 0) {
|
if (the_numinrow != 0)
|
||||||
|
{
|
||||||
printf("%08lX:\n", the_count);
|
printf("%08lX:\n", the_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
struct blob_attr **aw_ubus_parse_msg (struct blob_attr *msg)
|
struct blob_attr **aw_ubus_parse_msg(struct blob_attr *msg)
|
||||||
{
|
{
|
||||||
int the_ret;
|
int the_ret;
|
||||||
// printf ("==> aw_ubus_parse_msg\n");
|
// printf ("==> aw_ubus_parse_msg\n");
|
||||||
@@ -222,10 +240,9 @@ struct blob_attr **aw_ubus_parse_msg (struct blob_attr *msg)
|
|||||||
return attrbuf;
|
return attrbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void ubus_lookup_id_cb (struct ubus_request *req, int type, struct blob_attr *msg)
|
static void ubus_lookup_id_cb(struct ubus_request *req, int type, struct blob_attr *msg)
|
||||||
{
|
{
|
||||||
struct blob_attr **attr;
|
struct blob_attr **attr;
|
||||||
uint32_t *id = req->priv;
|
uint32_t *id = req->priv;
|
||||||
@@ -242,7 +259,7 @@ static void ubus_lookup_id_cb (struct ubus_request *req, int type, struct blob_a
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void aw_ubus_sync_req_cb (struct ubus_request *req, int ret)
|
static void aw_ubus_sync_req_cb(struct ubus_request *req, int ret)
|
||||||
{
|
{
|
||||||
// printf ("==> aw_ubus_sync_req_cb\n");
|
// printf ("==> aw_ubus_sync_req_cb\n");
|
||||||
req->status_msg = true;
|
req->status_msg = true;
|
||||||
@@ -250,12 +267,11 @@ static void aw_ubus_sync_req_cb (struct ubus_request *req, int ret)
|
|||||||
// uloop_end();
|
// uloop_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static bool aw_ubus_validate_hdr (struct ubus_msghdr *hdr)
|
static bool aw_ubus_validate_hdr(struct ubus_msghdr *hdr)
|
||||||
{
|
{
|
||||||
struct blob_attr *data = (struct blob_attr *) (hdr + 1);
|
struct blob_attr *data = (struct blob_attr *)(hdr + 1);
|
||||||
// printf ("==> aw_ubus_validate_hdr\n");
|
// printf ("==> aw_ubus_validate_hdr\n");
|
||||||
|
|
||||||
if (hdr->version != 0)
|
if (hdr->version != 0)
|
||||||
@@ -272,13 +288,14 @@ static bool aw_ubus_validate_hdr (struct ubus_msghdr *hdr)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int ubus_find_notify_id (struct ubus_notify_request *n, uint32_t objid)
|
static int ubus_find_notify_id(struct ubus_notify_request *n, uint32_t objid)
|
||||||
{
|
{
|
||||||
uint32_t pending = n->pending;
|
uint32_t pending = n->pending;
|
||||||
int i;
|
int i;
|
||||||
// printf ("==> ubus_find_notify_id\n");
|
// printf ("==> ubus_find_notify_id\n");
|
||||||
|
|
||||||
for (i = 0; pending; i++, pending >>= 1) {
|
for (i = 0; pending; i++, pending >>= 1)
|
||||||
|
{
|
||||||
if (!(pending & 1))
|
if (!(pending & 1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -291,12 +308,13 @@ static int ubus_find_notify_id (struct ubus_notify_request *n, uint32_t objid)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static struct ubus_request *ubus_find_request (struct ubus_sync_context *ctx, uint32_t seq, uint32_t peer, int *id)
|
static struct ubus_request *ubus_find_request(struct ubus_sync_context *ctx, uint32_t seq, uint32_t peer, int *id)
|
||||||
{
|
{
|
||||||
struct ubus_request *req;
|
struct ubus_request *req;
|
||||||
// printf ("==> ubus_find_request ctx: %p, seq: %d peer:%d\n", ctx, seq, peer);
|
// 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);
|
// printf (". req = %p seq: %d next: %p peer: %d\n", req, req->seq, req->list.next, req->peer);
|
||||||
struct ubus_notify_request *nreq;
|
struct ubus_notify_request *nreq;
|
||||||
nreq = container_of(req, struct ubus_notify_request, req);
|
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)
|
if (seq != req->seq)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (req->notify) {
|
if (req->notify)
|
||||||
|
{
|
||||||
|
|
||||||
if (!nreq->pending)
|
if (!nreq->pending)
|
||||||
continue;
|
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);
|
*id = ubus_find_notify_id(nreq, peer);
|
||||||
if (*id < 0)
|
if (*id < 0)
|
||||||
continue;
|
continue;
|
||||||
} else if (peer != req->peer)
|
}
|
||||||
|
else if (peer != req->peer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// printf ("<== ubus_find_request found: %p\n", req);
|
// printf ("<== ubus_find_request found: %p\n", req);
|
||||||
@@ -324,7 +344,7 @@ static struct ubus_request *ubus_find_request (struct ubus_sync_context *ctx, ui
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static bool aw_ubus_get_status (struct ubus_msghdr_buf *buf, int *ret)
|
static bool aw_ubus_get_status(struct ubus_msghdr_buf *buf, int *ret)
|
||||||
{
|
{
|
||||||
struct blob_attr **attrbuf = aw_ubus_parse_msg(buf->data);
|
struct blob_attr **attrbuf = aw_ubus_parse_msg(buf->data);
|
||||||
// printf ("==> aw_ubus_get_status\n");
|
// printf ("==> aw_ubus_get_status\n");
|
||||||
@@ -338,7 +358,7 @@ static bool aw_ubus_get_status (struct ubus_msghdr_buf *buf, int *ret)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void ubus_process_notify_status (struct ubus_request *req, int id, struct ubus_msghdr_buf *buf)
|
static void ubus_process_notify_status(struct ubus_request *req, int id, struct ubus_msghdr_buf *buf)
|
||||||
{
|
{
|
||||||
struct ubus_notify_request *nreq;
|
struct ubus_notify_request *nreq;
|
||||||
struct blob_attr **tb;
|
struct blob_attr **tb;
|
||||||
@@ -350,11 +370,14 @@ static void ubus_process_notify_status (struct ubus_request *req, int id, struct
|
|||||||
nreq = container_of(req, struct ubus_notify_request, req);
|
nreq = container_of(req, struct ubus_notify_request, req);
|
||||||
nreq->pending &= ~(1 << id);
|
nreq->pending &= ~(1 << id);
|
||||||
|
|
||||||
if (!id) {
|
if (!id)
|
||||||
|
{
|
||||||
/* first id: ubusd's status message with a list of ids */
|
/* first id: ubusd's status message with a list of ids */
|
||||||
tb = aw_ubus_parse_msg(buf->data);
|
tb = aw_ubus_parse_msg(buf->data);
|
||||||
if (tb[UBUS_ATTR_SUBSCRIBERS]) {
|
if (tb[UBUS_ATTR_SUBSCRIBERS])
|
||||||
blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem) {
|
{
|
||||||
|
blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem)
|
||||||
|
{
|
||||||
if (!blob_check_type(blob_data(cur), blob_len(cur), BLOB_ATTR_INT32))
|
if (!blob_check_type(blob_data(cur), blob_len(cur), BLOB_ATTR_INT32))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -366,7 +389,9 @@ static void ubus_process_notify_status (struct ubus_request *req, int id, struct
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
aw_ubus_get_status(buf, &ret);
|
aw_ubus_get_status(buf, &ret);
|
||||||
if (nreq->status_cb)
|
if (nreq->status_cb)
|
||||||
nreq->status_cb(nreq, id, ret);
|
nreq->status_cb(nreq, id, ret);
|
||||||
@@ -378,7 +403,7 @@ static void ubus_process_notify_status (struct ubus_request *req, int id, struct
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int ubus_process_req_status (struct ubus_request *req, struct ubus_msghdr_buf *buf)
|
static int ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr_buf *buf)
|
||||||
{
|
{
|
||||||
int ret = UBUS_STATUS_INVALID_ARGUMENT;
|
int ret = UBUS_STATUS_INVALID_ARGUMENT;
|
||||||
// printf ("==> ubus_process_req_status\n");
|
// printf ("==> ubus_process_req_status\n");
|
||||||
@@ -392,20 +417,22 @@ static int ubus_process_req_status (struct ubus_request *req, struct ubus_msghdr
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void ubus_process_req_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf, int fd)
|
void ubus_process_req_msg(struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf, int fd)
|
||||||
{
|
{
|
||||||
struct ubus_msghdr *hdr = &buf->hdr;
|
struct ubus_msghdr *hdr = &buf->hdr;
|
||||||
struct ubus_request *req;
|
struct ubus_request *req;
|
||||||
int id = -1;
|
int id = -1;
|
||||||
// printf ("==> ubus_process_req_msg\n");
|
// printf ("==> ubus_process_req_msg\n");
|
||||||
switch(hdr->type) {
|
switch (hdr->type)
|
||||||
|
{
|
||||||
case UBUS_MSG_STATUS:
|
case UBUS_MSG_STATUS:
|
||||||
// printf (" - type: UBUS_MSG_STATUS\n");
|
// printf (" - type: UBUS_MSG_STATUS\n");
|
||||||
req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id);
|
req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id);
|
||||||
if (!req)
|
if (!req)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0)
|
||||||
|
{
|
||||||
if (req->fd_cb)
|
if (req->fd_cb)
|
||||||
req->fd_cb(req, fd);
|
req->fd_cb(req, fd);
|
||||||
else
|
else
|
||||||
@@ -430,12 +457,13 @@ void ubus_process_req_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void __ubus_process_req_data (struct ubus_request *req)
|
static void __ubus_process_req_data(struct ubus_request *req)
|
||||||
{
|
{
|
||||||
struct ubus_pending_data *data;
|
struct ubus_pending_data *data;
|
||||||
// printf ("==> __ubus_process_req_data\n");
|
// printf ("==> __ubus_process_req_data\n");
|
||||||
|
|
||||||
while (!list_empty(&req->pending)) {
|
while (!list_empty(&req->pending))
|
||||||
|
{
|
||||||
data = list_first_entry(&req->pending,
|
data = list_first_entry(&req->pending,
|
||||||
struct ubus_pending_data, list);
|
struct ubus_pending_data, list);
|
||||||
list_del(&data->list);
|
list_del(&data->list);
|
||||||
@@ -447,7 +475,7 @@ static void __ubus_process_req_data (struct ubus_request *req)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void req_data_cb (struct ubus_request *req, int type, struct blob_attr *data)
|
static void req_data_cb(struct ubus_request *req, int type, struct blob_attr *data)
|
||||||
{
|
{
|
||||||
struct blob_attr **attr;
|
struct blob_attr **attr;
|
||||||
// printf ("==> req_data_cb\n");
|
// printf ("==> req_data_cb\n");
|
||||||
@@ -463,13 +491,14 @@ static void req_data_cb (struct ubus_request *req, int type, struct blob_attr *d
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void aw_ubus_process_req_data (struct ubus_request *req, struct ubus_msghdr_buf *buf)
|
static void aw_ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr_buf *buf)
|
||||||
{
|
{
|
||||||
struct ubus_pending_data *data;
|
struct ubus_pending_data *data;
|
||||||
int len;
|
int len;
|
||||||
// printf ("==> aw_ubus_process_req_data\n");
|
// printf ("==> aw_ubus_process_req_data\n");
|
||||||
|
|
||||||
if (!req->blocked) {
|
if (!req->blocked)
|
||||||
|
{
|
||||||
req->blocked = true;
|
req->blocked = true;
|
||||||
req_data_cb(req, buf->hdr.type, buf->data);
|
req_data_cb(req, buf->hdr.type, buf->data);
|
||||||
__ubus_process_req_data(req);
|
__ubus_process_req_data(req);
|
||||||
@@ -493,7 +522,7 @@ static void aw_ubus_process_req_data (struct ubus_request *req, struct ubus_msgh
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void ubus_process_obj_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf)
|
void ubus_process_obj_msg(struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf)
|
||||||
{
|
{
|
||||||
void (*cb)(struct ubus_sync_context *, struct ubus_msghdr *,
|
void (*cb)(struct ubus_sync_context *, struct ubus_msghdr *,
|
||||||
struct ubus_object *, struct blob_attr **);
|
struct ubus_object *, struct blob_attr **);
|
||||||
@@ -510,31 +539,34 @@ void ubus_process_obj_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf
|
|||||||
objid = blob_get_u32(attrbuf[UBUS_ATTR_OBJID]);
|
objid = blob_get_u32(attrbuf[UBUS_ATTR_OBJID]);
|
||||||
obj = avl_find_element(&ctx->objects, &objid, obj, avl);
|
obj = avl_find_element(&ctx->objects, &objid, obj, avl);
|
||||||
|
|
||||||
switch (hdr->type) {
|
switch (hdr->type)
|
||||||
|
{
|
||||||
case UBUS_MSG_INVOKE:
|
case UBUS_MSG_INVOKE:
|
||||||
printf ("==> UBUS_MSG_INVOKE (TODO)\n");
|
printf("==> UBUS_MSG_INVOKE (TODO)\n");
|
||||||
//cb = ubus_process_invoke;
|
//cb = ubus_process_invoke;
|
||||||
break;
|
break;
|
||||||
case UBUS_MSG_UNSUBSCRIBE:
|
case UBUS_MSG_UNSUBSCRIBE:
|
||||||
printf ("==> UBUS_MSG_UNSUBSCRIBE (TODO)\n");
|
printf("==> UBUS_MSG_UNSUBSCRIBE (TODO)\n");
|
||||||
//cb = ubus_process_unsubscribe;
|
//cb = ubus_process_unsubscribe;
|
||||||
break;
|
break;
|
||||||
case UBUS_MSG_NOTIFY:
|
case UBUS_MSG_NOTIFY:
|
||||||
printf ("==> UBUS_MSG_NOTIFY (TODO)\n");
|
printf("==> UBUS_MSG_NOTIFY (TODO)\n");
|
||||||
//cb = ubus_process_notify;
|
//cb = ubus_process_notify;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf == &ctx->msgbuf) {
|
if (buf == &ctx->msgbuf)
|
||||||
|
{
|
||||||
prev_data = buf->data;
|
prev_data = buf->data;
|
||||||
buf->data = NULL;
|
buf->data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//cb(ctx, hdr, obj, attrbuf);
|
//cb(ctx, hdr, obj, attrbuf);
|
||||||
|
|
||||||
if (prev_data) {
|
if (prev_data)
|
||||||
|
{
|
||||||
if (buf->data)
|
if (buf->data)
|
||||||
free(prev_data);
|
free(prev_data);
|
||||||
else
|
else
|
||||||
@@ -544,10 +576,11 @@ void ubus_process_obj_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void ubus_process_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf, int fd)
|
void ubus_process_msg(struct ubus_sync_context *ctx, struct ubus_msghdr_buf *buf, int fd)
|
||||||
{
|
{
|
||||||
// printf ("==> ubus_process_msg : %d\n", buf->hdr.type);
|
// printf ("==> ubus_process_msg : %d\n", buf->hdr.type);
|
||||||
switch(buf->hdr.type) {
|
switch (buf->hdr.type)
|
||||||
|
{
|
||||||
case UBUS_MSG_STATUS:
|
case UBUS_MSG_STATUS:
|
||||||
case UBUS_MSG_DATA:
|
case UBUS_MSG_DATA:
|
||||||
ubus_process_req_msg(ctx, buf, fd);
|
ubus_process_req_msg(ctx, buf, fd);
|
||||||
@@ -568,23 +601,24 @@ void ubus_process_msg (struct ubus_sync_context *ctx, struct ubus_msghdr_buf *bu
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int64_t aw_get_time_msec (void)
|
static int64_t aw_get_time_msec(void)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
int64_t val;
|
int64_t val;
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
val = (int64_t) ts.tv_sec * 1000LL;
|
val = (int64_t)ts.tv_sec * 1000LL;
|
||||||
val += ts.tv_nsec / 1000000LL;
|
val += ts.tv_nsec / 1000000LL;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int aw_ubus_reconnect (struct ubus_sync_context *ctx, const char *path)
|
int aw_ubus_reconnect(struct ubus_sync_context *ctx, const char *path)
|
||||||
{
|
{
|
||||||
// printf ("==> aw_ubus_reconnect\n");
|
// printf ("==> aw_ubus_reconnect\n");
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
struct ubus_msghdr hdr;
|
struct ubus_msghdr hdr;
|
||||||
struct blob_attr data;
|
struct blob_attr data;
|
||||||
} hdr;
|
} hdr;
|
||||||
@@ -629,7 +663,7 @@ int aw_ubus_reconnect (struct ubus_sync_context *ctx, const char *path)
|
|||||||
ret = UBUS_STATUS_OK;
|
ret = UBUS_STATUS_OK;
|
||||||
//fcntl(ctx->sock.fd, F_SETFL, fcntl(ctx->sock.fd, F_GETFL) | O_NONBLOCK | O_CLOEXEC);
|
//fcntl(ctx->sock.fd, F_SETFL, fcntl(ctx->sock.fd, F_GETFL) | O_NONBLOCK | O_CLOEXEC);
|
||||||
// AWOX M2: Should add F_SETFD:
|
// 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);
|
// ubus_refresh_state(ctx);
|
||||||
|
|
||||||
@@ -644,7 +678,7 @@ out_close:
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int aw_ubus_connect (struct ubus_sync_context *ctx, const char *path)
|
static int aw_ubus_connect(struct ubus_sync_context *ctx, const char *path)
|
||||||
{
|
{
|
||||||
// printf ("==> aw_ubus_connect ctx: %p\n", ctx);
|
// printf ("==> aw_ubus_connect ctx: %p\n", ctx);
|
||||||
ctx->fd = -1;
|
ctx->fd = -1;
|
||||||
@@ -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->requests);
|
||||||
//INIT_LIST_HEAD(&ctx->pending);
|
//INIT_LIST_HEAD(&ctx->pending);
|
||||||
//avl_init(&ctx->objects, ubus_cmp_id, false, NULL);
|
//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);
|
free(ctx->msgbuf.data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -670,7 +705,7 @@ static int aw_ubus_connect (struct ubus_sync_context *ctx, const char *path)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
struct ubus_sync_context *aw_new_ubus_connect (void)
|
struct ubus_sync_context *aw_new_ubus_connect(void)
|
||||||
{
|
{
|
||||||
struct ubus_sync_context *ctx;
|
struct ubus_sync_context *ctx;
|
||||||
// printf ("==> aw_new_ubus_connect\n");
|
// printf ("==> aw_new_ubus_connect\n");
|
||||||
@@ -679,7 +714,8 @@ struct ubus_sync_context *aw_new_ubus_connect (void)
|
|||||||
if (!ctx)
|
if (!ctx)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (aw_ubus_connect(ctx, NULL)) {
|
if (aw_ubus_connect(ctx, NULL))
|
||||||
|
{
|
||||||
free(ctx);
|
free(ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
}
|
}
|
||||||
@@ -689,7 +725,7 @@ struct ubus_sync_context *aw_new_ubus_connect (void)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void aw_ubus_free (struct ubus_sync_context *ctx)
|
void aw_ubus_free(struct ubus_sync_context *ctx)
|
||||||
{
|
{
|
||||||
// printf ("aw_ubus_free ctx: %p\n", ctx);
|
// printf ("aw_ubus_free ctx: %p\n", ctx);
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
@@ -698,12 +734,11 @@ void aw_ubus_free (struct ubus_sync_context *ctx)
|
|||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void aw_wait_data (int fd, bool write)
|
static void aw_wait_data(int fd, bool write)
|
||||||
{
|
{
|
||||||
struct pollfd pfd = { .fd = fd };
|
struct pollfd pfd = {.fd = fd};
|
||||||
// printf ("==>aw_wait_data\n");
|
// printf ("==>aw_wait_data\n");
|
||||||
pfd.events = write ? POLLOUT : POLLIN;
|
pfd.events = write ? POLLOUT : POLLIN;
|
||||||
poll(&pfd, 1, -1);
|
poll(&pfd, 1, -1);
|
||||||
@@ -711,7 +746,7 @@ static void aw_wait_data (int fd, bool write)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void aw_ubus_poll_data (struct ubus_sync_context *ctx, int timeout)
|
void aw_ubus_poll_data(struct ubus_sync_context *ctx, int timeout)
|
||||||
{
|
{
|
||||||
// printf ("==> aw_ubus_poll_data\n");
|
// printf ("==> aw_ubus_poll_data\n");
|
||||||
struct pollfd pfd = {
|
struct pollfd pfd = {
|
||||||
@@ -720,18 +755,19 @@ void aw_ubus_poll_data (struct ubus_sync_context *ctx, int timeout)
|
|||||||
};
|
};
|
||||||
|
|
||||||
poll(&pfd, 1, timeout);
|
poll(&pfd, 1, timeout);
|
||||||
aw_ubus_handle_data (ctx, ULOOP_READ);
|
aw_ubus_handle_data(ctx, ULOOP_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void aw_ubus_handle_data (struct ubus_sync_context *ctx, unsigned int events)
|
void aw_ubus_handle_data(struct ubus_sync_context *ctx, unsigned int events)
|
||||||
{
|
{
|
||||||
// printf ("==> aw_ubus_handle_data\n");
|
// printf ("==> aw_ubus_handle_data\n");
|
||||||
// struct ubus_context *ctx = container_of(u, struct ubus_context, sock);
|
// struct ubus_context *ctx = container_of(u, struct ubus_context, sock);
|
||||||
int recv_fd = -1;
|
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);
|
ubus_process_msg(ctx, &ctx->msgbuf, recv_fd);
|
||||||
//if (uloop_cancelled)
|
//if (uloop_cancelled)
|
||||||
// break;
|
// break;
|
||||||
@@ -743,7 +779,7 @@ void aw_ubus_handle_data (struct ubus_sync_context *ctx, unsigned int events)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static bool aw_alloc_msg_buf (struct ubus_sync_context *ctx, int len)
|
static bool aw_alloc_msg_buf(struct ubus_sync_context *ctx, int len)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
int buf_len = ctx->msgbuf_data_len;
|
int buf_len = ctx->msgbuf_data_len;
|
||||||
@@ -779,9 +815,10 @@ static bool aw_alloc_msg_buf (struct ubus_sync_context *ctx, int len)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd)
|
static bool aw_get_next_msg(struct ubus_sync_context *ctx, int *recv_fd)
|
||||||
{
|
{
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
struct ubus_msghdr hdr;
|
struct ubus_msghdr hdr;
|
||||||
struct blob_attr data;
|
struct blob_attr data;
|
||||||
} hdrbuf;
|
} hdrbuf;
|
||||||
@@ -792,7 +829,8 @@ static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd)
|
|||||||
|
|
||||||
/* receive header + start attribute */
|
/* receive header + start attribute */
|
||||||
r = recv_retry(ctx->fd, &iov, false, recv_fd);
|
r = recv_retry(ctx->fd, &iov, false, recv_fd);
|
||||||
if (r <= 0) {
|
if (r <= 0)
|
||||||
|
{
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
ctx->eof = true;
|
ctx->eof = true;
|
||||||
|
|
||||||
@@ -821,13 +859,13 @@ static bool aw_get_next_msg (struct ubus_sync_context *ctx, int *recv_fd)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int aw_writev_retry (int fd, struct iovec *iov, int iov_len, int sock_fd)
|
static int aw_writev_retry(int fd, struct iovec *iov, int iov_len, int sock_fd)
|
||||||
{
|
{
|
||||||
// printf ("==>aw_writev_retry\n");
|
// printf ("==>aw_writev_retry\n");
|
||||||
static struct {
|
static struct
|
||||||
|
{
|
||||||
struct cmsghdr h;
|
struct cmsghdr h;
|
||||||
int fd;
|
int fd;
|
||||||
} fd_buf = {
|
} 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_len = sizeof(fd_buf),
|
||||||
.cmsg_level = SOL_SOCKET,
|
.cmsg_level = SOL_SOCKET,
|
||||||
.cmsg_type = SCM_RIGHTS,
|
.cmsg_type = SCM_RIGHTS,
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
struct msghdr msghdr = {
|
struct msghdr msghdr = {
|
||||||
.msg_iov = iov,
|
.msg_iov = iov,
|
||||||
.msg_iovlen = iov_len,
|
.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;
|
int len = 0;
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
int cur_len;
|
int cur_len;
|
||||||
|
|
||||||
if (sock_fd < 0) {
|
if (sock_fd < 0)
|
||||||
|
{
|
||||||
msghdr.msg_control = NULL;
|
msghdr.msg_control = NULL;
|
||||||
msghdr.msg_controllen = 0;
|
msghdr.msg_controllen = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fd_buf.fd = sock_fd;
|
fd_buf.fd = sock_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_len = sendmsg(fd, &msghdr, 0);
|
cur_len = sendmsg(fd, &msghdr, 0);
|
||||||
if (cur_len < 0) {
|
if (cur_len < 0)
|
||||||
switch(errno) {
|
{
|
||||||
|
switch (errno)
|
||||||
|
{
|
||||||
case EAGAIN:
|
case EAGAIN:
|
||||||
aw_wait_data(fd, true);
|
aw_wait_data(fd, true);
|
||||||
break;
|
break;
|
||||||
@@ -873,7 +916,8 @@ static int aw_writev_retry (int fd, struct iovec *iov, int iov_len, int sock_fd)
|
|||||||
sock_fd = -1;
|
sock_fd = -1;
|
||||||
|
|
||||||
len += cur_len;
|
len += cur_len;
|
||||||
while (cur_len >= iov->iov_len) {
|
while (cur_len >= iov->iov_len)
|
||||||
|
{
|
||||||
cur_len -= iov->iov_len;
|
cur_len -= iov->iov_len;
|
||||||
iov_len--;
|
iov_len--;
|
||||||
iov++;
|
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)
|
static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd)
|
||||||
{
|
{
|
||||||
int bytes, total = 0;
|
int bytes, total = 0;
|
||||||
static struct {
|
static struct
|
||||||
|
{
|
||||||
struct cmsghdr h;
|
struct cmsghdr h;
|
||||||
int fd;
|
int fd;
|
||||||
} fd_buf = {
|
} fd_buf = {
|
||||||
@@ -910,14 +955,18 @@ static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd)
|
|||||||
.msg_iovlen = 1,
|
.msg_iovlen = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
while (iov->iov_len > 0) {
|
while (iov->iov_len > 0)
|
||||||
|
{
|
||||||
if (wait)
|
if (wait)
|
||||||
aw_wait_data(fd, false);
|
aw_wait_data(fd, false);
|
||||||
|
|
||||||
if (recv_fd) {
|
if (recv_fd)
|
||||||
|
{
|
||||||
msghdr.msg_control = &fd_buf;
|
msghdr.msg_control = &fd_buf;
|
||||||
msghdr.msg_controllen = sizeof(fd_buf);
|
msghdr.msg_controllen = sizeof(fd_buf);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
msghdr.msg_control = NULL;
|
msghdr.msg_control = NULL;
|
||||||
msghdr.msg_controllen = 0;
|
msghdr.msg_controllen = 0;
|
||||||
}
|
}
|
||||||
@@ -927,7 +976,8 @@ static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd)
|
|||||||
if (!bytes)
|
if (!bytes)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (bytes < 0) {
|
if (bytes < 0)
|
||||||
|
{
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
//if (uloop_cancelled)
|
//if (uloop_cancelled)
|
||||||
// return 0;
|
// return 0;
|
||||||
@@ -956,13 +1006,12 @@ static int recv_retry(int fd, struct iovec *iov, bool wait, int *recv_fd)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int aw_ubus_send_msg (struct ubus_sync_context *ctx, uint32_t seq,
|
int aw_ubus_send_msg(struct ubus_sync_context *ctx, uint32_t seq,
|
||||||
struct blob_attr *msg, int cmd, uint32_t peer, int fd)
|
struct blob_attr *msg, int cmd, uint32_t peer, int fd)
|
||||||
{
|
{
|
||||||
struct ubus_msghdr hdr;
|
struct ubus_msghdr hdr;
|
||||||
struct iovec iov[2] = {
|
struct iovec iov[2] = {
|
||||||
STATIC_IOV(hdr)
|
STATIC_IOV(hdr)};
|
||||||
};
|
|
||||||
int ret;
|
int ret;
|
||||||
// printf ("==>aw_ubus_send_msg\n");
|
// printf ("==>aw_ubus_send_msg\n");
|
||||||
hdr.version = 0;
|
hdr.version = 0;
|
||||||
@@ -970,12 +1019,13 @@ int aw_ubus_send_msg (struct ubus_sync_context *ctx, uint32_t seq,
|
|||||||
hdr.seq = cpu_to_be16(seq);
|
hdr.seq = cpu_to_be16(seq);
|
||||||
hdr.peer = cpu_to_be32(peer);
|
hdr.peer = cpu_to_be32(peer);
|
||||||
|
|
||||||
if (!msg) {
|
if (!msg)
|
||||||
|
{
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
msg = b.head;
|
msg = b.head;
|
||||||
}
|
}
|
||||||
|
|
||||||
iov[1].iov_base = (char *) msg;
|
iov[1].iov_base = (char *)msg;
|
||||||
iov[1].iov_len = blob_raw_len(msg);
|
iov[1].iov_len = blob_raw_len(msg);
|
||||||
|
|
||||||
ret = aw_writev_retry(ctx->fd, iov, ARRAY_SIZE(iov), fd);
|
ret = aw_writev_retry(ctx->fd, iov, ARRAY_SIZE(iov), fd);
|
||||||
@@ -990,7 +1040,7 @@ int aw_ubus_send_msg (struct ubus_sync_context *ctx, uint32_t seq,
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void aw_ubus_complete_request_async (struct ubus_sync_context *ctx, struct ubus_request *req)
|
void aw_ubus_complete_request_async(struct ubus_sync_context *ctx, struct ubus_request *req)
|
||||||
{
|
{
|
||||||
// printf ("==> aw_ubus_complete_request_async...\n");
|
// printf ("==> aw_ubus_complete_request_async...\n");
|
||||||
if (!list_empty(&req->list))
|
if (!list_empty(&req->list))
|
||||||
@@ -1001,7 +1051,7 @@ void aw_ubus_complete_request_async (struct ubus_sync_context *ctx, struct ubus_
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void aw_ubus_req_complete_cb (struct ubus_request *req)
|
static void aw_ubus_req_complete_cb(struct ubus_request *req)
|
||||||
{
|
{
|
||||||
// printf ("==> aw_ubus_req_complete_cb\n");
|
// printf ("==> aw_ubus_req_complete_cb\n");
|
||||||
ubus_complete_handler_t cb = req->complete_cb;
|
ubus_complete_handler_t cb = req->complete_cb;
|
||||||
@@ -1015,7 +1065,7 @@ static void aw_ubus_req_complete_cb (struct ubus_request *req)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void aw_ubus_set_req_status (struct ubus_request *req, int ret)
|
static void aw_ubus_set_req_status(struct ubus_request *req, int ret)
|
||||||
{
|
{
|
||||||
// printf ("==> aw_ubus_set_req_status\n");
|
// printf ("==> aw_ubus_set_req_status\n");
|
||||||
//if (!list_empty(&req->list))
|
//if (!list_empty(&req->list))
|
||||||
@@ -1029,7 +1079,7 @@ static void aw_ubus_set_req_status (struct ubus_request *req, int ret)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int aw_ubus_start_request (struct ubus_sync_context *ctx, struct ubus_request *req,
|
int aw_ubus_start_request(struct ubus_sync_context *ctx, struct ubus_request *req,
|
||||||
struct blob_attr *msg, int cmd, uint32_t peer)
|
struct blob_attr *msg, int cmd, uint32_t peer)
|
||||||
{
|
{
|
||||||
memset(req, 0, sizeof(*req));
|
memset(req, 0, sizeof(*req));
|
||||||
@@ -1049,7 +1099,7 @@ int aw_ubus_start_request (struct ubus_sync_context *ctx, struct ubus_request *r
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request *req,
|
int aw_ubus_complete_request(struct ubus_sync_context *ctx, struct ubus_request *req,
|
||||||
int req_timeout)
|
int req_timeout)
|
||||||
{
|
{
|
||||||
ubus_complete_handler_t complete_cb = req->complete_cb;
|
ubus_complete_handler_t complete_cb = req->complete_cb;
|
||||||
@@ -1057,7 +1107,7 @@ int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request
|
|||||||
int status = UBUS_STATUS_NO_DATA;
|
int status = UBUS_STATUS_NO_DATA;
|
||||||
int64_t timeout = -1, time_end = 0;
|
int64_t timeout = -1, time_end = 0;
|
||||||
// printf ("==> aw_ubus_complete_request %p\n", req);
|
// printf ("==> aw_ubus_complete_request %p\n", req);
|
||||||
/*
|
/*
|
||||||
if (!registered) {
|
if (!registered) {
|
||||||
uloop_init();
|
uloop_init();
|
||||||
ubus_add_uloop(ctx);
|
ubus_add_uloop(ctx);
|
||||||
@@ -1071,23 +1121,26 @@ int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request
|
|||||||
|
|
||||||
// ctx->stack_depth++;
|
// ctx->stack_depth++;
|
||||||
// printf ("wait response ....\n");
|
// printf ("wait response ....\n");
|
||||||
while (!req->status_msg) {
|
while (!req->status_msg)
|
||||||
|
{
|
||||||
bool cancelled = uloop_cancelled;
|
bool cancelled = uloop_cancelled;
|
||||||
|
|
||||||
uloop_cancelled = false;
|
uloop_cancelled = false;
|
||||||
if (req_timeout) {
|
if (req_timeout)
|
||||||
|
{
|
||||||
timeout = time_end - aw_get_time_msec();
|
timeout = time_end - aw_get_time_msec();
|
||||||
if (timeout <= 0) {
|
if (timeout <= 0)
|
||||||
|
{
|
||||||
aw_ubus_set_req_status(req, UBUS_STATUS_TIMEOUT);
|
aw_ubus_set_req_status(req, UBUS_STATUS_TIMEOUT);
|
||||||
uloop_cancelled = cancelled;
|
uloop_cancelled = cancelled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aw_ubus_poll_data(ctx, (unsigned int) timeout);
|
aw_ubus_poll_data(ctx, (unsigned int)timeout);
|
||||||
|
|
||||||
uloop_cancelled = cancelled;
|
uloop_cancelled = cancelled;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
ctx->stack_depth--;
|
ctx->stack_depth--;
|
||||||
if (ctx->stack_depth)
|
if (ctx->stack_depth)
|
||||||
uloop_cancelled = true;
|
uloop_cancelled = true;
|
||||||
@@ -1101,7 +1154,7 @@ int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request
|
|||||||
if (req->complete_cb)
|
if (req->complete_cb)
|
||||||
req->complete_cb(req, status);
|
req->complete_cb(req, status);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (!registered) {
|
if (!registered) {
|
||||||
uloop_fd_delete(&ctx->sock);
|
uloop_fd_delete(&ctx->sock);
|
||||||
|
|
||||||
@@ -1114,7 +1167,7 @@ int aw_ubus_complete_request (struct ubus_sync_context *ctx, struct ubus_request
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int aw_ubus_invoke_async (struct ubus_sync_context *ctx, uint32_t obj, const char *method,
|
int aw_ubus_invoke_async(struct ubus_sync_context *ctx, uint32_t obj, const char *method,
|
||||||
struct blob_attr *msg, struct ubus_request *req)
|
struct blob_attr *msg, struct ubus_request *req)
|
||||||
{
|
{
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
@@ -1132,7 +1185,7 @@ int aw_ubus_invoke_async (struct ubus_sync_context *ctx, uint32_t obj, const cha
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int aw_ubus_lookup_id (struct ubus_sync_context *a_ctx, const char *a_path, uint32_t *an_id)
|
int aw_ubus_lookup_id(struct ubus_sync_context *a_ctx, const char *a_path, uint32_t *an_id)
|
||||||
{
|
{
|
||||||
struct ubus_request req;
|
struct ubus_request req;
|
||||||
int the_ret;
|
int the_ret;
|
||||||
@@ -1159,7 +1212,7 @@ int aw_ubus_lookup_id (struct ubus_sync_context *a_ctx, const char *a_path, uint
|
|||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// ubus_data_handler_t cb, void *priv,
|
// ubus_data_handler_t cb, void *priv,
|
||||||
int aw_ubus_invoke (struct ubus_sync_context *ctx, uint32_t obj, const char *method,
|
int aw_ubus_invoke(struct ubus_sync_context *ctx, uint32_t obj, const char *method,
|
||||||
struct blob_attr *msg, ubus_data_handler_t cb, void *priv, int timeout)
|
struct blob_attr *msg, ubus_data_handler_t cb, void *priv, int timeout)
|
||||||
{
|
{
|
||||||
struct ubus_request req;
|
struct ubus_request req;
|
||||||
@@ -1179,7 +1232,7 @@ int aw_ubus_invoke (struct ubus_sync_context *ctx, uint32_t obj, const char *met
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int aw_ubus_send_event (struct ubus_sync_context *ctx, const char *id, struct blob_attr *data)
|
int aw_ubus_send_event(struct ubus_sync_context *ctx, const char *id, struct blob_attr *data)
|
||||||
{
|
{
|
||||||
struct ubus_request req;
|
struct ubus_request req;
|
||||||
void *s;
|
void *s;
|
||||||
@@ -1200,59 +1253,60 @@ int aw_ubus_send_event (struct ubus_sync_context *ctx, const char *id, struct bl
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int ubus_sync_exec (const char *a_path, const char *a_method, const char *a_parameter, ubus_data_handler_t cb, void *priv)
|
int ubus_sync_exec(const char *a_path, const char *a_method, const char *a_parameter, ubus_data_handler_t cb, void *priv)
|
||||||
{
|
{
|
||||||
uint32_t the_id;
|
uint32_t the_id;
|
||||||
int the_ret;
|
int the_ret;
|
||||||
|
|
||||||
struct blob_buf the_buf = { 0 };
|
struct blob_buf the_buf = {0};
|
||||||
struct ubus_sync_context *the_ctx;
|
struct ubus_sync_context *the_ctx;
|
||||||
|
|
||||||
blob_buf_init(&the_buf, 0);
|
blob_buf_init(&the_buf, 0);
|
||||||
// printf ("==> ubus_exec: path:%s method:%s, parameter:%s\n", a_path, a_method, a_parameter);
|
// printf ("==> ubus_exec: path:%s method:%s, parameter:%s\n", a_path, a_method, a_parameter);
|
||||||
if (strlen(a_parameter) != 0) {
|
if (strlen(a_parameter) != 0)
|
||||||
if (!blobmsg_add_json_from_string (&the_buf, a_parameter)) {
|
{
|
||||||
|
if (!blobmsg_add_json_from_string(&the_buf, a_parameter))
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
the_ctx = aw_new_ubus_connect();
|
the_ctx = aw_new_ubus_connect();
|
||||||
|
|
||||||
the_ret = aw_ubus_lookup_id (the_ctx, a_path, &the_id);
|
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);
|
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);
|
aw_ubus_free(the_ctx);
|
||||||
blob_buf_free (&the_buf);
|
blob_buf_free(&the_buf);
|
||||||
return the_ret;
|
return the_ret;
|
||||||
}
|
}
|
||||||
// printf ("====> ID ici: %d\n", the_id);
|
// printf ("====> ID ici: %d\n", the_id);
|
||||||
|
|
||||||
the_ret = aw_ubus_invoke (the_ctx, the_id, a_method, the_buf.head, cb, priv, 5 * 1000);
|
the_ret = aw_ubus_invoke(the_ctx, the_id, a_method, the_buf.head, cb, priv, 5 * 1000);
|
||||||
|
|
||||||
aw_ubus_free(the_ctx);
|
aw_ubus_free(the_ctx);
|
||||||
blob_buf_free (&the_buf);
|
blob_buf_free(&the_buf);
|
||||||
// printf ("<== ubus_exec:\n");
|
// printf ("<== ubus_exec:\n");
|
||||||
return the_ret;
|
return the_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int ubus_sync_send_event (const char *an_event, const char *a_data)
|
int ubus_sync_send_event(const char *an_event, const char *a_data)
|
||||||
{
|
{
|
||||||
int the_ret = 0;
|
int the_ret = 0;
|
||||||
struct blob_buf the_buf = { 0 };
|
struct blob_buf the_buf = {0};
|
||||||
struct ubus_sync_context *the_ctx;
|
struct ubus_sync_context *the_ctx;
|
||||||
|
|
||||||
// printf("%s => (%s>\n", __PRETTY_FUNCTION__, a_data);
|
// printf("%s => (%s>\n", __PRETTY_FUNCTION__, a_data);
|
||||||
|
|
||||||
the_ctx = aw_new_ubus_connect();
|
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__);
|
fprintf(stderr, "%s - Failed to create an ubus context.\n", __PRETTY_FUNCTION__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,9 @@
|
|||||||
|
|
||||||
#include <libubus.h> // temporary for ubus_data_handler_t
|
#include <libubus.h> // temporary for ubus_data_handler_t
|
||||||
|
|
||||||
double time_diff (struct timeval x , struct timeval y);
|
double time_diff(struct timeval x, struct timeval y);
|
||||||
|
|
||||||
int ubus_sync_exec (const char *a_path, const char* a_method, const char *a_parameter, ubus_data_handler_t cb, void *priv);
|
int ubus_sync_exec(const char *a_path, const char *a_method, const char *a_parameter, ubus_data_handler_t cb, void *priv);
|
||||||
int ubus_sync_send_event (const char *an_event, const char *a_data);
|
int ubus_sync_send_event(const char *an_event, const char *a_data);
|
||||||
|
|
||||||
#endif /* _AW_UBUS_SYNC_H */
|
#endif /* _AW_UBUS_SYNC_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user