import uhttpd-rest-api
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
menuconfig BR2_PACKAGE_UHTTPD_REST_API_PLUGIN
|
||||
bool "uhttpd rest api plugin"
|
||||
select BR2_PACKAGE_UHTTPD_3P
|
||||
select BR2_PACKAGE_UBUS
|
||||
select BR2_PACKAGE_JSON_C
|
||||
select BR2_PACKAGE_LIBFMT
|
||||
select BR2_PACKAGE_LIBUBUS_CPP
|
||||
default n
|
||||
help
|
||||
Enable the rest api uhttpd plugin.
|
||||
@@ -0,0 +1,19 @@
|
||||
################################################################################
|
||||
#
|
||||
# UHTTPD REST API PLUGIN
|
||||
#
|
||||
################################################################################
|
||||
|
||||
UHTTPD_REST_API_PLUGIN_VERSION:= 1.0.0
|
||||
|
||||
UHTTPD_REST_API_PLUGIN_SITE = $(TOPDIR)/../../src/plugins/uhttpd/uhttpd-rest-api/builders/cmake
|
||||
|
||||
UHTTPD_REST_API_PLUGIN_SITE_METHOD = local
|
||||
UHTTPD_REST_API_PLUGIN_INSTALL_TARGET = YES
|
||||
UHTTPD_REST_API_PLUGIN_INSTALL_STAGING = YES
|
||||
|
||||
UHTTPD_REST_API_PLUGIN_DEPENDENCIES = uhttpd-3p ubus json-c libfmt libubus-cpp
|
||||
|
||||
UHTTPD_REST_API_PLUGIN_CONF_OPTS += -DworkspaceRoot=$(TOPDIR)/../.. -DMODULE_PATH=$(TOPDIR)/../../bsp/cmake-modules -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
|
||||
|
||||
$(eval $(cmake-package))
|
||||
@@ -1,85 +1,56 @@
|
||||
cmake_minimum_required (VERSION 3.0)
|
||||
|
||||
project (uhttpd-awox-api-plugin)
|
||||
project (uhttpd-rest-api-plugin)
|
||||
|
||||
set (CMAKE_MODULE_PATH "${MODULE_PATH}")
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
include (aw)
|
||||
include (br)
|
||||
|
||||
include_directories ($ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/)
|
||||
include_directories (${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/)
|
||||
|
||||
file (
|
||||
GLOB_RECURSE
|
||||
source_files
|
||||
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/plugin.c
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/uhttp-server.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/plugin.c
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.cpp
|
||||
# core
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/http-reason.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/http-parameter.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/http-header.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/uri-transform.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/web-controller.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/web-connection.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/ubus-connection.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/core/ubus-reason.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-reason.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-parameter.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-header.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/uri-transform.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/web-connection.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-connection.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-reason.cpp
|
||||
# rest
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/rest/rest-controller.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/rest/rest-connection.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.cpp
|
||||
#etag-rest
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/etag-rest/etag-rest-controller.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/etag-rest/etag-rest-connection.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-controller.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.cpp
|
||||
# notification
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/notification/notification-controller.cpp
|
||||
$ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/notification/notification-connection.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-controller.cpp
|
||||
${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.cpp
|
||||
)
|
||||
|
||||
add_library (awox-api-plugin SHARED ${source_files})
|
||||
add_library (rest-api-plugin SHARED ${source_files})
|
||||
|
||||
target_link_libraries (awox-api-plugin
|
||||
target_link_libraries (rest-api-plugin
|
||||
LINK_PUBLIC
|
||||
ubus
|
||||
ubox
|
||||
blobmsg_json
|
||||
json-c
|
||||
fmt
|
||||
aw-ubus
|
||||
ubus-cpp
|
||||
)
|
||||
|
||||
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
|
||||
|
||||
set_target_properties (awox-api-plugin PROPERTIES PREFIX "uhttpd_")
|
||||
set_target_properties (rest-api-plugin PROPERTIES PREFIX "uhttpd_")
|
||||
|
||||
target_include_directories (awox-api-plugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
install (TARGETS awox-api-plugin LIBRARY DESTINATION local/bin/Plugins/)
|
||||
|
||||
if (INSTALL_CORE)
|
||||
install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/core.json DESTINATION local/configs/restd/)
|
||||
endif ()
|
||||
|
||||
if (INSTALL_SPOTIFY)
|
||||
install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/spotify.json DESTINATION local/configs/restd/)
|
||||
endif ()
|
||||
|
||||
if (INSTALL_DEAP)
|
||||
install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/deap.json DESTINATION local/configs/restd/)
|
||||
endif ()
|
||||
|
||||
if (INSTALL_LIGHT)
|
||||
install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/light.json DESTINATION local/configs/restd/)
|
||||
endif ()
|
||||
|
||||
if (INSTALL_LIGHT_COLOR)
|
||||
install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/light-color.json DESTINATION local/configs/restd/)
|
||||
endif ()
|
||||
|
||||
if (INSTALL_LIGHT_WHITE)
|
||||
install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/light-white.json DESTINATION local/configs/restd/)
|
||||
endif ()
|
||||
|
||||
if (INSTALL_VOICE_CONTROL)
|
||||
install (FILES $ENV{AWOXCVS}/AwoxAudio/Plugins/uhttpd/uhttpd-awox-api/configs/voice-control.json DESTINATION local/configs/restd/)
|
||||
endif ()
|
||||
target_include_directories (rest-api-plugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
install (TARGETS rest-api-plugin LIBRARY DESTINATION local/bin/plugins/)
|
||||
|
||||
@@ -22,7 +22,11 @@
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <aw-ubus/UBusCall.h>
|
||||
extern "C" {
|
||||
#include <libubus.h>
|
||||
}
|
||||
|
||||
#include <ubus-cpp/ubus-call.h>
|
||||
|
||||
#include "ubus-reason.h"
|
||||
|
||||
|
||||
@@ -33,6 +33,13 @@ struct client;
|
||||
struct uhttpd_ops;
|
||||
struct ubus_context;
|
||||
|
||||
/*----------------------------- Dependencies --------------------------------*/
|
||||
|
||||
#define kEvent_status_entry "status"
|
||||
#define kEvent_version_entry "version"
|
||||
#define kEvent_content_entry "content"
|
||||
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class WebConnection {
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
#include <aw-ubus/UBusCall.h>
|
||||
#include <ubus-cpp/ubus-call.h>
|
||||
|
||||
#include <mozart/event/messages.h>
|
||||
//#include <mozart/event/messages.h>
|
||||
|
||||
#include "etag-rest/etag-rest-controller.h"
|
||||
|
||||
@@ -90,7 +90,7 @@ EtagRestConnection::~EtagRestConnection (void)
|
||||
void EtagRestConnection::invoke (struct ubus_context *a_ctx)
|
||||
{
|
||||
uint32_t the_id = 0;
|
||||
awUBusCall the_cmd;
|
||||
UBusCall the_cmd;
|
||||
std::string the_method;
|
||||
|
||||
m_ctx = a_ctx;
|
||||
@@ -103,7 +103,7 @@ void EtagRestConnection::invoke (struct ubus_context *a_ctx)
|
||||
if (!ubus_lookup_id(a_ctx, m_controller->get_path().c_str(), &the_id)) {
|
||||
|
||||
// printf ("%s launch async call (%s)(%s)....\n", __PRETTY_FUNCTION__, the_method.c_str(), m_parameters.c_str());
|
||||
the_cmd.ExecAsync(a_ctx, the_id, the_method, m_parameters, this);
|
||||
the_cmd.exec_async(a_ctx, the_id, the_method, m_parameters, this);
|
||||
}
|
||||
|
||||
if (m_client->request.method == UH_HTTP_MSG_GET) {
|
||||
@@ -186,7 +186,7 @@ int EtagRestConnection::parse_parameter (void)
|
||||
the_content_node = json_tokener_parse(m_connection_data.c_str());
|
||||
if (the_content_node != NULL) {
|
||||
|
||||
json_object_object_add(the_root_node, kEvent_Message_content_entry, the_content_node);
|
||||
json_object_object_add(the_root_node, kEvent_content_entry, the_content_node);
|
||||
}
|
||||
|
||||
m_parameters = json_object_to_json_string(the_root_node);
|
||||
@@ -223,13 +223,13 @@ void EtagRestConnection::manage_response (std::string a_response_data)
|
||||
}
|
||||
|
||||
// get status
|
||||
if (json_object_object_get_ex(the_root_node, kEvent_Message_status_entry, &the_status_node)) {
|
||||
if (json_object_object_get_ex(the_root_node, kEvent_status_entry, &the_status_node)) {
|
||||
|
||||
the_result_code = json_object_get_int(the_status_node);
|
||||
}
|
||||
|
||||
// get etag.
|
||||
if (json_object_object_get_ex(the_root_node, kEvent_Message_version_entry, &the_etag_node)) {
|
||||
if (json_object_object_get_ex(the_root_node, kEvent_version_entry, &the_etag_node)) {
|
||||
|
||||
enum json_type the_json_type;
|
||||
|
||||
@@ -249,7 +249,7 @@ void EtagRestConnection::manage_response (std::string a_response_data)
|
||||
|
||||
// get contents
|
||||
the_content_node = NULL;
|
||||
if (!json_object_object_get_ex(the_root_node, kEvent_Message_content_entry, &the_content_node)) {
|
||||
if (!json_object_object_get_ex(the_root_node, kEvent_content_entry, &the_content_node)) {
|
||||
|
||||
the_content_node = the_root_node;
|
||||
}
|
||||
|
||||
@@ -27,23 +27,22 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <aw-ubus/UloopTimer.h>
|
||||
#include <aw-ubus/UBusExecReceiver.h>
|
||||
#include "aw-ubus/UBusEventReceiver.h"
|
||||
#include <aw-ubus/UBusEvent.h>
|
||||
#include <ubus-cpp/uloop-timer.h>
|
||||
#include <ubus-cpp/ubus-exec-receiver.h>
|
||||
#include "ubus-cpp/ubus-event-receiver.h"
|
||||
#include <ubus-cpp/ubus-event.h>
|
||||
|
||||
#include "core/http-header.h"
|
||||
|
||||
#include "core/web-connection.h"
|
||||
|
||||
/*----------------------------- Dependencies --------------------------------*/
|
||||
|
||||
class EtagRestController;
|
||||
struct ubus_context;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class EtagRestConnection : public WebConnection, public awUBusExecReceiver, public awUBusEventReceiver, public ULoopTimer {
|
||||
class EtagRestConnection : public WebConnection, public UBusExecReceiver, public UBusEventReceiver, public ULoopTimer {
|
||||
|
||||
public:
|
||||
EtagRestConnection (struct uhttpd_ops *an_ops, struct client *a_client, EtagRestController *a_controller, const std::string &a_parameters);
|
||||
|
||||
@@ -29,8 +29,6 @@ extern "C" {
|
||||
#include <uhttpd/uhttpd.h>
|
||||
#include <uhttpd/plugin.h>
|
||||
|
||||
#include <notification-center/StringNotification.h>
|
||||
|
||||
#include "core/http-reason.h"
|
||||
|
||||
#include "notification/notification-controller.h"
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <aw-ubus/UloopTimer.h>
|
||||
#include "aw-ubus/UBusEventReceiver.h"
|
||||
#include <ubus-cpp/uloop-timer.h>
|
||||
#include <ubus-cpp/ubus-event-receiver.h>
|
||||
|
||||
#include "core/web-connection.h"
|
||||
|
||||
/*----------------------------- Dependencies --------------------------------*/
|
||||
@@ -36,7 +37,7 @@ struct ubus_context;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class NotificationConnection : public WebConnection, public awUBusEventReceiver, public ULoopTimer {
|
||||
class NotificationConnection : public WebConnection, public UBusEventReceiver, public ULoopTimer {
|
||||
|
||||
public:
|
||||
NotificationConnection (struct uhttpd_ops *an_ops, struct client *a_client, NotificationController *a_controller);
|
||||
@@ -45,7 +46,7 @@ public:
|
||||
// WebConnection
|
||||
void invoke (struct ubus_context *a_ctx);
|
||||
|
||||
// awUBusEventReceiver
|
||||
// UBusEventReceiver
|
||||
void handle_event (const char *a_type, const char *a_json_msg);
|
||||
|
||||
// Timer.
|
||||
|
||||
@@ -24,14 +24,14 @@
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
#include <mozart/event/messages.h>
|
||||
//#include <mozart/event/messages.h>
|
||||
|
||||
extern "C" {
|
||||
#include <uhttpd/uhttpd.h>
|
||||
#include <uhttpd/plugin.h>
|
||||
}
|
||||
|
||||
#include <aw-ubus/UBusCall.h>
|
||||
#include <ubus-cpp/ubus-call.h>
|
||||
|
||||
#include "core/http-reason.h"
|
||||
#include "core/http-parameter.h"
|
||||
@@ -97,7 +97,7 @@ void RestConnection::complete (void)
|
||||
void RestConnection::invoke (struct ubus_context *a_ctx)
|
||||
{
|
||||
uint32_t the_id = 0;
|
||||
awUBusCall the_cmd;
|
||||
UBusCall the_cmd;
|
||||
std::string the_method;
|
||||
|
||||
m_ctx = a_ctx;
|
||||
@@ -114,7 +114,7 @@ void RestConnection::invoke (struct ubus_context *a_ctx)
|
||||
the_parameter_doc = parse_form_encoded_data();
|
||||
|
||||
// printf("RestConnection::invoke launch async call (%d)....\n", the_id);
|
||||
the_cmd.ExecAsync(a_ctx, the_id, the_method, json_object_to_json_string(the_parameter_doc), this);
|
||||
the_cmd.exec_async(a_ctx, the_id, the_method, json_object_to_json_string(the_parameter_doc), this);
|
||||
|
||||
json_object_put(the_parameter_doc);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ void RestConnection::send_response(int a_result_code, std::string a_content_docu
|
||||
}
|
||||
|
||||
json_object_object_add(the_root_node, "id", json_object_new_string(m_controller->get_name().c_str()));
|
||||
json_object_object_add(the_root_node, kEvent_Message_status_entry, json_object_new_string(the_status.c_str()));
|
||||
json_object_object_add(the_root_node, kEvent_status_entry, json_object_new_string(the_status.c_str()));
|
||||
json_object_object_add(the_root_node, "response_code", json_object_new_int(a_result_code));
|
||||
|
||||
the_http_header.send(m_ops, m_client, a_result_code);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "core/web-connection.h"
|
||||
|
||||
#include <aw-ubus/UBusExecReceiver.h>
|
||||
#include <ubus-cpp/ubus-exec-receiver.h>
|
||||
|
||||
/*----------------------------- Dependencies --------------------------------*/
|
||||
|
||||
@@ -39,7 +39,7 @@ struct json_object;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class RestConnection : public WebConnection, public awUBusExecReceiver {
|
||||
class RestConnection : public WebConnection, public UBusExecReceiver {
|
||||
|
||||
public:
|
||||
RestConnection (struct uhttpd_ops *an_ops, struct client *a_client, RestController *a_controller, const std::string &a_parameters);
|
||||
|
||||
Reference in New Issue
Block a user