Skip to content

Commit

Permalink
support for all other parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
Niall Ryan authored and Niall Ryan committed Jun 5, 2010
1 parent d359a04 commit 179b32c
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 35 deletions.
95 changes: 74 additions & 21 deletions Cpp/ProtoBufRemote/Generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,60 @@

#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))
//is non-void, is result as parameter ptr, can get ref, type, parameter type, return type, set func, get func, is set func
#define PBR_VOID ((0, 0, 0, void, void, void, ~, ~, ~))
#define PBR_CHAR ((1, 0, 1, signed char, signed char, signed char, SetChar, GetChar, IsChar))
#define PBR_UCHAR ((1, 0, 1, unsigned char, unsigned char, unsigned char, SetUnsignedChar, GetUnsignedChar, IsUnsignedChar))
#define PBR_SHORT ((1, 0, 1, short, short, short, SetShort, GetShort, IsShort))
#define PBR_USHORT ((1, 0, 1, unsigned short, unsigned short, unsigned short, SetUnsignedShort, GetUnsignedShort, IsUnsignedShort))
#define PBR_INT ((1, 0, 1, int, int, int, SetInt, GetInt, IsInt))
#define PBR_UINT ((1, 0, 1, unsigned int, unsigned int, unsigned int, SetUnsignedInt, GetUnsignedInt, IsUnsignedInt))
#define PBR_INT64 ((1, 0, 1, long long, long long, long long, SetInt64, GetInt64, IsInt64))
#define PBR_UINT64 ((1, 0, 1, unsigned long long, unsigned long long, unsigned long long, SetUnsignedInt64, GetUnsignedInt64, IsUnsignedInt64))
#define PBR_BOOL ((1, 0, 1, bool, bool, bool, SetBool, GetBool, IsBool))
#define PBR_STRING ((1, 1, 1, std::string, const std::string&, void, SetString, GetString, IsString))
#define PBR_WCHAR ((1, 0, 1, wchar_t, wchar_t, wchar_t, SetWChar, GetWChar, IsWChar))
#define PBR_PROTO(protoType) ((1, 1, 0, protoType, const protoType&, void, SetProto, GetProto, IsProto))


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

#define PBR_X_PARAM_IS_NON_VOID(param) BOOST_PP_TUPLE_ELEM(9, 0, param)
#define PBR_X_PARAM_IS_RESULT_PTR(param) BOOST_PP_TUPLE_ELEM(9, 1, param)
#define PBR_X_PARAM_CAN_GET_REF(param) BOOST_PP_TUPLE_ELEM(9, 2, param)
#define PBR_X_PARAM_TYPE(param) BOOST_PP_TUPLE_ELEM(9, 3, param)
#define PBR_X_PARAM_PARAM_TYPE(param) BOOST_PP_TUPLE_ELEM(9, 4, param)
#define PBR_X_PARAM_RETURN_TYPE(param) BOOST_PP_TUPLE_ELEM(9, 5, param)
#define PBR_X_PARAM_SET_FUNC(param) BOOST_PP_TUPLE_ELEM(9, 6, param)
#define PBR_X_PARAM_GET_FUNC(param) BOOST_PP_TUPLE_ELEM(9, 7, param)
#define PBR_X_PARAM_CHECK_FUNC(param) BOOST_PP_TUPLE_ELEM(9, 8, param)

#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_METHOD_HAS_RETURN(method) PBR_X_PARAM_IS_NON_VOID(PBR_X_METHOD_RETURN(method))
#define PBR_X_METHOD_HAS_PARAMS(method) PBR_X_PARAM_IS_NON_VOID(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))
BOOST_PP_EXPR_IF(PBR_X_METHOD_HAS_PARAMS(method), \
BOOST_PP_SEQ_FOR_EACH_I(PBR_X_DECLARE_METHOD_PARAM, ~, PBR_X_METHOD_PARAMS(method))) \
BOOST_PP_EXPR_IF( \
BOOST_PP_AND(PBR_X_METHOD_HAS_PARAMS(method), PBR_X_PARAM_IS_RESULT_PTR(PBR_X_METHOD_RETURN(method))), \
BOOST_PP_COMMA()) \
BOOST_PP_EXPR_IF(PBR_X_PARAM_IS_RESULT_PTR(PBR_X_METHOD_RETURN(method)), \
PBR_X_PARAM_TYPE(PBR_X_METHOD_RETURN(method))* resultPtr)

