From d89067c3bb8e74b2f92eb1f6a86e997d64b92784 Mon Sep 17 00:00:00 2001 From: ruanshudong Date: Tue, 10 Mar 2020 20:50:37 +0800 Subject: [PATCH] reserve makefile support --- .../{demo => cmake_demo}/CMakeLists.txt | 0 .../{demo => cmake_demo}/src/CMakeLists.txt | 0 .../{demo => cmake_demo}/src/DemoServant.tars | 0 .../src/DemoServantImp.cpp | 0 .../{demo => cmake_demo}/src/DemoServantImp.h | 0 .../{demo => cmake_demo}/src/DemoServer.cpp | 0 .../{demo => cmake_demo}/src/DemoServer.h | 0 .../CMakeLists.txt | 0 .../src/CMakeLists.txt | 0 .../src/DemoServantImp.cpp | 0 .../src/DemoServantImp.h | 0 .../src/DemoServer.cpp | 0 .../src/DemoServer.h | 0 servant/script/cmake_http_server.sh | 62 ++++++++++++++++++ servant/script/cmake_tars_server.sh | 63 +++++++++++++++++++ servant/script/create_http_server.sh | 32 ++++------ servant/script/create_tars_server.sh | 10 +-- servant/script/demo/DemoServant.tars | 10 +++ servant/script/demo/DemoServantImp.cpp | 19 ++++++ servant/script/demo/DemoServantImp.h | 35 +++++++++++ servant/script/demo/DemoServer.cpp | 43 +++++++++++++ servant/script/demo/DemoServer.h | 34 ++++++++++ servant/script/demo/makefile | 16 +++++ servant/script/http_demo/DemoServantImp.cpp | 44 +++++++++++++ servant/script/http_demo/DemoServantImp.h | 37 +++++++++++ servant/script/http_demo/DemoServer.cpp | 44 +++++++++++++ servant/script/http_demo/DemoServer.h | 34 ++++++++++ servant/script/http_demo/makefile | 16 +++++ servant/script/win_create.bat | 16 ++--- 29 files changed, 477 insertions(+), 38 deletions(-) rename servant/script/{demo => cmake_demo}/CMakeLists.txt (100%) rename servant/script/{demo => cmake_demo}/src/CMakeLists.txt (100%) rename servant/script/{demo => cmake_demo}/src/DemoServant.tars (100%) rename servant/script/{demo => cmake_demo}/src/DemoServantImp.cpp (100%) rename servant/script/{demo => cmake_demo}/src/DemoServantImp.h (100%) rename servant/script/{demo => cmake_demo}/src/DemoServer.cpp (100%) rename servant/script/{demo => cmake_demo}/src/DemoServer.h (100%) rename servant/script/{http_demo => cmake_http_demo}/CMakeLists.txt (100%) rename servant/script/{http_demo => cmake_http_demo}/src/CMakeLists.txt (100%) rename servant/script/{http_demo => cmake_http_demo}/src/DemoServantImp.cpp (100%) rename servant/script/{http_demo => cmake_http_demo}/src/DemoServantImp.h (100%) rename servant/script/{http_demo => cmake_http_demo}/src/DemoServer.cpp (100%) rename servant/script/{http_demo => cmake_http_demo}/src/DemoServer.h (100%) create mode 100755 servant/script/cmake_http_server.sh create mode 100755 servant/script/cmake_tars_server.sh create mode 100644 servant/script/demo/DemoServant.tars create mode 100644 servant/script/demo/DemoServantImp.cpp create mode 100644 servant/script/demo/DemoServantImp.h create mode 100644 servant/script/demo/DemoServer.cpp create mode 100644 servant/script/demo/DemoServer.h create mode 100644 servant/script/demo/makefile create mode 100644 servant/script/http_demo/DemoServantImp.cpp create mode 100644 servant/script/http_demo/DemoServantImp.h create mode 100644 servant/script/http_demo/DemoServer.cpp create mode 100644 servant/script/http_demo/DemoServer.h create mode 100644 servant/script/http_demo/makefile diff --git a/servant/script/demo/CMakeLists.txt b/servant/script/cmake_demo/CMakeLists.txt similarity index 100% rename from servant/script/demo/CMakeLists.txt rename to servant/script/cmake_demo/CMakeLists.txt diff --git a/servant/script/demo/src/CMakeLists.txt b/servant/script/cmake_demo/src/CMakeLists.txt similarity index 100% rename from servant/script/demo/src/CMakeLists.txt rename to servant/script/cmake_demo/src/CMakeLists.txt diff --git a/servant/script/demo/src/DemoServant.tars b/servant/script/cmake_demo/src/DemoServant.tars similarity index 100% rename from servant/script/demo/src/DemoServant.tars rename to servant/script/cmake_demo/src/DemoServant.tars diff --git a/servant/script/demo/src/DemoServantImp.cpp b/servant/script/cmake_demo/src/DemoServantImp.cpp similarity index 100% rename from servant/script/demo/src/DemoServantImp.cpp rename to servant/script/cmake_demo/src/DemoServantImp.cpp diff --git a/servant/script/demo/src/DemoServantImp.h b/servant/script/cmake_demo/src/DemoServantImp.h similarity index 100% rename from servant/script/demo/src/DemoServantImp.h rename to servant/script/cmake_demo/src/DemoServantImp.h diff --git a/servant/script/demo/src/DemoServer.cpp b/servant/script/cmake_demo/src/DemoServer.cpp similarity index 100% rename from servant/script/demo/src/DemoServer.cpp rename to servant/script/cmake_demo/src/DemoServer.cpp diff --git a/servant/script/demo/src/DemoServer.h b/servant/script/cmake_demo/src/DemoServer.h similarity index 100% rename from servant/script/demo/src/DemoServer.h rename to servant/script/cmake_demo/src/DemoServer.h diff --git a/servant/script/http_demo/CMakeLists.txt b/servant/script/cmake_http_demo/CMakeLists.txt similarity index 100% rename from servant/script/http_demo/CMakeLists.txt rename to servant/script/cmake_http_demo/CMakeLists.txt diff --git a/servant/script/http_demo/src/CMakeLists.txt b/servant/script/cmake_http_demo/src/CMakeLists.txt similarity index 100% rename from servant/script/http_demo/src/CMakeLists.txt rename to servant/script/cmake_http_demo/src/CMakeLists.txt diff --git a/servant/script/http_demo/src/DemoServantImp.cpp b/servant/script/cmake_http_demo/src/DemoServantImp.cpp similarity index 100% rename from servant/script/http_demo/src/DemoServantImp.cpp rename to servant/script/cmake_http_demo/src/DemoServantImp.cpp diff --git a/servant/script/http_demo/src/DemoServantImp.h b/servant/script/cmake_http_demo/src/DemoServantImp.h similarity index 100% rename from servant/script/http_demo/src/DemoServantImp.h rename to servant/script/cmake_http_demo/src/DemoServantImp.h diff --git a/servant/script/http_demo/src/DemoServer.cpp b/servant/script/cmake_http_demo/src/DemoServer.cpp similarity index 100% rename from servant/script/http_demo/src/DemoServer.cpp rename to servant/script/cmake_http_demo/src/DemoServer.cpp diff --git a/servant/script/http_demo/src/DemoServer.h b/servant/script/cmake_http_demo/src/DemoServer.h similarity index 100% rename from servant/script/http_demo/src/DemoServer.h rename to servant/script/cmake_http_demo/src/DemoServer.h diff --git a/servant/script/cmake_http_server.sh b/servant/script/cmake_http_server.sh new file mode 100755 index 0000000..187679a --- /dev/null +++ b/servant/script/cmake_http_server.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +if [ $# -lt 3 ] +then + echo "" + exit 0 +fi + +APP=$1 +SERVER=$2 +SERVANT=$3 + +echo "APP:$APP, SERVER:$SERVER, SERVANT:$SERVANT" + +if [ "$SERVER" == "$SERVANT" ] +then + echo "Error!(ServerName == ServantName)" + exit -1 +fi + +if [ ! -d $SERVER ] +then + echo "[mkdir: $SERVER]" + mkdir -p $SERVER +fi + +echo "[create server: $APP.$SERVER ...]" + +DEMO_PATH=/usr/local/tars/cpp/script/cmake_http_demo + +#make cleanall -C $DEMO_PATH + +cp -rf $DEMO_PATH/* $SERVER/ + +cd $SERVER/src + +SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp CMakeLists.txt" + +for FILE in $SRC_FILE +do + cat $FILE | sed "s/DemoServer/$SERVER/g" > $FILE.tmp + mv $FILE.tmp $FILE + + cat $FILE | sed "s/DemoApp/$APP/g" > $FILE.tmp + mv $FILE.tmp $FILE + + cat $FILE | sed "s/DemoServant/$SERVANT/g" > $FILE.tmp + mv $FILE.tmp $FILE +done + +mv DemoServer.h ${SERVER}.h +mv DemoServer.cpp ${SERVER}.cpp +mv DemoServantImp.h ${SERVANT}Imp.h +mv DemoServantImp.cpp ${SERVANT}Imp.cpp + +cd .. +mkdir build; cd build +cmake ..; make + +#cd ../../ + +echo "[done.]" diff --git a/servant/script/cmake_tars_server.sh b/servant/script/cmake_tars_server.sh new file mode 100755 index 0000000..0f1dc26 --- /dev/null +++ b/servant/script/cmake_tars_server.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +if [ $# -lt 3 ] +then + echo "" + exit 0 +fi + +APP=$1 +SERVER=$2 +SERVANT=$3 + +echo "APP:$APP, SERVER:$SERVER, SERVANT:$SERVANT" + +if [ "$SERVER" == "$SERVANT" ] +then + echo "Error!(ServerName == ServantName)" + exit -1 +fi + +if [ ! -d $SERVER ] +then + echo "[mkdir: $SERVER]" + mkdir -p $SERVER +fi + +echo "[create server: $APP.$SERVER ...]" + +DEMO_PATH=/usr/local/tars/cpp/script/cmake_demo + +#make cleanall -C $DEMO_PATH + +cp -rf $DEMO_PATH/* $SERVER/ + +cd $SERVER/src + +SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp DemoServant.tars CMakeLists.txt" + +for FILE in $SRC_FILE +do + cat $FILE | sed "s/DemoServer/$SERVER/g" > $FILE.tmp + mv $FILE.tmp $FILE + + cat $FILE | sed "s/DemoApp/$APP/g" > $FILE.tmp + mv $FILE.tmp $FILE + + cat $FILE | sed "s/DemoServant/$SERVANT/g" > $FILE.tmp + mv $FILE.tmp $FILE +done + +mv DemoServer.h ${SERVER}.h +mv DemoServer.cpp ${SERVER}.cpp +mv DemoServantImp.h ${SERVANT}Imp.h +mv DemoServantImp.cpp ${SERVANT}Imp.cpp +mv DemoServant.tars ${SERVANT}.tars + +cd .. +mkdir build; cd build +cmake ..; make + +#cd ../../ + +echo "[done.]" diff --git a/servant/script/create_http_server.sh b/servant/script/create_http_server.sh index dc86f19..a9f5c1f 100755 --- a/servant/script/create_http_server.sh +++ b/servant/script/create_http_server.sh @@ -10,31 +10,27 @@ APP=$1 SERVER=$2 SERVANT=$3 -echo "APP:$APP, SERVER:$SERVER, SERVANT:$SERVANT" - if [ "$SERVER" == "$SERVANT" ] then echo "Error!(ServerName == ServantName)" exit -1 fi -if [ ! -d $SERVER ] +if [ ! -d $APP/$SERVER ] then - echo "[mkdir: $SERVER]" - mkdir -p $SERVER + echo "[mkdir: $APP/$SERVER]" + mkdir -p $APP/$SERVER fi echo "[create server: $APP.$SERVER ...]" -DEMO_PATH=/usr/local/tars/cpp/script/http_demo +DEMO_PATH=/usr/local/tars/cpp/script/demo -#make cleanall -C $DEMO_PATH +cp $DEMO_PATH/* $APP/$SERVER/ -cp -rf $DEMO_PATH/* $SERVER/ +cd $APP/$SERVER/ -cd $SERVER/src - -SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp CMakeLists.txt" +SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp DemoServant.tars makefile" for FILE in $SRC_FILE do @@ -48,15 +44,9 @@ do mv $FILE.tmp $FILE done -mv DemoServer.h ${SERVER}.h -mv DemoServer.cpp ${SERVER}.cpp -mv DemoServantImp.h ${SERVANT}Imp.h -mv DemoServantImp.cpp ${SERVANT}Imp.cpp +rename "DemoServer" "$SERVER" $SRC_FILE +rename "DemoServant" "$SERVANT" $SRC_FILE -cd .. -mkdir build; cd build -cmake ..; make +cd ../../ -#cd ../../ - -echo "[done.]" +echo "[done.]" \ No newline at end of file diff --git a/servant/script/create_tars_server.sh b/servant/script/create_tars_server.sh index 30be853..f2db878 100755 --- a/servant/script/create_tars_server.sh +++ b/servant/script/create_tars_server.sh @@ -32,9 +32,9 @@ DEMO_PATH=/usr/local/tars/cpp/script/demo cp -rf $DEMO_PATH/* $SERVER/ -cd $SERVER/src +cd $SERVER -SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp DemoServant.tars CMakeLists.txt" +SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp DemoServant.tars makefile" for FILE in $SRC_FILE do @@ -54,10 +54,6 @@ mv DemoServantImp.h ${SERVANT}Imp.h mv DemoServantImp.cpp ${SERVANT}Imp.cpp mv DemoServant.tars ${SERVANT}.tars -cd .. -mkdir build; cd build -cmake ..; make - -#cd ../../ +make echo "[done.]" diff --git a/servant/script/demo/DemoServant.tars b/servant/script/demo/DemoServant.tars new file mode 100644 index 0000000..87f1910 --- /dev/null +++ b/servant/script/demo/DemoServant.tars @@ -0,0 +1,10 @@ + +module DemoApp +{ + +interface DemoServant +{ + int test(); +}; + +}; diff --git a/servant/script/demo/DemoServantImp.cpp b/servant/script/demo/DemoServantImp.cpp new file mode 100644 index 0000000..c5ca8bc --- /dev/null +++ b/servant/script/demo/DemoServantImp.cpp @@ -0,0 +1,19 @@ +#include "DemoServantImp.h" +#include "servant/Application.h" + +using namespace std; + +////////////////////////////////////////////////////// +void DemoServantImp::initialize() +{ + //initialize servant here: + //... +} + +////////////////////////////////////////////////////// +void DemoServantImp::destroy() +{ + //destroy servant here: + //... +} + diff --git a/servant/script/demo/DemoServantImp.h b/servant/script/demo/DemoServantImp.h new file mode 100644 index 0000000..1f10d1b --- /dev/null +++ b/servant/script/demo/DemoServantImp.h @@ -0,0 +1,35 @@ +#ifndef _DemoServantImp_H_ +#define _DemoServantImp_H_ + +#include "servant/Application.h" +#include "DemoServant.h" + +/** + * + * + */ +class DemoServantImp : public DemoApp::DemoServant +{ +public: + /** + * + */ + virtual ~DemoServantImp() {} + + /** + * + */ + virtual void initialize(); + + /** + * + */ + virtual void destroy(); + + /** + * + */ + virtual int test(tars::TarsCurrentPtr current) { return 0;}; +}; +///////////////////////////////////////////////////// +#endif diff --git a/servant/script/demo/DemoServer.cpp b/servant/script/demo/DemoServer.cpp new file mode 100644 index 0000000..c1ad88f --- /dev/null +++ b/servant/script/demo/DemoServer.cpp @@ -0,0 +1,43 @@ +#include "DemoServer.h" +#include "DemoServantImp.h" + +using namespace std; + +DemoServer g_app; + +///////////////////////////////////////////////////////////////// +void +DemoServer::initialize() +{ + //initialize application here: + //... + + addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj"); +} +///////////////////////////////////////////////////////////////// +void +DemoServer::destroyApp() +{ + //destroy application here: + //... +} +///////////////////////////////////////////////////////////////// +int +main(int argc, char* argv[]) +{ + try + { + g_app.main(argc, argv); + g_app.waitForShutdown(); + } + catch (std::exception& e) + { + cerr << "std::exception:" << e.what() << std::endl; + } + catch (...) + { + cerr << "unknown exception." << std::endl; + } + return -1; +} +///////////////////////////////////////////////////////////////// diff --git a/servant/script/demo/DemoServer.h b/servant/script/demo/DemoServer.h new file mode 100644 index 0000000..462c966 --- /dev/null +++ b/servant/script/demo/DemoServer.h @@ -0,0 +1,34 @@ +#ifndef _DemoServer_H_ +#define _DemoServer_H_ + +#include +#include "servant/Application.h" + +using namespace tars; + +/** + * + **/ +class DemoServer : public Application +{ +public: + /** + * + **/ + virtual ~DemoServer() {}; + + /** + * + **/ + virtual void initialize(); + + /** + * + **/ + virtual void destroyApp(); +}; + +extern DemoServer g_app; + +//////////////////////////////////////////// +#endif diff --git a/servant/script/demo/makefile b/servant/script/demo/makefile new file mode 100644 index 0000000..5c27a5c --- /dev/null +++ b/servant/script/demo/makefile @@ -0,0 +1,16 @@ +#----------------------------------------------------------------------- + +APP := DemoApp +TARGET := DemoServer +CONFIG := +STRIP_FLAG:= N +TARS2CPP_FLAG:= + +INCLUDE += +LIB += + +#----------------------------------------------------------------------- + +include /usr/local/tars/cpp/makefile/makefile.tars + +#----------------------------------------------------------------------- \ No newline at end of file diff --git a/servant/script/http_demo/DemoServantImp.cpp b/servant/script/http_demo/DemoServantImp.cpp new file mode 100644 index 0000000..0ac5668 --- /dev/null +++ b/servant/script/http_demo/DemoServantImp.cpp @@ -0,0 +1,44 @@ +#include "DemoServantImp.h" +#include "servant/Application.h" + +using namespace std; + +////////////////////////////////////////////////////// +void DemoServantImp::initialize() +{ + //initialize servant here: + //... +} + +////////////////////////////////////////////////////// +void DemoServantImp::destroy() +{ + //destroy servant here: + //... +} + +int DemoServantImp::doRequest(TarsCurrentPtr current, vector &buffer) +{ + TC_HttpRequest req; + TC_HttpResponse rsp; + + // parse request header + vector v = current->getRequestBuffer(); + string sBuf; + sBuf.assign(v.data(), v.size()); + req.decode(sBuf); + + int ret = doRequest(req, rsp); + + rsp.encode(buffer); + + return ret; +} + +int DemoServantImp::doRequest(const TC_HttpRequest &req, TC_HttpResponse &rsp) +{ + string msg = "Hello Tars!"; + rsp.setContentType("text/html"); + rsp.setResponse(msg.c_str(), msg.size()); + return 0; +} diff --git a/servant/script/http_demo/DemoServantImp.h b/servant/script/http_demo/DemoServantImp.h new file mode 100644 index 0000000..5a5e964 --- /dev/null +++ b/servant/script/http_demo/DemoServantImp.h @@ -0,0 +1,37 @@ +#ifndef _DemoServantImp_H_ +#define _DemoServantImp_H_ + +#include "servant/Application.h" + +/** + * + * + */ +class DemoServantImp : public Servant +{ +public: + /** + * + */ + virtual ~DemoServantImp() {} + + /** + * + */ + virtual void initialize(); + + /** + * + */ + virtual void destroy(); + + /** + * + */ + int doRequest(TarsCurrentPtr current, vector &buffer); + +private: + int doRequest(const TC_HttpRequest &req, TC_HttpResponse &rsp); +}; +///////////////////////////////////////////////////// +#endif diff --git a/servant/script/http_demo/DemoServer.cpp b/servant/script/http_demo/DemoServer.cpp new file mode 100644 index 0000000..d5208df --- /dev/null +++ b/servant/script/http_demo/DemoServer.cpp @@ -0,0 +1,44 @@ +#include "DemoServer.h" +#include "DemoServantImp.h" + +using namespace std; + +DemoServer g_app; + +///////////////////////////////////////////////////////////////// +void +DemoServer::initialize() +{ + //initialize application here: + //... + + addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj"); + addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".DemoServantObj", &TC_NetWorkBuffer::parseHttp); +} +///////////////////////////////////////////////////////////////// +void +DemoServer::destroyApp() +{ + //destroy application here: + //... +} +///////////////////////////////////////////////////////////////// +int +main(int argc, char* argv[]) +{ + try + { + g_app.main(argc, argv); + g_app.waitForShutdown(); + } + catch (std::exception& e) + { + cerr << "std::exception:" << e.what() << std::endl; + } + catch (...) + { + cerr << "unknown exception." << std::endl; + } + return -1; +} +///////////////////////////////////////////////////////////////// diff --git a/servant/script/http_demo/DemoServer.h b/servant/script/http_demo/DemoServer.h new file mode 100644 index 0000000..462c966 --- /dev/null +++ b/servant/script/http_demo/DemoServer.h @@ -0,0 +1,34 @@ +#ifndef _DemoServer_H_ +#define _DemoServer_H_ + +#include +#include "servant/Application.h" + +using namespace tars; + +/** + * + **/ +class DemoServer : public Application +{ +public: + /** + * + **/ + virtual ~DemoServer() {}; + + /** + * + **/ + virtual void initialize(); + + /** + * + **/ + virtual void destroyApp(); +}; + +extern DemoServer g_app; + +//////////////////////////////////////////// +#endif diff --git a/servant/script/http_demo/makefile b/servant/script/http_demo/makefile new file mode 100644 index 0000000..5c27a5c --- /dev/null +++ b/servant/script/http_demo/makefile @@ -0,0 +1,16 @@ +#----------------------------------------------------------------------- + +APP := DemoApp +TARGET := DemoServer +CONFIG := +STRIP_FLAG:= N +TARS2CPP_FLAG:= + +INCLUDE += +LIB += + +#----------------------------------------------------------------------- + +include /usr/local/tars/cpp/makefile/makefile.tars + +#----------------------------------------------------------------------- \ No newline at end of file diff --git a/servant/script/win_create.bat b/servant/script/win_create.bat index fdde913..53ead57 100644 --- a/servant/script/win_create.bat +++ b/servant/script/win_create.bat @@ -26,16 +26,13 @@ fi echo "[create server: $APP.$SERVER ...]" -DEMO_PATH=c:\\taf\\cpp\\script\\demo +DEMO_PATH=c:/tars/cpp/script/cmake_demo -SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp DemoServant.tars makefile CMakeLists.txt" +cp -rf $DEMO_PATH/* $APP/$SERVER -for FILE in $SRC_FILE -do - cp -rf $DEMO_PATH\\$FILE $APP\\$SERVER\\src -done +SRC_FILE="DemoServer.h DemoServer.cpp DemoServantImp.h DemoServantImp.cpp DemoServant.tars CMakeLists.txt ../CMakeLists.txt" -cd $APP\\$SERVER\\src +cd $APP/$SERVER/src for FILE in $SRC_FILE do @@ -53,10 +50,9 @@ mv DemoServer.h ${SERVER}.h mv DemoServer.cpp ${SERVER}.cpp mv DemoServantImp.h ${SERVANT}Imp.h mv DemoServantImp.cpp ${SERVANT}Imp.cpp -mv DemoServant.jce ${SERVANT}.jce +mv DemoServant.tars ${SERVANT}.tars cd ..\\build -cmake ..\\src -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Debug -cmake ..\\src -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release +cmake .. -DCMAKE_BUILD_TYPE=Release echo "[done.]"