Skip to content

Commit

Permalink
added missing debug defines
Browse files Browse the repository at this point in the history
  • Loading branch information
Niall Ryan authored and Niall Ryan committed May 30, 2010
0 parents commit 25b877a
Show file tree
Hide file tree
Showing 88 changed files with 9,182 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax: glob

*.user
*.sln.cache
*.suo
*.tmp
*.orig
*.ncb
*.log
*.sdf
*.opensdf
obj/*
bin/*
Thumbs.db
_ReSharper*

29 changes: 29 additions & 0 deletions Cpp/ProtoBufRemote.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProtoBufRemote", "ProtoBufRemote\ProtoBufRemote.vcxproj", "{F43A5DDB-5E60-4DAC-8B1B-C248B435125E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProtoBufRemoteTest", "ProtoBufRemoteTest\ProtoBufRemoteTest.vcxproj", "{26DD0D61-9C86-4B99-A90D-D10965E2822B}"
ProjectSection(ProjectDependencies) = postProject
{F43A5DDB-5E60-4DAC-8B1B-C248B435125E} = {F43A5DDB-5E60-4DAC-8B1B-C248B435125E}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F43A5DDB-5E60-4DAC-8B1B-C248B435125E}.Debug|Win32.ActiveCfg = Debug|Win32
{F43A5DDB-5E60-4DAC-8B1B-C248B435125E}.Debug|Win32.Build.0 = Debug|Win32
{F43A5DDB-5E60-4DAC-8B1B-C248B435125E}.Release|Win32.ActiveCfg = Release|Win32
{F43A5DDB-5E60-4DAC-8B1B-C248B435125E}.Release|Win32.Build.0 = Release|Win32
{26DD0D61-9C86-4B99-A90D-D10965E2822B}.Debug|Win32.ActiveCfg = Debug|Win32
{26DD0D61-9C86-4B99-A90D-D10965E2822B}.Debug|Win32.Build.0 = Debug|Win32
{26DD0D61-9C86-4B99-A90D-D10965E2822B}.Release|Win32.ActiveCfg = Release|Win32
{26DD0D61-9C86-4B99-A90D-D10965E2822B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
160 changes: 160 additions & 0 deletions Cpp/ProtoBufRemote/Generators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#ifndef PROTOBUFREMOTE_GENERATORS_H
#define PROTOBUFREMOTE_GENERATORS_H 1

#include <boost/preprocessor.hpp>
#include "ProtoBufRemote/PendingCall.h"
#include "ProtoBufRemote/Proxy.h"
#include "ProtoBufRemote/RpcClient.h"
#include "ProtoBufRemote/RpcService.h"

/**
* Declares both a proxy and a service stub. Here is a sample declaration, note that there are no commas between methods
* or between parameters.
* PBR_SERVICE(SampleService2,
* PBR_METHOD(GetSquare, PBR_INT(PBR_INT))
* PBR_METHOD(DoStuff, PBR_VOID(PBR_STRING))
* PBR_METHOD(DoOtherStuff, PBR_VOID(PBR_STRING PBR_INT PBR_BOOL))
* PBR_METHOD(DoEvenMoreStuff, PBR_VOID(PBR_VOID))
* )
*/
#define PBR_SERVICE(name, methods) \
PBR_PROXY(name, methods) \
PBR_SERVICE_STUB(name, methods)

/**
* Declares a proxy only, without a matching service stub. See PBR_SERVICE for a description.
*/
#define PBR_PROXY(name, methods) \
class name##Proxy : public ::ProtoBufRemote::Proxy \
{ \
public: \
name##Proxy(::ProtoBufRemote::RpcClient& client) : ::ProtoBufRemote::Proxy(client, #name) { } \
BOOST_PP_SEQ_FOR_EACH(PBR_X_PROXY_METHOD, ~, methods) \
};

