Reorganize folder structure.

master
Adam Gu 7 years ago
parent 3b13cc74f7
commit 88511caff6

@ -101,7 +101,7 @@ if(Boost_FOUND)
endif()
# For including its own headers as "webcc/http_client.h".
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR})
if(WIN32)
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)
endif()
add_subdirectory(src/webcc)
add_subdirectory(webcc)
if(WEBCC_BUILD_EXAMPLE)
add_subdirectory(${PROJECT_SOURCE_DIR}/example/http/client)
add_subdirectory(${PROJECT_SOURCE_DIR}/example/http/async_client)
add_subdirectory(${PROJECT_SOURCE_DIR}/example/http_hello_client)
add_subdirectory(${PROJECT_SOURCE_DIR}/example/http_hello_async_client)
# REST example needs jsoncpp to parse and create JSON.
add_subdirectory(${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_client)
add_subdirectory(${PROJECT_SOURCE_DIR}/example/rest/book_async_client)
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_async_client)
if(WEBCC_ENABLE_SOAP)
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_server)
add_subdirectory(${PROJECT_SOURCE_DIR}/example/soap_calc_client)
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})

@ -1,7 +1,7 @@
#include "book_services.h"
#include "example/rest_book_server/book_services.h"
#include <list>
#include <iostream>
#include <list>
#include "boost/thread/thread.hpp"
#include "json/json.h"

@ -3,7 +3,7 @@
#include "webcc/logger.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
// 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})

@ -1,4 +1,4 @@
#include "calc_client.h"
#include "example/soap_calc_client/calc_client.h"
#include <iostream>
@ -73,8 +73,7 @@ bool CalcClient::Calc(const std::string& operation,
// Error handling if any.
if (error != webcc::kNoError) {
LOG_ERRO("Operation '%s' failed: %s",
operation.c_str(),
LOG_ERRO("Operation '%s' failed: %s", operation.c_str(),
webcc::DescribeError(error));
return false;
}

@ -2,6 +2,7 @@
#define CALC_CLIENT_H_
#include <string>
#include "webcc/soap_client.h"
class CalcClient : public webcc::SoapClient {

@ -2,7 +2,7 @@
#include "webcc/logger.h"
#include "calc_client.h"
#include "example/soap_calc_client/calc_client.h"
int main() {
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})

@ -1,4 +1,4 @@
#include "calc_service.h"
#include "example/soap_calc_server/calc_service.h"
#include <functional>
#include <string>
@ -80,12 +80,10 @@ bool CalcService::Handle(const webcc::SoapRequest& soap_request,
}
bool CalcService::GetParameters(const webcc::SoapRequest& soap_request,
double* x,
double* y) {
double* x, double* y) {
try {
*x = std::stod(soap_request.GetParameter("x"));
*y = std::stod(soap_request.GetParameter("y"));
} catch (const std::exception& e) {
LOG_ERRO("Parameter cast error: %s", e.what());
return false;

@ -13,8 +13,7 @@ public:
private:
bool GetParameters(const webcc::SoapRequest& soap_request,
double* x,
double* y);
double* x, double* y);
};
#endif // CALC_SERVICE_H_

@ -3,7 +3,7 @@
#include "webcc/logger.h"
#include "webcc/soap_server.h"
#include "calc_service.h"
#include "example/soap_calc_server/calc_service.h"
static void Help(const char* argv0) {
std::cout << "Usage: " << argv0 << " <port>" << std::endl;
@ -20,16 +20,12 @@ int main(int argc, char* argv[]) {
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
std::uint16_t port = static_cast<std::uint16_t>(std::atoi(argv[1]));
std::size_t workers = 2;
try {
webcc::SoapServer server(port, workers);
server.Bind(std::make_shared<CalcService>(), "/calculator");
server.Run();
} catch (const std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
return 1;

@ -1,9 +1,7 @@
#include "webcc/rest_service_manager.h"
#include "gtest/gtest.h"
using namespace webcc;
class TestRestService : public RestService {
class TestRestService : public webcc::RestService {
public:
bool Handle(const std::string& http_method,
const std::vector<std::string>& url_sub_matches,
@ -15,10 +13,10 @@ public:
};
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);
}
@ -26,7 +24,7 @@ TEST(RestServiceManager, URL_RegexBasic) {
std::vector<std::string> sub_matches;
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);
@ -41,17 +39,16 @@ TEST(RestServiceManager, URL_RegexBasic) {
}
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);
}
std::vector<std::string> sub_matches;
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_EQ(0, sub_matches.size());

Loading…
Cancel
Save