Skip to content

Commit ea65189

Browse files
添加websocket动态库实现
1 parent c0f04c2 commit ea65189

File tree

17 files changed

+235
-212
lines changed

17 files changed

+235
-212
lines changed
Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
#
2-
# Copyright (c) 2013 No Face Press, LLC
3-
# License http://opensource.org/licenses/mit-license.php MIT License
4-
#
5-
6-
#This makefile is used to test the other Makefiles
7-
8-
9-
PROG = embedded_cpp
10-
SRC = embedded_cpp.cpp
11-
12-
TOP = ../..
13-
CIVETWEB_LIB = libcivetweb.a
14-
15-
CFLAGS = -I$(TOP)/include $(COPT)
16-
LIBS = -lpthread
17-
18-
include $(TOP)/resources/Makefile.in-os
19-
20-
ifeq ($(TARGET_OS),LINUX)
21-
LIBS += -ldl -lrt
22-
endif
23-
ifdef WITH_ZLIB
24-
LIBS += -lz
25-
endif
26-
27-
all: $(PROG)
28-
29-
$(PROG): $(CIVETWEB_LIB) $(SRC)
30-
$(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS)
31-
32-
$(CIVETWEB_LIB):
33-
$(MAKE) -C $(TOP) clean lib WITH_CPP=1
34-
cp $(TOP)/$(CIVETWEB_LIB) .
35-
36-
clean:
37-
rm -f $(CIVETWEB_LIB) $(PROG)
38-
39-
.PHONY: all clean
1+
#!/bin/sh
2+
all:
3+
g++ embedded_cpp.cpp ../../src/civetweb.c ../../src/CivetServer.cpp -DUSE_WEBSOCKET -I../../include -lpthread -ldl -std=c++11 -g -O0 -DNO_SSL -o ws_server -Wall

3rd/civetweb/examples/https/README.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

3rd/civetweb/examples/https/civetweb.conf

Lines changed: 0 additions & 86 deletions
This file was deleted.

3rd/civetweb/examples/multidomain/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

3rd/civetweb/examples/multidomain/add_domain.conf

Lines changed: 0 additions & 5 deletions
This file was deleted.

3rd/civetweb/examples/multidomain/base_domain.conf

Lines changed: 0 additions & 7 deletions
This file was deleted.

3rd/civetweb/include/civetweb.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,14 @@ CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
452452
453453
Must be called last, when an application wants to stop the web server and
454454
release all associated resources. This function blocks until all Civetweb
455-
threads are stopped. Context pointer becomes invalid. */
455+
threads are stopped. IContext pointer becomes invalid. */
456456
CIVETWEB_API void mg_stop(struct mg_context *);
457457

458458

459459
/* Add an additional domain to an already running web server.
460460
*
461461
* Parameters:
462-
* ctx: Context handle of a server started by mg_start.
462+
* ctx: IContext handle of a server started by mg_start.
463463
* options: NULL terminated list of option_name, option_value pairs that
464464
* specify CivetWeb configuration parameters.
465465
*
@@ -1613,7 +1613,7 @@ CIVETWEB_API int mg_get_system_info(char *buffer, int buflen);
16131613

16141614
/* Get context information. Useful for server diagnosis.
16151615
Parameters:
1616-
ctx: Context handle
1616+
ctx: IContext handle
16171617
buffer: Store context information here.
16181618
buflen: Length of buffer (including a byte required for a terminating 0).
16191619
Return:
@@ -1641,7 +1641,7 @@ CIVETWEB_API void mg_disable_connection_keep_alive(struct mg_connection *conn);
16411641
#if defined(MG_EXPERIMENTAL_INTERFACES)
16421642
/* Get connection information. Useful for server diagnosis.
16431643
Parameters:
1644-
ctx: Context handle
1644+
ctx: IContext handle
16451645
idx: Connection index
16461646
buffer: Store context information here.
16471647
buflen: Length of buffer (including a byte required for a terminating 0).

inc/dlms_bash.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,45 @@
66
#define DLMS_DLMS_BASH_H
77
#include <iostream>
88
#include <functional>
9+
#include "status.h"
910
#include "thread_manager.h"
1011

12+
1113
class Plugin;
12-
class IDlms {
14+
class IContext {
1315
public:
1416

1517

1618
public:
17-
virtual ~IDlms() = default;
19+
virtual ~IContext() = default;
1820

1921
/**
2022
* @brief 主进程初始化
2123
*
2224
* @return 0:成功,其他:失败
2325
*/
24-
virtual int32_t Init() = 0;
26+
virtual Status Init() = 0;
2527

2628
/**
2729
* @brief 启动主进程
2830
*
2931
* @return 0:成功,其他:失败
3032
*/
31-
virtual int32_t Start() = 0;
33+
virtual Status Start() = 0;
3234

3335
/**
3436
* @brief 停止主进程
3537
*
3638
* @return 0:成功,其他:失败
3739
*/
38-
virtual int32_t Stop() = 0;
40+
virtual Status Stop() = 0;
3941