/**
* Declares a service stub only, without a matching proxy. See PBR_SERVICE for a description.
*/
#define PBR_SERVICE_STUB(name, methods) \
class name##Stub : public ::ProtoBufRemote::RpcService \
{ \
public: \
name##Stub() : ::ProtoBufRemote::RpcService(#name) \
{ \
} \
virtual bool Call(const char* methodName, const ::ProtoBufRemote::ParameterList& parameters, \
::ProtoBufRemote::MutableParameter* result) \
{ \
if (0) { } \
BOOST_PP_SEQ_FOR_EACH(PBR_X_STUB_CALL_METHOD, ~, methods) \
return false; \
} \
BOOST_PP_SEQ_FOR_EACH(PBR_X_STUB_METHOD, ~, methods) \
};

#define PBR_METHOD(name, signature) ((name, signature))

#define PBR_VOID ((void, 0, ~, ~, ~))
#define PBR_INT ((int, 1, SetInt, GetInt, IsInt))
#define PBR_BOOL ((bool, 1, SetBool, GetBool, IsBool))
#define PBR_STRING ((const std::string&, 1, SetString, GetString, IsString))


//=============================================================================================================
// internal macros
//=============================================================================================================

#define PBR_X_METHOD_NAME(method) BOOST_PP_TUPLE_ELEM(2, 0, method)
#define PBR_X_METHOD_SIG(method) BOOST_PP_TUPLE_ELEM(2, 1, method)
#define PBR_X_METHOD_RETURN(method) BOOST_PP_SEQ_ELEM(0, PBR_X_METHOD_SIG(method))
#define PBR_X_METHOD_PARAMS(method) BOOST_PP_SEQ_ELEM(1, PBR_X_METHOD_SIG(method))
#define PBR_X_METHOD_HAS_RETURN(method) BOOST_PP_TUPLE_ELEM(5, 1, PBR_X_METHOD_RETURN(method))
#define PBR_X_METHOD_HAS_PARAMS(method) BOOST_PP_TUPLE_ELEM(5, 1, BOOST_PP_SEQ_HEAD(PBR_X_METHOD_PARAMS(method)))

#define PBR_X_DECLARE_METHOD_PARAMS(method) \
BOOST_PP_SEQ_FOR_EACH_I(PBR_X_DECLARE_METHOD_PARAM, ~, PBR_X_METHOD_PARAMS(method))

#define PBR_X_DECLARE_METHOD_PARAM(r, data, i, param) \
BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(5, 0, param) BOOST_PP_CAT(p, i)

//proxy

#define PBR_X_PROXY_METHOD(r, data, method) \
BOOST_PP_TUPLE_ELEM(5, 0, PBR_X_METHOD_RETURN(method)) PBR_X_METHOD_NAME(method)( \
BOOST_PP_EXPR_IF(PBR_X_METHOD_HAS_PARAMS(method), PBR_X_DECLARE_METHOD_PARAMS(method))) \
{ \
m_parameters.Clear(); \
BOOST_PP_EXPR_IF(PBR_X_METHOD_HAS_PARAMS(method), PBR_X_PROXY_METHOD_PARAMS(method)) \
BOOST_PP_IF(PBR_X_METHOD_HAS_RETURN(method), PBR_X_METHOD_CALL(method), PBR_X_METHOD_CALLWITHOUTRESULT(method)) \
}

#define PBR_X_PROXY_METHOD_PARAMS(method) \
BOOST_PP_SEQ_FOR_EACH_I(PBR_X_PROXY_METHOD_PARAM, ~, PBR_X_METHOD_PARAMS(method))

#define PBR_X_PROXY_METHOD_PARAM(r, data, i, param) \
m_parameters.Add(). BOOST_PP_TUPLE_ELEM(5, 2, param) (BOOST_PP_CAT(p, i)); \

