mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Initial commit
This commit is contained in:
9
blacklib/samples/com_server/CMakeLists.txt
Normal file
9
blacklib/samples/com_server/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
FILE(GLOB sample_com_server_SOURCES *.cpp)
|
||||
SET(sample_com_server_HEADERS server.h)
|
||||
|
||||
QT4_WRAP_CPP(sample_com_server_HEADERS_MOC ${sample_com_server_HEADERS})
|
||||
|
||||
ADD_EXECUTABLE(sample_com_server ${sample_com_server_SOURCES} ${sample_com_server_HEADERS_MOC})
|
||||
|
||||
TARGET_LINK_LIBRARIES(sample_com_server blackmisc ${QT_LIBRARIES})
|
||||
SET_TARGET_PROPERTIES(sample_com_server PROPERTIES PROJECT_LABEL "Samples - Com Server")
|
||||
16
blacklib/samples/com_server/main.cpp
Normal file
16
blacklib/samples/com_server/main.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <QApplication>
|
||||
|
||||
#include <blackmisc/context.h>
|
||||
#include "server.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BlackMisc::CApplicationContext myApplicationContext;
|
||||
QApplication a(argc, argv);
|
||||
|
||||
Server server;
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
39
blacklib/samples/com_server/server.cpp
Normal file
39
blacklib/samples/com_server/server.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <blackmisc/debug.h>
|
||||
#include "server.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
Server::Server(QObject *parent) : QObject(parent)
|
||||
{
|
||||
QHostAddress local = QHostAddress(QHostAddress::LocalHost);
|
||||
|
||||
server.Host(local, 6809);
|
||||
|
||||
connect(&server, SIGNAL(doMessageReceived(QString &, QByteArray&)), this, SLOT(onData(QString &, QByteArray&)));
|
||||
|
||||
CMessageSystem myMessageSystem;
|
||||
|
||||
bInfo << "Com Server running. \n";
|
||||
}
|
||||
|
||||
Server::~Server()
|
||||
{
|
||||
}
|
||||
|
||||
void Server::onData(QString &messageID, QByteArray &message)
|
||||
{
|
||||
BlackMisc::IMessage* test = BlackMisc::CMessageFactory::getInstance().create(messageID);
|
||||
QDataStream stream(&message, QIODevice::ReadOnly);
|
||||
|
||||
bAssert (test);
|
||||
*test << stream;
|
||||
|
||||
CMessageDispatcher::getInstance().append(test);
|
||||
CMessageDispatcher::getInstance().dispatch();
|
||||
|
||||
}
|
||||
|
||||
void TestMessageHandler::onTestMessage(const TestMessage *testmessage)
|
||||
{
|
||||
bDebug << "Message ID: " << testmessage->getID() << " with text: " << testmessage->getTestString();
|
||||
}
|
||||
32
blacklib/samples/com_server/server.h
Normal file
32
blacklib/samples/com_server/server.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <blackmisc/message_system.h>
|
||||
#include <blackmisc/com_server.h>
|
||||
|
||||
class TestMessageHandler : public BlackMisc::CMessageHandler
|
||||
{
|
||||
public:
|
||||
TestMessageHandler()
|
||||
{
|
||||
registerMessageFunction(this, &TestMessageHandler::onTestMessage);
|
||||
}
|
||||
private:
|
||||
|
||||
void onTestMessage(const BlackMisc::TestMessage *testmessage);
|
||||
|
||||
};
|
||||
|
||||
class Server : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Server(QObject *parent = NULL);
|
||||
~Server();
|
||||
|
||||
protected slots:
|
||||
|
||||
void onData(QString &messageID, QByteArray& message);
|
||||
|
||||
private:
|
||||
BlackMisc::CComServer server;
|
||||
TestMessageHandler myHandler;
|
||||
};
|
||||
Reference in New Issue
Block a user