mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
MessagePage setup.
This commit is contained in:
parent
863599e554
commit
6dd235c077
8
main.cpp
8
main.cpp
@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
#include "rdn_application.h"
|
#include "rdn_application.h"
|
||||||
|
|
||||||
#include "modules/message_page/message_page.h"
|
|
||||||
|
|
||||||
#include "core/database_manager.h"
|
#include "core/database_manager.h"
|
||||||
|
|
||||||
#include "database/db_init.h"
|
#include "database/db_init.h"
|
||||||
@ -32,10 +30,6 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
HTTPServer *server = new HTTPServer();
|
HTTPServer *server = new HTTPServer();
|
||||||
|
|
||||||
MessagePage *mp = new MessagePage();
|
|
||||||
|
|
||||||
printf("%s\n", mp->get_class().c_str());
|
|
||||||
|
|
||||||
server->port = 8080;
|
server->port = 8080;
|
||||||
server->initialize();
|
server->initialize();
|
||||||
server->main_loop();
|
server->main_loop();
|
||||||
@ -44,8 +38,6 @@ int main(int argc, char **argv) {
|
|||||||
delete app;
|
delete app;
|
||||||
delete dbm;
|
delete dbm;
|
||||||
delete file_cache;
|
delete file_cache;
|
||||||
delete mp;
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
Import("env_mod")
|
Import("env_mod")
|
||||||
|
Import("env")
|
||||||
|
|
||||||
env_mod.core_sources = []
|
env_mod.core_sources = []
|
||||||
|
|
||||||
@ -8,4 +9,4 @@ env_mod.add_source_files(env_mod.core_sources, "*.cpp")
|
|||||||
|
|
||||||
# Build it all as a library
|
# Build it all as a library
|
||||||
lib = env_mod.add_library("message_page", env_mod.core_sources)
|
lib = env_mod.add_library("message_page", env_mod.core_sources)
|
||||||
env_mod.Prepend(LIBS=[lib])
|
env.Prepend(LIBS=[lib])
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
#include "message_page.h"
|
||||||
|
|
||||||
|
void MessagePage::index(Request *request) {
|
||||||
|
|
||||||
|
std::string r = "<html><body>";
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < messages.size(); ++i) {
|
||||||
|
r += "<p>" + messages[i] + "</p><br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
r += "</html></body>";
|
||||||
|
|
||||||
|
request->response->setBody(r);
|
||||||
|
request->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagePage::MessagePage() {
|
||||||
|
messages.push_back("t message 1");
|
||||||
|
messages.push_back("t message 2");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagePage::~MessagePage() {
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,24 @@
|
|||||||
#ifndef MESSAGE_PAGE_H
|
#ifndef MESSAGE_PAGE_H
|
||||||
#define MESSAGE_PAGE_H
|
#define MESSAGE_PAGE_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "core/object.h"
|
#include "core/object.h"
|
||||||
|
|
||||||
|
#include "core/request.h"
|
||||||
|
|
||||||
|
|
||||||
class MessagePage : public Object {
|
class MessagePage : public Object {
|
||||||
RCPP_OBJECT(MessagePage, Object);
|
RCPP_OBJECT(MessagePage, Object);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void index(Request *request);
|
||||||
|
|
||||||
|
MessagePage();
|
||||||
|
~MessagePage();
|
||||||
|
|
||||||
|
std::vector<std::string> messages;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -25,7 +25,7 @@ void RDNApplication::index(Object *instance, Request *request) {
|
|||||||
request->send();
|
request->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RDNApplication::session_middleware_func(Object* instance, Request *request) {
|
void RDNApplication::session_middleware_func(Object *instance, Request *request) {
|
||||||
std::cout << "test: session_middleware_func called" << std::endl;
|
std::cout << "test: session_middleware_func called" << std::endl;
|
||||||
|
|
||||||
//if fail
|
//if fail
|
||||||
@ -34,12 +34,17 @@ void RDNApplication::session_middleware_func(Object* instance, Request *request)
|
|||||||
request->next_stage();
|
request->next_stage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RDNApplication::message_page_func(Object *instance, Request *request) {
|
||||||
|
dynamic_cast<MessagePage *>(instance)->index(request);
|
||||||
|
}
|
||||||
|
|
||||||
void RDNApplication::setup_routes() {
|
void RDNApplication::setup_routes() {
|
||||||
Application::setup_routes();
|
Application::setup_routes();
|
||||||
|
|
||||||
index_func = HandlerInstance(index);
|
index_func = HandlerInstance(index);
|
||||||
|
|
||||||
main_route_map["asd"] = HandlerInstance(index);
|
main_route_map["asd"] = HandlerInstance(index);
|
||||||
|
main_route_map["message_page"] = HandlerInstance(message_page_func, message_page);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RDNApplication::setup_middleware() {
|
void RDNApplication::setup_middleware() {
|
||||||
@ -48,7 +53,8 @@ void RDNApplication::setup_middleware() {
|
|||||||
//middlewares.push_back(RDNApplication::session_middleware_func);
|
//middlewares.push_back(RDNApplication::session_middleware_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
RDNApplication::RDNApplication() : Application() {
|
RDNApplication::RDNApplication() :
|
||||||
|
Application() {
|
||||||
|
|
||||||
SiteTheme *t = new TestSiteTheme();
|
SiteTheme *t = new TestSiteTheme();
|
||||||
t->register_theme();
|
t->register_theme();
|
||||||
@ -60,6 +66,8 @@ RDNApplication::RDNApplication() : Application() {
|
|||||||
t->register_theme();
|
t->register_theme();
|
||||||
|
|
||||||
themes.push_back(t);
|
themes.push_back(t);
|
||||||
|
|
||||||
|
message_page = new MessagePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
RDNApplication::~RDNApplication() {
|
RDNApplication::~RDNApplication() {
|
||||||
@ -68,4 +76,6 @@ RDNApplication::~RDNApplication() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
themes.clear();
|
themes.clear();
|
||||||
|
|
||||||
|
delete message_page;
|
||||||
}
|
}
|
@ -5,12 +5,16 @@
|
|||||||
#include "core/theme.h"
|
#include "core/theme.h"
|
||||||
#include "core/object.h"
|
#include "core/object.h"
|
||||||
|
|
||||||
|
#include "modules/message_page/message_page.h"
|
||||||
|
|
||||||
class RDNApplication : public Application {
|
class RDNApplication : public Application {
|
||||||
public:
|
public:
|
||||||
static void index(Object *instance, Request *request);
|
static void index(Object *instance, Request *request);
|
||||||
|
|
||||||
static void session_middleware_func(Object* instance, Request *request);
|
static void session_middleware_func(Object* instance, Request *request);
|
||||||
|
|
||||||
|
static void message_page_func(Object *instance, Request *request);
|
||||||
|
|
||||||
virtual void setup_routes();
|
virtual void setup_routes();
|
||||||
virtual void setup_middleware();
|
virtual void setup_middleware();
|
||||||
|
|
||||||
@ -18,6 +22,8 @@ public:
|
|||||||
~RDNApplication();
|
~RDNApplication();
|
||||||
|
|
||||||
std::vector<Theme *> themes;
|
std::vector<Theme *> themes;
|
||||||
|
|
||||||
|
MessagePage *message_page;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user