#define PBR_X_METHOD_CALL(method) \
::ProtoBufRemote::PendingCall* call = m_client.Call(m_serviceName, BOOST_PP_STRINGIZE(PBR_X_METHOD_NAME(method)), \
m_parameters); \
call->Wait(); \
BOOST_PP_TUPLE_ELEM(5, 0, PBR_X_METHOD_RETURN(method)) result \
= call->GetResult()->BOOST_PP_TUPLE_ELEM(5, 3, PBR_X_METHOD_RETURN(method))(); \
m_client.ReleaseCall(call); \
return result;

#define PBR_X_METHOD_CALLWITHOUTRESULT(method) \
m_client.CallWithoutResult(m_serviceName, BOOST_PP_STRINGIZE(PBR_X_METHOD_NAME(method)), m_parameters);


//stub

#define PBR_X_STUB_METHOD(r, data, method) \
virtual BOOST_PP_TUPLE_ELEM(5, 0, PBR_X_METHOD_RETURN(method)) PBR_X_METHOD_NAME(method)( \
BOOST_PP_EXPR_IF(PBR_X_METHOD_HAS_PARAMS(method), PBR_X_DECLARE_METHOD_PARAMS(method))) = 0;

#define PBR_X_STUB_CALL_METHOD(r, data, method) \
else if (strcmp(methodName, BOOST_PP_STRINGIZE(PBR_X_METHOD_NAME(method))) == 0) \
{ \
BOOST_PP_IF(PBR_X_METHOD_HAS_PARAMS(method), PBR_X_STUB_CHECK_PARAMS(method), \
PBR_X_STUB_CHECK_NO_PARAMS(method)) \
}

#define PBR_X_STUB_CHECK_PARAMS(method) \
if (parameters.GetNumParameters() == BOOST_PP_SEQ_SIZE(PBR_X_METHOD_PARAMS(method))) \
{ \
if (BOOST_PP_SEQ_FOR_EACH_I(PBR_X_STUB_CHECK_PARAM, ~, PBR_X_METHOD_PARAMS(method))) \
{ \
PBR_X_STUB_MAKE_CALL(method) \
} \
}

#define PBR_X_STUB_CHECK_NO_PARAMS(method) \
if (parameters.GetNumParameters() == 0) \
{ \
PBR_X_STUB_MAKE_CALL(method) \
}

#define PBR_X_STUB_CHECK_PARAM(r, data, i, param) \
BOOST_PP_EXPR_IF(i, &&) parameters.GetParameter(i).BOOST_PP_TUPLE_ELEM(5, 4, param)()

#define PBR_X_STUB_MAKE_CALL(method) \
BOOST_PP_IF(PBR_X_METHOD_HAS_RETURN(method), PBR_X_STUB_MAKE_CALL_WITH_RETURN(method), \
PBR_X_STUB_MAKE_CALL_WITHOUT_RETURN(method))

#define PBR_X_STUB_MAKE_CALL_WITH_RETURN(method) \
BOOST_PP_TUPLE_ELEM(5, 0, PBR_X_METHOD_RETURN(method)) resultValue = \
PBR_X_METHOD_NAME(method)(BOOST_PP_EXPR_IF(PBR_X_METHOD_HAS_PARAMS(method), \
BOOST_PP_SEQ_FOR_EACH_I(PBR_X_STUB_MAKE_CALL_PARAM, ~, PBR_X_METHOD_PARAMS(method)))); \
result->BOOST_PP_TUPLE_ELEM(5, 2, PBR_X_METHOD_RETURN(method))(resultValue); \
return true;

#define PBR_X_STUB_MAKE_CALL_WITHOUT_RETURN(method) \
PBR_X_METHOD_NAME(method)(BOOST_PP_EXPR_IF(PBR_X_METHOD_HAS_PARAMS(method), \
BOOST_PP_SEQ_FOR_EACH_I(PBR_X_STUB_MAKE_CALL_PARAM, ~, PBR_X_METHOD_PARAMS(method)))); \
return true;

#define PBR_X_STUB_MAKE_CALL_PARAM(r, data, i, param) \
BOOST_PP_COMMA_IF(i) parameters.GetParameter(i).BOOST_PP_TUPLE_ELEM(5, 3, param)()

