Backup:AppManager.
This commit is contained in:
parent
1046ac2eff
commit
3964a430ec
|
@ -54,4 +54,8 @@ set(CROSS_COMPILE_PREFIX "")
|
|||
# set(CROSS_COMPILE_PREFIX "")
|
||||
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
||||
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}/WebServer/include
|
||||
${HAL_SOURCE_PATH}/include
|
||||
${EXTERNAL_SOURCE_PATH}/cJSON-1.7.17
|
||||
)
|
||||
#do not rely on any other library
|
||||
#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/Protocol/SixFrame SRC_FILES)
|
||||
|
||||
set(TARGET_NAME AppManager)
|
||||
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")
|
||||
add_custom_target(
|
||||
|
|
|
@ -70,7 +70,8 @@ void AppManager::HttpServerThread(void)
|
|||
};
|
||||
// FxHttpServerInit(httpHandle, 8080);
|
||||
// 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);
|
||||
WebServerUnInit();
|
||||
}
|
|
@ -14,15 +14,17 @@
|
|||
*/
|
||||
#include "SixFrameHandle.h"
|
||||
#include "ILog.h"
|
||||
#include "cJSON.h"
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
using std::placeholders::_3;
|
||||
// using std::placeholders::_4;
|
||||
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
|
||||
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);
|
||||
}
|
||||
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,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
//
|
||||
LogInfo("RequestGetProductInfo.\n");
|
||||
responseHandle("hello world.", context);
|
||||
// cJSON *monitor = cJSON_CreateObject();
|
||||
}
|
|
@ -51,9 +51,9 @@ public:
|
|||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo)
|
||||
{
|
||||
IAppManager::GetInstance()->Init();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetProductInfo();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
} // namespace AppManagerTest
|
|
@ -17,6 +17,18 @@ include_directories(
|
|||
# ${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)
|
||||
set(TEST_TOOL_TARGET AppManagerTestTool)
|
||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "ServersMock.h"
|
||||
#include "ILog.h"
|
||||
#include "servers.h"
|
||||
#include <cstring>
|
||||
extern const char *APP_GET_PRODUCT_INFO;
|
||||
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<ServersMock>();
|
||||
|
@ -29,46 +31,29 @@ std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMo
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
#include <arpa/inet.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
static int GetIp(void)
|
||||
ServersMock::ServersMock()
|
||||
{
|
||||
char hostname[256];
|
||||
if (gethostname(hostname, sizeof(hostname)) == -1) {
|
||||
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;
|
||||
//
|
||||
mServerUrl = APP_MANAGER_HTTP_SERVER_IP ":" + std::to_string(APP_MANAGER_HTTP_SERVER_PORT);
|
||||
}
|
||||
void ServersMock::MockGetProductInfo(void)
|
||||
{
|
||||
GetIp();
|
||||
ServerParam init = {
|
||||
.logFlag = LOG_FLAG_ENABLE,
|
||||
.sslVerifyFlag = SSL_VERIFY_DISABLE,
|
||||
};
|
||||
ServersInit(init);
|
||||
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) {
|
||||
HttpGet(http);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -18,9 +18,12 @@
|
|||
class ServersMock
|
||||
{
|
||||
public:
|
||||
ServersMock() = default;
|
||||
ServersMock();
|
||||
virtual ~ServersMock() = default;
|
||||
static std::shared_ptr<ServersMock> &GetInstance(std::shared_ptr<ServersMock> *impl = nullptr);
|
||||
virtual void MockGetProductInfo(void);
|
||||
|
||||
private:
|
||||
std::string mServerUrl;
|
||||
};
|
||||
#endif
|
|
@ -67,7 +67,6 @@ static bool AppRequestHandle(Webs *wp)
|
|||
gHttpHandle(wp->url, 0, response_handle, wp);
|
||||
websDone(wp);
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
StatusCode WebServerInit(const WebServerParam webParam)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user