Modify drogon_ctl

This commit is contained in:
antao 2018-08-22 15:08:48 +08:00
parent aa8170ff18
commit c0acf347a3
3 changed files with 29 additions and 3 deletions

View File

@ -122,7 +122,7 @@ void create_controller::handleCommand(std::vector<std::string> &parameters)
}
}
createSimpleController(parameters,namespaceName);
createWebsockController(parameters,namespaceName);
}
else
createApiController(parameters);
@ -241,7 +241,7 @@ void create_controller::newSimpleControllerSourceFile(std::ofstream &file,const
void create_controller::newWebsockControllerHeaderFile(std::ofstream &file,const std::string &ctlName,const std::string &namespaceName)
{
file<<"#pragma once\n";
file<<"#include <drogon/HttpWebsocketController.h>\n";
file<<"#include <drogon/WebsocketController.h>\n";
file<<"using namespace drogon;\n";
std::string indent="";
auto namespace_name=namespaceName;
@ -263,7 +263,7 @@ void create_controller::newWebsockControllerHeaderFile(std::ofstream &file,const
indent.append(" ");
}
}
file<<indent<<"class "<<ctlName<<":public drogon::HttpWebsocketController<"<<ctlName<<">\n";
file<<indent<<"class "<<ctlName<<":public drogon::WebSocketController<"<<ctlName<<">\n";
file<<indent<<"{\n";
file<<indent<<"public:\n";
//TestController(){}

View File

@ -0,0 +1,9 @@
#include "WebSocketTest.h"
using namespace example;
void WebSocketTest::handleNewMessage(const WebSocketConnectionPtr& wsConnPtr,trantor::MsgBuffer* buffer)
{
//write your application logic here
}void WebSocketTest::handleConnection(const WebSocketConnectionPtr& wsConnPtr)
{
//write your application logic here
}

View File

@ -0,0 +1,17 @@
#pragma once
#include <drogon/WebSocketController.h>
using namespace drogon;
namespace example
{
class WebSocketTest:public drogon::WebSocketController<WebSocketTest>
{
public:
virtual void handleNewMessage(const WebSocketConnectionPtr&,
trantor::MsgBuffer*)override;
virtual void handleConnection(const WebSocketConnectionPtr&)override;
WS_PATH_LIST_BEGIN
//list path definations here;
WS_PATH_ADD("/chat");
WS_PATH_LIST_END
};
}