#endif
27 changes: 27 additions & 0 deletions Cpp/ProtoBufRemote/MutableParameter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include "ProtoBufRemote/MutableParameter.h"


namespace ProtoBufRemote {

MutableParameter::MutableParameter(RpcMessage::Parameter& message)
: Parameter(message), m_message(message)
{
}

void MutableParameter::SetInt(int value)
{
m_message.set_int_param(value);
}

void MutableParameter::SetBool(bool value)
{
m_message.set_bool_param(value);
}

void MutableParameter::SetString(const std::string& value)
{
m_message.set_string_param(value);
}

}
23 changes: 23 additions & 0 deletions Cpp/ProtoBufRemote/MutableParameter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef PROTOBUFREMOTE_MUTABLEPARAMETER_H
#define PROTOBUFREMOTE_MUTABLEPARAMETER_H 1

#include "ProtoBufRemote/Parameter.h"

namespace ProtoBufRemote {

class MutableParameter : public Parameter
{
public:
explicit MutableParameter(RpcMessage::Parameter& message);

void SetInt(int value);
void SetBool(bool value);
void SetString(const std::string& value);

private:
RpcMessage::Parameter& m_message;
};

}

#endif
23 changes: 23 additions & 0 deletions Cpp/ProtoBufRemote/MutableParameterList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#include "ProtoBufRemote/MutableParameterList.h"


namespace ProtoBufRemote {

MutableParameterList::MutableParameterList(RpcMessage& message)
: ParameterList(message), m_message(message)
{
}

void MutableParameterList::Clear()
{
m_message.mutable_call_message()->clear_parameters();
}

MutableParameter MutableParameterList::Add()
{
RpcMessage::Parameter* paramMessage = m_message.mutable_call_message()->add_parameters();
return MutableParameter(*paramMessage);
}

}
23 changes: 23 additions & 0 deletions Cpp/ProtoBufRemote/MutableParameterList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef PROTOBUFREMOTE_MUTABLEPARAMETERLIST_H
#define PROTOBUFREMOTE_MUTABLEPARAMETERLIST_H 1

#include "ProtoBufRemote/ParameterList.h"

namespace ProtoBufRemote {

class MutableParameterList : public ParameterList
{
public:
MutableParameterList(RpcMessage& message);

void Clear();

MutableParameter Add();

private:
RpcMessage& m_message;
};

}

#endif
44 changes: 44 additions & 0 deletions Cpp/ProtoBufRemote/Parameter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#include "ProtoBufRemote/Parameter.h"

namespace ProtoBufRemote {

Parameter::Parameter(const RpcMessage::Parameter& message)
: m_message(message)
{
}

bool Parameter::IsInt() const
{
return m_message.has_int_param();
}

bool Parameter::IsBool() const
{
return m_message.has_bool_param();
}

bool Parameter::IsString() const
{
return m_message.has_string_param();
}

int Parameter::GetInt() const
{
assert(m_message.has_int_param());
return m_message.int_param();
}

bool Parameter::GetBool() const
{
assert(m_message.has_bool_param());
return m_message.bool_param();
}

const std::string& Parameter::GetString() const
{
assert(m_message.has_string_param());
return m_message.string_param();
}

}
27 changes: 27 additions & 0 deletions Cpp/ProtoBufRemote/Parameter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef PROTOBUFREMOTE_PARAMETER_H
#define PROTOBUFREMOTE_PARAMETER_H 1

#include "ProtoBufRemote/RpcMessage.pb.h"

namespace ProtoBufRemote {

class Parameter
{
public:
explicit Parameter(const RpcMessage::Parameter& message);

int GetInt() const;
bool GetBool() const;
const std::string& GetString() const;

bool IsInt() const;
bool IsBool() const;
bool IsString() const;

private:
const RpcMessage::Parameter& m_message;
};

}

#endif
Loading

0 comments on commit 25b877a

Please sign in to comment.