Reorganize folder structure.
This commit is contained in:
+9
-9
@@ -101,7 +101,7 @@ if(Boost_FOUND)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# For including its own headers as "webcc/http_client.h".
|
# For including its own headers as "webcc/http_client.h".
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/src)
|
include_directories(${PROJECT_SOURCE_DIR})
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/third_party/win32/include)
|
include_directories(${PROJECT_SOURCE_DIR}/third_party/win32/include)
|
||||||
@@ -116,23 +116,23 @@ if(WEBCC_ENABLE_SOAP)
|
|||||||
include_directories(${PROJECT_SOURCE_DIR}/third_party/src)
|
include_directories(${PROJECT_SOURCE_DIR}/third_party/src)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(src/webcc)
|
add_subdirectory(webcc)
|
||||||
|
|
||||||
if(WEBCC_BUILD_EXAMPLE)
|
if(WEBCC_BUILD_EXAMPLE)
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/example/http/client)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/example/http_hello_client)
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/example/http/async_client)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/example/http_hello_async_client)
|
||||||
|
|
||||||
# REST example needs jsoncpp to parse and create JSON.
|
# REST example needs jsoncpp to parse and create JSON.
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/src/jsoncpp)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/src/jsoncpp)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/third_party/src/jsoncpp)
|
include_directories(${PROJECT_SOURCE_DIR}/third_party/src/jsoncpp)
|
||||||
|
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/example/rest/book_server)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/example/rest_book_server)
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/example/rest/book_client)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/example/rest_book_client)
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/example/rest/book_async_client)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/example/rest_book_async_client)
|
||||||
|
|
||||||
if(WEBCC_ENABLE_SOAP)
|
if(WEBCC_ENABLE_SOAP)
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/example/soap/calc_server)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/example/soap_calc_server)
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/example/soap/calc_client)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/example/soap_calc_client)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
add_executable(http_async_client main.cc)
|
|
||||||
|
|
||||||
target_link_libraries(http_async_client webcc ${Boost_LIBRARIES})
|
|
||||||
target_link_libraries(http_async_client "${CMAKE_THREAD_LIBS_INIT}")
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
add_executable(http_client main.cc)
|
|
||||||
|
|
||||||
target_link_libraries(http_client webcc ${Boost_LIBRARIES})
|
|
||||||
target_link_libraries(http_client "${CMAKE_THREAD_LIBS_INIT}")
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
add_executable(http_hello_async_client main.cc)
|
||||||
|
|
||||||
|
target_link_libraries(http_hello_async_client webcc ${Boost_LIBRARIES})
|
||||||
|
target_link_libraries(http_hello_async_client "${CMAKE_THREAD_LIBS_INIT}")
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
add_executable(http_hello_client main.cc)
|
||||||
|
|
||||||
|
target_link_libraries(http_hello_client webcc ${Boost_LIBRARIES})
|
||||||
|
target_link_libraries(http_hello_client "${CMAKE_THREAD_LIBS_INIT}")
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
file(GLOB SRCS *.cc *.h)
|
set(SRCS book_services.cc book_services.h main.cc)
|
||||||
|
|
||||||
add_executable(rest_book_server ${SRCS})
|
add_executable(rest_book_server ${SRCS})
|
||||||
|
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
#include "book_services.h"
|
#include "example/rest_book_server/book_services.h"
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include "boost/thread/thread.hpp"
|
#include "boost/thread/thread.hpp"
|
||||||
#include "json/json.h"
|
#include "json/json.h"
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "webcc/logger.h"
|
#include "webcc/logger.h"
|
||||||
#include "webcc/rest_server.h"
|
#include "webcc/rest_server.h"
|
||||||
|
|
||||||
#include "book_services.h"
|
#include "example/rest_book_server/book_services.h"
|
||||||
|
|
||||||
// In order to run with VLD, please copy the following files to the example
|
// In order to run with VLD, please copy the following files to the example
|
||||||
// output folder from "third_party\win32\bin":
|
// output folder from "third_party\win32\bin":
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
file(GLOB SRCS *.cc *.h)
|
set(SRCS calc_client.cc calc_client.h main.cc)
|
||||||
|
|
||||||
add_executable(soap_calc_client ${SRCS})
|
add_executable(soap_calc_client ${SRCS})
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "calc_client.h"
|
#include "example/soap_calc_client/calc_client.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -73,8 +73,7 @@ bool CalcClient::Calc(const std::string& operation,
|
|||||||
|
|
||||||
// Error handling if any.
|
// Error handling if any.
|
||||||
if (error != webcc::kNoError) {
|
if (error != webcc::kNoError) {
|
||||||
LOG_ERRO("Operation '%s' failed: %s",
|
LOG_ERRO("Operation '%s' failed: %s", operation.c_str(),
|
||||||
operation.c_str(),
|
|
||||||
webcc::DescribeError(error));
|
webcc::DescribeError(error));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#define CALC_CLIENT_H_
|
#define CALC_CLIENT_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "webcc/soap_client.h"
|
#include "webcc/soap_client.h"
|
||||||
|
|
||||||
class CalcClient : public webcc::SoapClient {
|
class CalcClient : public webcc::SoapClient {
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "webcc/logger.h"
|
#include "webcc/logger.h"
|
||||||
|
|
||||||
#include "calc_client.h"
|
#include "example/soap_calc_client/calc_client.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
file(GLOB SRCS *.cc *.h)
|
set(SRCS calc_service.cc calc_service.h main.cc)
|
||||||
|
|
||||||
add_executable(soap_calc_server ${SRCS})
|
add_executable(soap_calc_server ${SRCS})
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "calc_service.h"
|
#include "example/soap_calc_server/calc_service.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -80,12 +80,10 @@ bool CalcService::Handle(const webcc::SoapRequest& soap_request,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CalcService::GetParameters(const webcc::SoapRequest& soap_request,
|
bool CalcService::GetParameters(const webcc::SoapRequest& soap_request,
|
||||||
double* x,
|
double* x, double* y) {
|
||||||
double* y) {
|
|
||||||
try {
|
try {
|
||||||
*x = std::stod(soap_request.GetParameter("x"));
|
*x = std::stod(soap_request.GetParameter("x"));
|
||||||
*y = std::stod(soap_request.GetParameter("y"));
|
*y = std::stod(soap_request.GetParameter("y"));
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
LOG_ERRO("Parameter cast error: %s", e.what());
|
LOG_ERRO("Parameter cast error: %s", e.what());
|
||||||
return false;
|
return false;
|
||||||
@@ -13,8 +13,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool GetParameters(const webcc::SoapRequest& soap_request,
|
bool GetParameters(const webcc::SoapRequest& soap_request,
|
||||||
double* x,
|
double* x, double* y);
|
||||||
double* y);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CALC_SERVICE_H_
|
#endif // CALC_SERVICE_H_
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "webcc/logger.h"
|
#include "webcc/logger.h"
|
||||||
#include "webcc/soap_server.h"
|
#include "webcc/soap_server.h"
|
||||||
|
|
||||||
#include "calc_service.h"
|
#include "example/soap_calc_server/calc_service.h"
|
||||||
|
|
||||||
static void Help(const char* argv0) {
|
static void Help(const char* argv0) {
|
||||||
std::cout << "Usage: " << argv0 << " <port>" << std::endl;
|
std::cout << "Usage: " << argv0 << " <port>" << std::endl;
|
||||||
@@ -20,16 +20,12 @@ int main(int argc, char* argv[]) {
|
|||||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||||
|
|
||||||
std::uint16_t port = static_cast<std::uint16_t>(std::atoi(argv[1]));
|
std::uint16_t port = static_cast<std::uint16_t>(std::atoi(argv[1]));
|
||||||
|
|
||||||
std::size_t workers = 2;
|
std::size_t workers = 2;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
webcc::SoapServer server(port, workers);
|
webcc::SoapServer server(port, workers);
|
||||||
|
|
||||||
server.Bind(std::make_shared<CalcService>(), "/calculator");
|
server.Bind(std::make_shared<CalcService>(), "/calculator");
|
||||||
|
|
||||||
server.Run();
|
server.Run();
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "Exception: " << e.what() << std::endl;
|
std::cerr << "Exception: " << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
#include "webcc/rest_service_manager.h"
|
#include "webcc/rest_service_manager.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
using namespace webcc;
|
class TestRestService : public webcc::RestService {
|
||||||
|
|
||||||
class TestRestService : public RestService {
|
|
||||||
public:
|
public:
|
||||||
bool Handle(const std::string& http_method,
|
bool Handle(const std::string& http_method,
|
||||||
const std::vector<std::string>& url_sub_matches,
|
const std::vector<std::string>& url_sub_matches,
|
||||||
@@ -15,10 +13,10 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
TEST(RestServiceManager, URL_RegexBasic) {
|
TEST(RestServiceManager, URL_RegexBasic) {
|
||||||
RestServiceManager service_manager;
|
webcc::RestServiceManager service_manager;
|
||||||
|
|
||||||
{
|
{
|
||||||
RestServicePtr service = std::make_shared<TestRestService>();
|
webcc::RestServicePtr service = std::make_shared<TestRestService>();
|
||||||
|
|
||||||
service_manager.AddService(service, "/instances/(\\d+)", true);
|
service_manager.AddService(service, "/instances/(\\d+)", true);
|
||||||
}
|
}
|
||||||
@@ -26,7 +24,7 @@ TEST(RestServiceManager, URL_RegexBasic) {
|
|||||||
std::vector<std::string> sub_matches;
|
std::vector<std::string> sub_matches;
|
||||||
|
|
||||||
std::string url = "/instances/12345";
|
std::string url = "/instances/12345";
|
||||||
RestServicePtr service = service_manager.GetService(url, &sub_matches);
|
webcc::RestServicePtr service = service_manager.GetService(url, &sub_matches);
|
||||||
|
|
||||||
EXPECT_TRUE(!!service);
|
EXPECT_TRUE(!!service);
|
||||||
|
|
||||||
@@ -41,17 +39,16 @@ TEST(RestServiceManager, URL_RegexBasic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(RestServiceManager, URL_NonRegex) {
|
TEST(RestServiceManager, URL_NonRegex) {
|
||||||
RestServiceManager service_manager;
|
webcc::RestServiceManager service_manager;
|
||||||
|
|
||||||
{
|
{
|
||||||
RestServicePtr service = std::make_shared<TestRestService>();
|
webcc::RestServicePtr service = std::make_shared<TestRestService>();
|
||||||
|
|
||||||
service_manager.AddService(service, "/instances", false);
|
service_manager.AddService(service, "/instances", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> sub_matches;
|
std::vector<std::string> sub_matches;
|
||||||
std::string url = "/instances";
|
std::string url = "/instances";
|
||||||
RestServicePtr service = service_manager.GetService(url, &sub_matches);
|
webcc::RestServicePtr service = service_manager.GetService(url, &sub_matches);
|
||||||
|
|
||||||
EXPECT_TRUE(!!service);
|
EXPECT_TRUE(!!service);
|
||||||
EXPECT_EQ(0, sub_matches.size());
|
EXPECT_EQ(0, sub_matches.size());
|
||||||
|
|||||||
Reference in New Issue
Block a user