Skip to content

Commit e15f449

Browse files
committedDec 8, 2024·
Update 'async-server', 'async-server-rooms', 'clietn', 'server' to the latest oatpp 1.4.0 API
1 parent 53dca49 commit e15f449

33 files changed

+129
-123
lines changed
 

‎async-server-rooms/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
cmake_minimum_required(VERSION 3.1)
1+
cmake_minimum_required(VERSION 3.20)
22

33
set(project_name async-server-rooms) ## rename your project here
44

55
project(${project_name})
66

7-
set(CMAKE_CXX_STANDARD 11)
7+
set(CMAKE_CXX_STANDARD 17)
88

99
include_directories(src)
1010

@@ -21,8 +21,8 @@ add_library(${project_name}-lib
2121

2222
## link libs
2323

24-
find_package(oatpp 1.3.0 REQUIRED)
25-
find_package(oatpp-websocket 1.3.0 REQUIRED)
24+
find_package(oatpp 1.4.0 REQUIRED)
25+
find_package(oatpp-websocket 1.4.0 REQUIRED)
2626

2727
target_link_libraries(${project_name}-lib
2828
PUBLIC oatpp::oatpp
@@ -47,7 +47,7 @@ target_link_libraries(${project_name}-test ${project_name}-lib)
4747
add_dependencies(${project_name}-test ${project_name}-lib)
4848

4949
set_target_properties(${project_name}-lib ${project_name}-exe ${project_name}-test PROPERTIES
50-
CXX_STANDARD 11
50+
CXX_STANDARD 17
5151
CXX_EXTENSIONS OFF
5252
CXX_STANDARD_REQUIRED ON
5353
LINKER_LANGUAGE CXX

‎async-server-rooms/src/App.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void run() {
2626
oatpp::network::Server server(connectionProvider, connectionHandler);
2727

2828
/* Priny info about server port */
29-
OATPP_LOGI("MyApp", "Server running on port %s", connectionProvider->getProperty("port").getData());
29+
OATPP_LOGi("MyApp", "Server running on port {}", connectionProvider->getProperty("port").toString());
3030

3131
/* Run server */
3232
server.run();
@@ -35,11 +35,11 @@ void run() {
3535

3636
int main(int argc, const char * argv[]) {
3737

38-
oatpp::base::Environment::init();
38+
oatpp::Environment::init();
3939

4040
run();
4141

42-
oatpp::base::Environment::destroy();
42+
oatpp::Environment::destroy();
4343

4444
return 0;
4545
}

‎async-server-rooms/src/AppComponent.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
#include "oatpp/web/server/HttpRouter.hpp"
88
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"
99

10-
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
10+
#include "oatpp/json/ObjectMapper.hpp"
1111

12-
#include "oatpp/core/macro/component.hpp"
12+
#include "oatpp/macro/component.hpp"
1313

1414
/**
15-
* Class which creates and holds Application components and registers components in oatpp::base::Environment
15+
* Class which creates and holds Application components and registers components in oatpp::Environment
1616
* Order of components initialization is from top to bottom
1717
*/
1818
class AppComponent {
@@ -56,7 +56,7 @@ class AppComponent {
5656
* Create ObjectMapper component to serialize/deserialize DTOs in Contoller's API
5757
*/
5858
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
59-
return oatpp::parser::json::mapping::ObjectMapper::createShared();
59+
return std::make_shared<oatpp::json::ObjectMapper>();
6060
}());
6161

6262
/**

‎async-server-rooms/src/controller/RoomsController.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "oatpp/network/ConnectionHandler.hpp"
1010

11-
#include "oatpp/core/macro/codegen.hpp"
12-
#include "oatpp/core/macro/component.hpp"
11+
#include "oatpp/macro/codegen.hpp"
12+
#include "oatpp/macro/component.hpp"
1313

1414

1515
#include OATPP_CODEGEN_BEGIN(ApiController) //<-- codegen begin

‎async-server-rooms/src/rooms/Peer.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "oatpp-websocket/AsyncWebSocket.hpp"
66

7-
#include "oatpp/core/async/Lock.hpp"
8-
#include "oatpp/core/async/Executor.hpp"
7+
#include "oatpp/async/Lock.hpp"
8+
#include "oatpp/async/Executor.hpp"
99

10-
#include "oatpp/core/macro/component.hpp"
10+
#include "oatpp/macro/component.hpp"
1111

1212
class Room; // FWD
1313

‎async-server-rooms/test/WSTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
void WSTest::onRun() {
88

9-
OATPP_LOGD(TAG, "TODO - write tests");
9+
OATPP_LOGd(TAG, "TODO - write tests");
1010

1111
}

‎async-server-rooms/test/tests.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ void runTests() {
1111

1212
int main() {
1313

14-
oatpp::base::Environment::init();
14+
oatpp::Environment::init();
1515

1616
runTests();
1717

1818
/* Print how much objects were created during app running, and what have left-probably leaked */
1919
/* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */
2020
std::cout << "\nEnvironment:\n";
21-
std::cout << "objectsCount = " << oatpp::base::Environment::getObjectsCount() << "\n";
22-
std::cout << "objectsCreated = " << oatpp::base::Environment::getObjectsCreated() << "\n\n";
21+
std::cout << "objectsCount = " << oatpp::Environment::getObjectsCount() << "\n";
22+
std::cout << "objectsCreated = " << oatpp::Environment::getObjectsCreated() << "\n\n";
2323

24-
OATPP_ASSERT(oatpp::base::Environment::getObjectsCount() == 0);
24+
OATPP_ASSERT(oatpp::Environment::getObjectsCount() == 0);
2525

26-
oatpp::base::Environment::destroy();
26+
oatpp::Environment::destroy();
2727

2828
return 0;
2929
}

‎async-server/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
cmake_minimum_required(VERSION 3.1)
1+
cmake_minimum_required(VERSION 3.20)
22

33
set(project_name async-websocket-server) ## rename your project here
44

55
project(${project_name})
66

7-
set(CMAKE_CXX_STANDARD 11)
7+
set(CMAKE_CXX_STANDARD 17)
88

99
include_directories(src)
1010

@@ -17,8 +17,8 @@ add_library(${project_name}-lib
1717

1818
## link libs
1919

20-
find_package(oatpp 1.3.0 REQUIRED)
21-
find_package(oatpp-websocket 1.3.0 REQUIRED)
20+
find_package(oatpp 1.4.0 REQUIRED)
21+
find_package(oatpp-websocket 1.4.0 REQUIRED)
2222

2323
target_link_libraries(${project_name}-lib
2424
PUBLIC oatpp::oatpp
@@ -43,7 +43,7 @@ target_link_libraries(${project_name}-test ${project_name}-lib)
4343
add_dependencies(${project_name}-test ${project_name}-lib)
4444

4545
set_target_properties(${project_name}-lib ${project_name}-exe ${project_name}-test PROPERTIES
46-
CXX_STANDARD 11
46+
CXX_STANDARD 17
4747
CXX_EXTENSIONS OFF
4848
CXX_STANDARD_REQUIRED ON
4949
LINKER_LANGUAGE CXX

‎async-server/src/App.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void run() {
2626
oatpp::network::Server server(connectionProvider, connectionHandler);
2727

2828
/* Priny info about server port */
29-
OATPP_LOGI("MyApp", "Server running on port %s", connectionProvider->getProperty("port").getData());
29+
OATPP_LOGi("MyApp", "Server running on port {}", connectionProvider->getProperty("port").toString());
3030

3131
/* Run server */
3232
server.run();
@@ -35,11 +35,11 @@ void run() {
3535

3636
int main(int argc, const char * argv[]) {
3737

38-
oatpp::base::Environment::init();
38+
oatpp::Environment::init();
3939

4040
run();
4141

42-
oatpp::base::Environment::destroy();
42+
oatpp::Environment::destroy();
4343

4444
return 0;
4545
}

‎async-server/src/AppComponent.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
#include "oatpp/web/server/HttpRouter.hpp"
88
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"
99

10-
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
10+
#include "oatpp/json/ObjectMapper.hpp"
1111

12-
#include "oatpp/core/macro/component.hpp"
12+
#include "oatpp/macro/component.hpp"
1313

1414
/**
15-
* Class which creates and holds Application components and registers components in oatpp::base::Environment
15+
* Class which creates and holds Application components and registers components in oatpp::Environment
1616
* Order of components initialization is from top to bottom
1717
*/
1818
class AppComponent {
@@ -56,7 +56,7 @@ class AppComponent {
5656
* Create ObjectMapper component to serialize/deserialize DTOs in Contoller's API
5757
*/
5858
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
59-
return oatpp::parser::json::mapping::ObjectMapper::createShared();
59+
return std::make_shared<oatpp::json::ObjectMapper>();
6060
}());
6161

6262
/**

‎async-server/src/controller/MyController.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "oatpp/network/ConnectionHandler.hpp"
1010

11-
#include "oatpp/core/macro/codegen.hpp"
12-
#include "oatpp/core/macro/component.hpp"
11+
#include "oatpp/macro/codegen.hpp"
12+
#include "oatpp/macro/component.hpp"
1313

1414
#include OATPP_CODEGEN_BEGIN(ApiController) //<-- codegen begin
1515

‎async-server/src/websocket/WSListener.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11

22
#include "WSListener.hpp"
3+
#include "oatpp/base/Log.hpp"
34

45
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56
// WSListener
67

78
oatpp::async::CoroutineStarter WSListener::onPing(const std::shared_ptr<AsyncWebSocket>& socket, const oatpp::String& message) {
8-
OATPP_LOGD(TAG, "onPing");
9+
OATPP_LOGd(TAG, "onPing");
910
return socket->sendPongAsync(message);
1011
}
1112

1213
oatpp::async::CoroutineStarter WSListener::onPong(const std::shared_ptr<AsyncWebSocket>& socket, const oatpp::String& message) {
13-
OATPP_LOGD(TAG, "onPong");
14+
OATPP_LOGd(TAG, "onPong");
1415
return nullptr; // do nothing
1516
}
1617

1718
oatpp::async::CoroutineStarter WSListener::onClose(const std::shared_ptr<AsyncWebSocket>& socket, v_uint16 code, const oatpp::String& message) {
18-
OATPP_LOGD(TAG, "onClose code=%d", code);
19+
OATPP_LOGd(TAG, "onClose code={}", code);
1920
return nullptr; // do nothing
2021
}
2122

@@ -26,7 +27,7 @@ oatpp::async::CoroutineStarter WSListener::readMessage(const std::shared_ptr<Asy
2627
auto wholeMessage = m_messageBuffer.toString();
2728
m_messageBuffer.setCurrentPosition(0);
2829

29-
OATPP_LOGD(TAG, "onMessage message='%s'", wholeMessage->c_str());
30+
OATPP_LOGd(TAG, "onMessage message='{}'", wholeMessage)
3031

3132
/* Send message in reply */
3233
return socket->sendOneFrameTextAsync( "Hello from oatpp!: " + wholeMessage);
@@ -47,7 +48,7 @@ std::atomic<v_int32> WSInstanceListener::SOCKETS(0);
4748
void WSInstanceListener::onAfterCreate_NonBlocking(const std::shared_ptr<WSListener::AsyncWebSocket>& socket, const std::shared_ptr<const ParameterMap>& params) {
4849

4950
SOCKETS ++;
50-
OATPP_LOGD(TAG, "New Incoming Connection. Connection count=%d", SOCKETS.load());
51+
OATPP_LOGd(TAG, "New Incoming Connection. Connection count={}", SOCKETS.load());
5152

5253
/* In this particular case we create one WSListener per each connection */
5354
/* Which may be redundant in many cases */
@@ -57,6 +58,6 @@ void WSInstanceListener::onAfterCreate_NonBlocking(const std::shared_ptr<WSListe
5758
void WSInstanceListener::onBeforeDestroy_NonBlocking(const std::shared_ptr<WSListener::AsyncWebSocket>& socket) {
5859

5960
SOCKETS --;
60-
OATPP_LOGD(TAG, "Connection closed. Connection count=%d", SOCKETS.load());
61+
OATPP_LOGd(TAG, "Connection closed. Connection count={}", SOCKETS.load());
6162

6263
}

‎async-server/test/WSTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
void WSTest::onRun() {
55

6-
OATPP_LOGD(TAG, "TODO - write tests");
6+
OATPP_LOGd(TAG, "TODO - write tests");
77

88
}

‎async-server/test/tests.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ void runTests() {
1111

1212
int main() {
1313

14-
oatpp::base::Environment::init();
14+
oatpp::Environment::init();
1515

1616
runTests();
1717

1818
/* Print how much objects were created during app running, and what have left-probably leaked */
1919
/* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */
2020
std::cout << "\nEnvironment:\n";
21-
std::cout << "objectsCount = " << oatpp::base::Environment::getObjectsCount() << "\n";
22-
std::cout << "objectsCreated = " << oatpp::base::Environment::getObjectsCreated() << "\n\n";
21+
std::cout << "objectsCount = " << oatpp::Environment::getObjectsCount() << "\n";
22+
std::cout << "objectsCreated = " << oatpp::Environment::getObjectsCreated() << "\n\n";
2323

24-
OATPP_ASSERT(oatpp::base::Environment::getObjectsCount() == 0);
24+
OATPP_ASSERT(oatpp::Environment::getObjectsCount() == 0);
2525

26-
oatpp::base::Environment::destroy();
26+
oatpp::Environment::destroy();
2727

2828
return 0;
2929
}

‎client-binance.com/src/App.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "oatpp-mbedtls/client/ConnectionProvider.hpp"
1212
#include "oatpp-mbedtls/Config.hpp"
1313

14-
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
14+
#include "oatpp/json/ObjectMapper.hpp"
1515

1616
#include <thread>
1717

@@ -86,7 +86,7 @@ void run() {
8686
auto connector = oatpp::websocket::Connector::createShared(connectionProvider);
8787

8888
/* object mapper for DTO objects */
89-
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
89+
auto objectMapper = std::make_shared<oatpp::json::ObjectMapper>();
9090

9191

9292
/* Start Stream Reading Tasks */
@@ -103,8 +103,8 @@ void run() {
103103
}
104104

105105
int main() {
106-
oatpp::base::Environment::init();
106+
oatpp::Environment::init();
107107
run();
108-
oatpp::base::Environment::destroy();
108+
oatpp::Environment::destroy();
109109
return 0;
110110
}

‎client-binance.com/src/Model.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#ifndef Model_hpp
33
#define Model_hpp
44

5-
#include "oatpp/core/Types.hpp"
6-
#include "oatpp/core/macro/codegen.hpp"
5+
#include "oatpp/Types.hpp"
6+
#include "oatpp/macro/codegen.hpp"
77

88
#include OATPP_CODEGEN_BEGIN(DTO)
99

‎client-binance.com/src/WSEventListener.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "WSListener.hpp"
66

7-
#include "oatpp/core/data/mapping/ObjectMapper.hpp"
7+
#include "oatpp/data/mapping/ObjectMapper.hpp"
88

99
/**
1010
* Template event listener class.

‎client-binance.com/src/WSListener.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
// WSListener
66

77
void WSListener::onPing(const WebSocket& socket, const oatpp::String& message) {
8-
OATPP_LOGD(TAG, "onPing");
8+
OATPP_LOGd(TAG, "onPing");
99
socket.sendPong(message);
1010
}
1111

1212
void WSListener::onPong(const WebSocket& socket, const oatpp::String& message) {
13-
OATPP_LOGD(TAG, "onPong");
13+
OATPP_LOGd(TAG, "onPong");
1414
}
1515

1616
void WSListener::onClose(const WebSocket& socket, v_uint16 code, const oatpp::String& message) {
17-
OATPP_LOGD(TAG, "onClose code=%d", code);
17+
OATPP_LOGd(TAG, "onClose code={}", code);
1818
}
1919

2020
void WSListener::readMessage(const WebSocket& socket, v_uint8 opcode, p_char8 data, oatpp::v_io_size size) {

‎client-binance.com/test/WSTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
void WSTest::onRun() {
55

6-
OATPP_LOGD(TAG, "TODO - write tests");
6+
OATPP_LOGd(TAG, "TODO - write tests");
77

88
}

0 commit comments

Comments
 (0)
Please sign in to comment.