4042
/**
4143
* @brief 退出主进程
4244
*
4345
* @return 0:成功,其他:失败
4446
*/
45-
virtual int32_t Reset() = 0;
47+
virtual Status Reset() = 0;
4648

4749
/**
4850
* @brief 获取插件对象
@@ -52,7 +54,7 @@ class IDlms {
5254
virtual Plugin *GetPlugin(std::string &pluginName) = 0;
5355

5456
// 将需要工作的线程放到Push里面
55-
virtual uint32_t Dispatch(Func workFunction) = 0;
57+
virtual Status Dispatch(Func workFunction) = 0;
5658
};
5759

5860

inc/plugin.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum NotifyTypes
2828
Quit = 1,
2929
};
3030

31-
class IDlms;
31+
class IContext;
3232
class Plugin {
3333
public:
3434
enum PluginStatus : uint8_t {
@@ -48,22 +48,22 @@ class Plugin {
4848
*
4949
* @param lpIDlms 主框架对象指针
5050
*/
51-
virtual int32_t Init(IDlms *lpIDlms, std::string& pluginName) = 0;
51+
virtual Status Init(IContext *lpIDlms, std::string& pluginName) = 0;
5252

53-
virtual int32_t Start() = 0;
53+
virtual Status Start() = 0;
5454

55-
virtual int32_t Stop() = 0;
55+
virtual Status Stop() = 0;
5656

57-
virtual int32_t Reset() = 0;
57+
virtual Status Reset() = 0;
5858

5959
// 获取插件名字
6060
virtual std::string GetHandleName() = 0;
6161

62-
virtual int32_t SendAndReceive(PluginServiceType in, void *lpInData, PluginServiceType out, void *lpOutData) = 0;
62+
virtual Status SendAndReceive(PluginServiceType in, void *lpInData, PluginServiceType out, void *lpOutData) = 0;
6363

64-
virtual int32_t Send(PluginServiceType in, void *lpInData) = 0;
64+
virtual Status Send(PluginServiceType in, void *lpInData) = 0;
6565

66-
virtual int32_t Notify(PluginServiceType in, void *lpInData) = 0;
66+
virtual Status Notify(PluginServiceType in, void *lpInData) = 0;
6767

6868
virtual bool ServiceSupport(PluginServiceType serviceType) = 0;
6969

plugins/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11

2-
2+
# 定义动态库,虽然最终是生成so文件,也被称为可执行文件的一种,但是动态库并不需要链接全部文件,有些依赖的文件只需要给出头文件即可
33
add_library(websocket SHARED
44
websocket/websocket_plugin.cpp
55
websocket/websocket_server.cpp
66
websocket/websocket_client.cpp)
7+
8+
#add_executable(websocket
9+
# websocket/websocket_plugin.cpp
10+
# websocket/websocket_server.cpp
11+
# websocket/websocket_client.cpp)
712
target_link_libraries(websocket
813
PUBLIC pthread)
914
target_include_directories(websocket
1015
PUBLIC ${PROJECT_SOURCE_DIR}/inc
11-
PUBLIC ${PROJECT_SOURCE_DIR}/3rd/civetweb)
16+
PUBLIC ${PROJECT_SOURCE_DIR}/3rd/civetweb/include
17+
PUBLIC ${PROJECT_SOURCE_DIR}/utils)
18+
target_compile_definitions(websocket
19+
PUBLIC pthread
20+
PUBLIC dl)
1221

1322

1423

plugins/websocket/websocket_plugin.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,52 @@
33
//
44

55
#include "websocket_plugin.h"
6+
7+
8+
9+
10+
Websocket::~Websocket() = default;
11+
12+
Status Websocket::Init(IContext *lpIDlms, std::string &pluginName) {
13+
14+
// 初始化websocket库
15+
mg_init_library(0);
16+
17+
18+
19+
return Status::Ok();
20+
}
21+
22+
Status Websocket::Send(PluginServiceType in, void *lpInData) {
23+
return Status::Ok();
24+
}
25+
26+
Status Websocket::Notify(PluginServiceType in, void *lpInData) {
27+
return Status::Ok();
28+
}
29+
30+
Status Websocket::Start() {
31+
32+
33+
return Status::Ok();
34+
}
35+
36+
Status Websocket::Stop() {
37+
return Status::Ok();
38+
}
39+
40+
Status Websocket::Reset() {
41+
return Status::Ok();
42+
}
43+
44+
std::string Websocket::GetHandleName() {
45+
return std::string();
46+
}
47+
48+
Status Websocket::SendAndReceive(PluginServiceType in, void *lpInData, PluginServiceType out, void *lpOutData) {
49+
return Status::Ok();
50+
}
51+
52+
bool Websocket::ServiceSupport(PluginServiceType serviceType) {
53+
return false;
54+
}

0 commit comments

Comments
 (0)