#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)
BOOST_PP_COMMA_IF(i) PBR_X_PARAM_PARAM_TYPE(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))) \
PBR_X_PARAM_RETURN_TYPE(PBR_X_METHOD_RETURN(method)) PBR_X_METHOD_NAME(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)) \
Expand All @@ -92,16 +118,21 @@
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)); \
m_parameters.Add().PBR_X_PARAM_SET_FUNC(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;
BOOST_PP_IF(PBR_X_PARAM_IS_RESULT_PTR(PBR_X_METHOD_RETURN(method)), \
call->GetResult()->PBR_X_PARAM_GET_FUNC(PBR_X_METHOD_RETURN(method))(resultPtr); \
m_client.ReleaseCall(call); \
, \
PBR_X_PARAM_TYPE(PBR_X_METHOD_RETURN(method)) result \
= call->GetResult()->PBR_X_PARAM_GET_FUNC(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);
Expand All @@ -110,8 +141,8 @@
//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;
virtual PBR_X_PARAM_RETURN_TYPE(PBR_X_METHOD_RETURN(method)) PBR_X_METHOD_NAME(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) \
Expand All @@ -136,17 +167,39 @@
}

#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)()
BOOST_PP_EXPR_IF(i, &&) parameters.GetParameter(i).PBR_X_PARAM_CHECK_FUNC(param)()

#define PBR_X_STUB_MAKE_CALL(method) \
BOOST_PP_EXPR_IF(PBR_X_METHOD_HAS_PARAMS(method), \
BOOST_PP_SEQ_FOR_EACH_I(PBR_X_STUB_PREPARE_PARAM, ~, PBR_X_METHOD_PARAMS(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_PREPARE_PARAM(r, data, i, param) \
BOOST_PP_IF(PBR_X_PARAM_CAN_GET_REF(param), \
PBR_X_PARAM_PARAM_TYPE(param) BOOST_PP_CAT(p, i) = parameters.GetParameter(i).PBR_X_PARAM_GET_FUNC(param)(); \
, \
PBR_X_PARAM_TYPE(param) BOOST_PP_CAT(p, i); \
parameters.GetParameter(i).PBR_X_PARAM_GET_FUNC(param)(&BOOST_PP_CAT(p, i)); \
)

#define PBR_X_STUB_MAKE_CALL_WITH_RETURN(method) \
BOOST_PP_TUPLE_ELEM(5, 0, PBR_X_METHOD_RETURN(method)) resultValue = \
BOOST_PP_IF(PBR_X_PARAM_IS_RESULT_PTR(PBR_X_METHOD_RETURN(method)), \
PBR_X_STUB_MAKE_CALL_WITH_RETURN_PTR(method), \
PBR_X_STUB_MAKE_CALL_WITH_RETURN_STD(method))

#define PBR_X_STUB_MAKE_CALL_WITH_RETURN_STD(method) \
PBR_X_PARAM_TYPE(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); \
result->PBR_X_PARAM_SET_FUNC(PBR_X_METHOD_RETURN(method))(resultValue); \
return true;

#define PBR_X_STUB_MAKE_CALL_WITH_RETURN_PTR(method) \
PBR_X_PARAM_TYPE(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))), &resultValue); \
result->PBR_X_PARAM_SET_FUNC(PBR_X_METHOD_RETURN(method))(resultValue); \
return true;

#define PBR_X_STUB_MAKE_CALL_WITHOUT_RETURN(method) \
Expand All @@ -155,6 +208,6 @@
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)()
BOOST_PP_COMMA_IF(i) BOOST_PP_CAT(p, i)

#endif
50 changes: 45 additions & 5 deletions Cpp/ProtoBufRemote/MutableParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,64 @@

