Backup:AppManager.
This commit is contained in:
parent
1046ac2eff
commit
3964a430ec
|
@ -55,3 +55,7 @@ set(CROSS_COMPILE_PREFIX "")
|
||||||
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
||||||
set(CURL_SHARED_LIBS_PATH "/mnt/mmc")
|
set(CURL_SHARED_LIBS_PATH "/mnt/mmc")
|
||||||
# ------------ build curl + openssl ------------ end
|
# ------------ build curl + openssl ------------ end
|
||||||
|
# ------------ build AppManager ------------ #
|
||||||
|
set(APP_MANAGER_HTTP_SERVER_IP "localhost")
|
||||||
|
set(APP_MANAGER_HTTP_SERVER_PORT "8888")
|
||||||
|
# ------------ build AppManager end ------------ #
|
|
@ -11,18 +11,31 @@ include_directories(
|
||||||
${UTILS_SOURCE_PATH}/FxHttpServer/include
|
${UTILS_SOURCE_PATH}/FxHttpServer/include
|
||||||
${UTILS_SOURCE_PATH}/WebServer/include
|
${UTILS_SOURCE_PATH}/WebServer/include
|
||||||
${HAL_SOURCE_PATH}/include
|
${HAL_SOURCE_PATH}/include
|
||||||
|
${EXTERNAL_SOURCE_PATH}/cJSON-1.7.17
|
||||||
)
|
)
|
||||||
#do not rely on any other library
|
#do not rely on any other library
|
||||||
#link_directories(
|
#link_directories(
|
||||||
#)
|
#)
|
||||||
|
|
||||||
|
if (NOT DEFINED APP_MANAGER_HTTP_SERVER_IP)
|
||||||
|
set(APP_MANAGER_HTTP_SERVER_IP "localhost")
|
||||||
|
endif()
|
||||||
|
add_definitions(-DAPP_MANAGER_HTTP_SERVER_IP=\"${APP_MANAGER_HTTP_SERVER_IP}\")
|
||||||
|
|
||||||
|
if (NOT DEFINED APP_MANAGER_HTTP_SERVER_PORT)
|
||||||
|
message(FATAL_ERROR "You should set http listen port.
|
||||||
|
Example: set(APP_MANAGER_HTTP_SERVER_PORT \"8888\")
|
||||||
|
Refer to:${CMAKE_SOURCE_DIR_IPCSDK}/builde/cmake/toolchain/linux.toolchain.cmake")
|
||||||
|
endif()
|
||||||
|
add_definitions(-DAPP_MANAGER_HTTP_SERVER_PORT=${APP_MANAGER_HTTP_SERVER_PORT})
|
||||||
|
|
||||||
aux_source_directory(./src SRC_FILES)
|
aux_source_directory(./src SRC_FILES)
|
||||||
aux_source_directory(./src/Protocol/SixFrame SRC_FILES)
|
aux_source_directory(./src/Protocol/SixFrame SRC_FILES)
|
||||||
|
|
||||||
set(TARGET_NAME AppManager)
|
set(TARGET_NAME AppManager)
|
||||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||||
|
|
||||||
target_link_libraries(${TARGET_NAME} WebServer StatusCode Log)
|
target_link_libraries(${TARGET_NAME} WebServer cjson-static StatusCode Log)
|
||||||
|
|
||||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
|
|
@ -70,7 +70,8 @@ void AppManager::HttpServerThread(void)
|
||||||
};
|
};
|
||||||
// FxHttpServerInit(httpHandle, 8080);
|
// FxHttpServerInit(httpHandle, 8080);
|
||||||
// FxHttpServerUnInit();
|
// FxHttpServerUnInit();
|
||||||
WebServerParam web = {.mIp = "192.168.1.29", .mPort = 8888, .mHttpRequestHandle = httpHandle};
|
WebServerParam web = {
|
||||||
|
.mIp = APP_MANAGER_HTTP_SERVER_IP, .mPort = APP_MANAGER_HTTP_SERVER_PORT, .mHttpRequestHandle = httpHandle};
|
||||||
WebServerInit(web);
|
WebServerInit(web);
|
||||||
WebServerUnInit();
|
WebServerUnInit();
|
||||||
}
|
}
|
|
@ -14,15 +14,17 @@
|
||||||
*/
|
*/
|
||||||
#include "SixFrameHandle.h"
|
#include "SixFrameHandle.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
|
#include "cJSON.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
using std::placeholders::_1;
|
using std::placeholders::_1;
|
||||||
using std::placeholders::_2;
|
using std::placeholders::_2;
|
||||||
using std::placeholders::_3;
|
using std::placeholders::_3;
|
||||||
// using std::placeholders::_4;
|
// using std::placeholders::_4;
|
||||||
|
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
|
||||||
SixFrameHandle::SixFrameHandle()
|
SixFrameHandle::SixFrameHandle()
|
||||||
{
|
{
|
||||||
mResquesHandleFunc["/app/getproductinfo"] = std::bind(&SixFrameHandle::RequestGetProductInfo, this, _1, _2, _3);
|
mResquesHandleFunc[APP_GET_PRODUCT_INFO] = std::bind(&SixFrameHandle::RequestGetProductInfo, this, _1, _2, _3);
|
||||||
// mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _3);
|
// mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _3);
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||||
|
@ -83,7 +85,7 @@ void SixFrameHandle::DoNothing(std::multimap<std::string, std::string> ¶msMa
|
||||||
void SixFrameHandle::RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap,
|
void SixFrameHandle::RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap,
|
||||||
ResponseHandle responseHandle, void *context)
|
ResponseHandle responseHandle, void *context)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
LogInfo("RequestGetProductInfo.\n");
|
LogInfo("RequestGetProductInfo.\n");
|
||||||
responseHandle("hello world.", context);
|
responseHandle("hello world.", context);
|
||||||
|
// cJSON *monitor = cJSON_CreateObject();
|
||||||
}
|
}
|
|
@ -51,9 +51,9 @@ public:
|
||||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo)
|
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo)
|
||||||
{
|
{
|
||||||
IAppManager::GetInstance()->Init();
|
IAppManager::GetInstance()->Init();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
MockGetProductInfo();
|
MockGetProductInfo();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
IAppManager::GetInstance()->UnInit();
|
IAppManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
} // namespace AppManagerTest
|
} // namespace AppManagerTest
|
|
@ -17,6 +17,18 @@ include_directories(
|
||||||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
if (NOT DEFINED APP_MANAGER_HTTP_SERVER_IP)
|
||||||
|
set(APP_MANAGER_HTTP_SERVER_IP "localhost")
|
||||||
|
endif()
|
||||||
|
add_definitions(-DAPP_MANAGER_HTTP_SERVER_IP=\"${APP_MANAGER_HTTP_SERVER_IP}\")
|
||||||
|
|
||||||
|
if (NOT DEFINED APP_MANAGER_HTTP_SERVER_PORT)
|
||||||
|
message(FATAL_ERROR "You should set http listen port.
|
||||||
|
Example: set(APP_MANAGER_HTTP_SERVER_PORT \"8888\")
|
||||||
|
Refer to:${CMAKE_SOURCE_DIR_IPCSDK}/builde/cmake/toolchain/linux.toolchain.cmake")
|
||||||
|
endif()
|
||||||
|
add_definitions(-DAPP_MANAGER_HTTP_SERVER_PORT=${APP_MANAGER_HTTP_SERVER_PORT})
|
||||||
|
|
||||||
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
||||||
set(TEST_TOOL_TARGET AppManagerTestTool)
|
set(TEST_TOOL_TARGET AppManagerTestTool)
|
||||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include "ServersMock.h"
|
#include "ServersMock.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "servers.h"
|
#include "servers.h"
|
||||||
|
#include <cstring>
|
||||||
|
extern const char *APP_GET_PRODUCT_INFO;
|
||||||
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
|
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<ServersMock>();
|
static auto instance = std::make_shared<ServersMock>();
|
||||||
|
@ -29,46 +31,29 @@ std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMo
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
#include <arpa/inet.h>
|
ServersMock::ServersMock()
|
||||||
#include <cstring>
|
|
||||||
#include <iostream>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
static int GetIp(void)
|
|
||||||
{
|
{
|
||||||
char hostname[256];
|
//
|
||||||
if (gethostname(hostname, sizeof(hostname)) == -1) {
|
mServerUrl = APP_MANAGER_HTTP_SERVER_IP ":" + std::to_string(APP_MANAGER_HTTP_SERVER_PORT);
|
||||||
std::cout << "Failed to get hostname." << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct hostent *hostent = gethostbyname(hostname);
|
|
||||||
if (hostent == nullptr || hostent->h_addr_list[0] == nullptr) {
|
|
||||||
std::cout << "Failed to get IP address." << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct in_addr **addr_list = reinterpret_cast<struct in_addr **>(hostent->h_addr_list);
|
|
||||||
for (int i = 0; addr_list[i] != nullptr; ++i) {
|
|
||||||
std::cout << inet_ntoa(*addr_list[i]) << std::endl;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
void ServersMock::MockGetProductInfo(void)
|
void ServersMock::MockGetProductInfo(void)
|
||||||
{
|
{
|
||||||
GetIp();
|
|
||||||
ServerParam init = {
|
ServerParam init = {
|
||||||
.logFlag = LOG_FLAG_ENABLE,
|
.logFlag = LOG_FLAG_ENABLE,
|
||||||
.sslVerifyFlag = SSL_VERIFY_DISABLE,
|
.sslVerifyFlag = SSL_VERIFY_DISABLE,
|
||||||
};
|
};
|
||||||
ServersInit(init);
|
ServersInit(init);
|
||||||
LogInfo("servers test start.\n");
|
LogInfo("servers test start.\n");
|
||||||
ServerHttp *http = NewServersHttp("http:192.168.1.29:80/app/test");
|
std::string mockRequest = mServerUrl + APP_GET_PRODUCT_INFO;
|
||||||
|
ServerHttp *http = NewServersHttp(mockRequest.c_str());
|
||||||
if (http) {
|
if (http) {
|
||||||
HttpGet(http);
|
HttpGet(http);
|
||||||
if (http->reply) {
|
if (http->reply) {
|
||||||
LogInfo("HttpGet ========\n %s\n", http->reply);
|
char *replyStr = (char *)malloc(http->replyLength + 1);
|
||||||
|
memset(replyStr, 0, http->replyLength + 1);
|
||||||
|
memcpy(replyStr, http->reply, http->replyLength);
|
||||||
|
LogInfo("HttpGet response : %s\n", replyStr);
|
||||||
|
free(replyStr);
|
||||||
}
|
}
|
||||||
DeleteServersHttp(http);
|
DeleteServersHttp(http);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
class ServersMock
|
class ServersMock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServersMock() = default;
|
ServersMock();
|
||||||
virtual ~ServersMock() = default;
|
virtual ~ServersMock() = default;
|
||||||
static std::shared_ptr<ServersMock> &GetInstance(std::shared_ptr<ServersMock> *impl = nullptr);
|
static std::shared_ptr<ServersMock> &GetInstance(std::shared_ptr<ServersMock> *impl = nullptr);
|
||||||
virtual void MockGetProductInfo(void);
|
virtual void MockGetProductInfo(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string mServerUrl;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -67,7 +67,6 @@ static bool AppRequestHandle(Webs *wp)
|
||||||
gHttpHandle(wp->url, 0, response_handle, wp);
|
gHttpHandle(wp->url, 0, response_handle, wp);
|
||||||
websDone(wp);
|
websDone(wp);
|
||||||
return 1;
|
return 1;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
StatusCode WebServerInit(const WebServerParam webParam)
|
StatusCode WebServerInit(const WebServerParam webParam)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user