Goahead demo ok.

This commit is contained in:
fancy 2023-12-21 06:23:25 -08:00
parent 20be0d73ed
commit b3b4e80931
2 changed files with 43 additions and 4 deletions

View File

@ -25,7 +25,7 @@ TEST(WebServerTest, Demo)
CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END);
WebServerInit();
std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 10));
// std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 10));
ILogUnInit();
}
} // namespace WebServerTest

View File

@ -13,11 +13,33 @@
* limitations under the License.
*/
#include "WebServer.h"
#include "ILog.h"
#include "goahead.h"
#include "js.h"
#include <signal.h>
static int finished = 0;
static void sigHandler(int signo) { finished = 1; }
static void sigHandler(int signo)
{
LogInfo("Stop goahead web server.\n");
finished = 1;
}
static void logHeader(void)
{
char home[ME_GOAHEAD_LIMIT_STRING];
getcwd(home, sizeof(home));
logmsg(2, "Configuration for %s", ME_TITLE);
logmsg(2, "---------------------------------------------");
logmsg(2, "Version: %s", ME_VERSION);
logmsg(2, "BuildType: %s", ME_DEBUG ? "Debug" : "Release");
logmsg(2, "CPU: %s", ME_CPU);
logmsg(2, "OS: %s", ME_OS);
logmsg(2, "Host: %s", websGetServer());
logmsg(2, "Directory: %s", home);
logmsg(2, "Documents: %s", websGetDocuments());
logmsg(2, "Configure: %s", ME_CONFIG_CMD);
logmsg(2, "---------------------------------------------");
}
void initPlatform(void)
{
signal(SIGINT, sigHandler);
@ -28,13 +50,30 @@ void initPlatform(void)
StatusCode WebServerInit(void)
{
websSetDebug(1);
logSetPath("stdout:2");
const char *documents = ME_GOAHEAD_DOCUMENTS;
const char *route = "route.txt";
const char *route =
"/home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/external/goahead-5.2.0/GoAhead/test/route.txt";
// /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/external/goahead-5.2.0/GoAhead/test/route.txt
const char *auth =
"/home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/external/goahead-5.2.0/GoAhead/test/auth.txt";
initPlatform();
if (websOpen(documents, route) < 0) {
error("Cannot initialize server. Exiting.");
LogError("Cannot initialize server. Exiting.\n");
return CreateStatusCode(STATUS_CODE_NOT_OK);
}
logHeader();
if (websLoad(auth) < 0) {
LogError("Cannot load %s", auth);
return CreateStatusCode(STATUS_CODE_NOT_OK);
}
if (websListen("192.168.1.189:8080") < 0) {
return CreateStatusCode(STATUS_CODE_NOT_OK);
}
websServiceEvents(&finished);
logmsg(1, "Instructed to exit\n");
websClose();
return CreateStatusCode(STATUS_CODE_OK);
}
StatusCode WebServerUnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }