reserve makefile support

This commit is contained in:
ruanshudong 2020-03-10 20:50:37 +08:00
parent b2ca1d68c1
commit d89067c3bb
29 changed files with 477 additions and 38 deletions

View File

@ -0,0 +1,62 @@
#!/bin/sh
if [ $# -lt 3 ]
then
echo "<Usage: $0 App Server Servant>"
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.]"

View File

@ -0,0 +1,63 @@
#!/bin/sh
if [ $# -lt 3 ]
then
echo "<Usage: $0 App Server Servant>"
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.]"

View File

@ -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.]"

View File

@ -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.]"

View File

@ -0,0 +1,10 @@
module DemoApp
{
interface DemoServant
{
int test();
};
};

View File

@ -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:
//...
}

View File

@ -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

View File

@ -0,0 +1,43 @@
#include "DemoServer.h"
#include "DemoServantImp.h"
using namespace std;
DemoServer g_app;
/////////////////////////////////////////////////////////////////
void
DemoServer::initialize()
{
//initialize application here:
//...
addServant<DemoServantImp>(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;
}
/////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,34 @@
#ifndef _DemoServer_H_
#define _DemoServer_H_
#include <iostream>
#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

View File

@ -0,0 +1,16 @@
#-----------------------------------------------------------------------
APP := DemoApp
TARGET := DemoServer
CONFIG :=
STRIP_FLAG:= N
TARS2CPP_FLAG:=
INCLUDE +=
LIB +=
#-----------------------------------------------------------------------
include /usr/local/tars/cpp/makefile/makefile.tars
#-----------------------------------------------------------------------

View File

@ -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<char> &buffer)
{
TC_HttpRequest req;
TC_HttpResponse rsp;
// parse request header
vector<char> 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;
}

View File

@ -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<char> &buffer);
private:
int doRequest(const TC_HttpRequest &req, TC_HttpResponse &rsp);
};
/////////////////////////////////////////////////////
#endif

View File

@ -0,0 +1,44 @@
#include "DemoServer.h"
#include "DemoServantImp.h"
using namespace std;
DemoServer g_app;
/////////////////////////////////////////////////////////////////
void
DemoServer::initialize()
{
//initialize application here:
//...
addServant<DemoServantImp>(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;
}
/////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,34 @@
#ifndef _DemoServer_H_
#define _DemoServer_H_
#include <iostream>
#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

View File

@ -0,0 +1,16 @@
#-----------------------------------------------------------------------
APP := DemoApp
TARGET := DemoServer
CONFIG :=
STRIP_FLAG:= N
TARS2CPP_FLAG:=
INCLUDE +=
LIB +=
#-----------------------------------------------------------------------
include /usr/local/tars/cpp/makefile/makefile.tars
#-----------------------------------------------------------------------

View File

@ -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.]"