namespace ProtoBufRemote {

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

void MutableParameter::SetChar(signed char value)
{
m_message->set_int_param(value);
}

void MutableParameter::SetUnsignedChar(unsigned char value)
{
m_message->set_uint_param(value);
}

void MutableParameter::SetShort(short value)
{
m_message->set_int_param(value);
}

void MutableParameter::SetUnsignedShort(unsigned short value)
{
m_message->set_uint_param(value);
}

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

void MutableParameter::SetUnsignedInt(unsigned int value)
{
m_message->set_uint_param(value);
}

void MutableParameter::SetInt64(long long value)
{
m_message->set_int64_param(value);
}

void MutableParameter::SetUnsignedInt64(unsigned long long value)
{
m_message->set_uint64_param(value);
}

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

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

void MutableParameter::SetWChar(wchar_t value)
{
m_message->set_uint_param(value);
}

}
19 changes: 17 additions & 2 deletions Cpp/ProtoBufRemote/MutableParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ namespace ProtoBufRemote {
class MutableParameter : public Parameter
{
public:
explicit MutableParameter(RpcMessage::Parameter& message);
explicit MutableParameter(RpcMessage::Parameter* message);

void SetChar(signed char value);
void SetUnsignedChar(unsigned char value);
void SetShort(short value);
void SetUnsignedShort(unsigned short value);
void SetInt(int value);
void SetUnsignedInt(unsigned int value);
void SetInt64(long long value);
void SetUnsignedInt64(unsigned long long value);

void SetBool(bool value);
void SetString(const std::string& value);
void SetWChar(wchar_t value);

template<typename T>
bool SetProto(const T& value)
{
return value.SerializeToString(m_message->mutable_proto_param());
}

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

}
Expand Down
2 changes: 1 addition & 1 deletion Cpp/ProtoBufRemote/MutableParameterList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void MutableParameterList::Clear()
MutableParameter MutableParameterList::Add()
{
RpcMessage::Parameter* paramMessage = m_message.mutable_call_message()->add_parameters();
return MutableParameter(*paramMessage);
return MutableParameter(paramMessage);
}

}
93 changes: 93 additions & 0 deletions Cpp/ProtoBufRemote/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,46 @@ Parameter::Parameter(const RpcMessage::Parameter& message)
{
}

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

bool Parameter::IsUnsignedChar() const
{
return m_message.has_uint_param();
}

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

bool Parameter::IsUnsignedShort() const
{
return m_message.has_uint_param();
}

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

bool Parameter::IsUnsignedInt() const
{
return m_message.has_uint_param();
}

bool Parameter::IsInt64() const
{
return m_message.has_int64_param();
}

bool Parameter::IsUnsignedInt64() const
{
return m_message.has_uint64_param();
}

bool Parameter::IsBool() const
{
return m_message.has_bool_param();
Expand All @@ -23,12 +58,64 @@ bool Parameter::IsString() const
return m_message.has_string_param();
}

bool Parameter::IsWChar() const
{
return m_message.has_uint_param();
}

bool Parameter::IsProto() const
{
return m_message.has_proto_param();
}

signed char Parameter::GetChar() const
{
assert(m_message.has_int_param());
return m_message.int_param();
}

unsigned char Parameter::GetUnsignedChar() const
{
assert(m_message.has_uint_param());
return m_message.uint_param();
}

short Parameter::GetShort() const
{
assert(m_message.has_int_param());
return m_message.int_param();
}

unsigned short Parameter::GetUnsignedShort() const
{
assert(m_message.has_uint_param());
return m_message.uint_param();
}

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

unsigned int Parameter::GetUnsignedInt() const
{
assert(m_message.has_uint_param());
return m_message.uint_param();
}

long long Parameter::GetInt64() const
{
assert(m_message.has_int64_param());
return m_message.int64_param();
}

unsigned long long Parameter::GetUnsignedInt64() const
{
assert(m_message.has_uint64_param());
return m_message.uint64_param();
}

bool Parameter::GetBool() const
{
assert(m_message.has_bool_param());
Expand All @@ -41,4 +128,10 @@ const std::string& Parameter::GetString() const
return m_message.string_param();
}

wchar_t Parameter::GetWChar() const
{
assert(m_message.has_uint_param());
return m_message.uint_param();
}

}
Loading

0 comments on commit 179b32c

Please sign in to comment.