summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Ice/Object.cpp')
-rw-r--r--cpp/src/Ice/Object.cpp434
1 files changed, 212 insertions, 222 deletions
diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp
index cf66c35b41c..db4b01cf72e 100644
--- a/cpp/src/Ice/Object.cpp
+++ b/cpp/src/Ice/Object.cpp
@@ -12,17 +12,22 @@
#include <Ice/IncomingAsync.h>
#include <Ice/IncomingRequest.h>
#include <Ice/LocalException.h>
-#include <Ice/Stream.h>
#include <Ice/SlicedData.h>
using namespace std;
using namespace Ice;
using namespace IceInternal;
+namespace Ice
+{
+const Current noExplicitCurrent = Current();
+}
+
+#ifndef ICE_CPP11_MAPPING
Object* Ice::upCast(Object* p) { return p; }
-void
-Ice::__patch(ObjectPtr& obj, const ObjectPtr& v)
+void
+Ice::_icePatchObjectPtr(ObjectPtr& obj, const ObjectPtr& v)
{
obj = v;
}
@@ -38,22 +43,46 @@ Ice::Object::operator<(const Object& r) const
{
return this < &r;
}
-
+#endif
namespace
{
-const string __Ice__Object_ids[] =
+const string object_ids[] =
{
"::Ice::Object"
};
+const string object_all[] =
+{
+ "ice_id",
+ "ice_ids",
+ "ice_isA",
+ "ice_ping"
+};
+
+}
+
+#ifndef ICE_CPP11_MAPPING
+Ice::DispatchInterceptorAsyncCallback::~DispatchInterceptorAsyncCallback()
+{
+ // Out of line to avoid weak vtable
+}
+#endif
+
+Ice::Request::~Request()
+{
+ // Out of line to avoid weak vtable
}
bool
+#ifdef ICE_CPP11_MAPPING
+Ice::Object::ice_isA(string s, const Current&) const
+#else
Ice::Object::ice_isA(const string& s, const Current&) const
+#endif
{
- return s == __Ice__Object_ids[0];
+ return s == object_ids[0];
}
void
@@ -65,213 +94,188 @@ Ice::Object::ice_ping(const Current&) const
vector<string>
Ice::Object::ice_ids(const Current&) const
{
- return vector<string>(&__Ice__Object_ids[0], &__Ice__Object_ids[1]);
+ return vector<string>(&object_ids[0], &object_ids[1]);
}
+#ifdef ICE_CPP11_MAPPING
+string
+#else
const string&
+#endif
Ice::Object::ice_id(const Current&) const
{
- return __Ice__Object_ids[0];
+ return object_ids[0];
}
const ::std::string&
Ice::Object::ice_staticId()
{
- return __Ice__Object_ids[0];
+ return object_ids[0];
}
+#ifndef ICE_CPP11_MAPPING
Ice::ObjectPtr
Ice::Object::ice_clone() const
{
throw CloneNotImplementedException(__FILE__, __LINE__);
return 0; // avoid warning with some compilers
}
+#endif
-void
-Ice::Object::ice_preMarshal()
-{
-}
-
-void
-Ice::Object::ice_postUnmarshal()
-{
-}
-
-DispatchStatus
-Ice::Object::___ice_isA(Incoming& __inS, const Current& __current)
-{
- BasicStream* __is = __inS.startReadParams();
- string __id;
- __is->read(__id, false);
- __inS.endReadParams();
- bool __ret = ice_isA(__id, __current);
- BasicStream* __os = __inS.__startWriteParams(DefaultFormat);
- __os->write(__ret);
- __inS.__endWriteParams(true);
- return DispatchOK;
-}
-
-DispatchStatus
-Ice::Object::___ice_ping(Incoming& __inS, const Current& __current)
-{
- __inS.readEmptyParams();
- ice_ping(__current);
- __inS.__writeEmptyParams();
- return DispatchOK;
+bool
+Ice::Object::_iceD_ice_isA(Incoming& inS, const Current& current)
+{
+ InputStream* istr = inS.startReadParams();
+ string iceP_id;
+ istr->read(iceP_id, false);
+ inS.endReadParams();
+#ifdef ICE_CPP11_MAPPING
+ bool ret = ice_isA(move(iceP_id), current);
+#else
+ bool ret = ice_isA(iceP_id, current);
+#endif
+ OutputStream* ostr = inS.startWriteParams();
+ ostr->write(ret);
+ inS.endWriteParams();
+ return false;
}
-DispatchStatus
-Ice::Object::___ice_ids(Incoming& __inS, const Current& __current)
+bool
+Ice::Object::_iceD_ice_ping(Incoming& inS, const Current& current)
{
- __inS.readEmptyParams();
- vector<string> __ret = ice_ids(__current);
- BasicStream* __os = __inS.__startWriteParams(DefaultFormat);
- __os->write(&__ret[0], &__ret[0] + __ret.size(), false);
- __inS.__endWriteParams(true);
- return DispatchOK;
+ inS.readEmptyParams();
+ ice_ping(current);
+ inS.writeEmptyParams();
+ return false;
}
-DispatchStatus
-Ice::Object::___ice_id(Incoming& __inS, const Current& __current)
+bool
+Ice::Object::_iceD_ice_ids(Incoming& inS, const Current& current)
{
- __inS.readEmptyParams();
- string __ret = ice_id(__current);
- BasicStream* __os = __inS.__startWriteParams(DefaultFormat);
- __os->write(__ret, false);
- __inS.__endWriteParams(true);
- return DispatchOK;
+ inS.readEmptyParams();
+ vector<string> ret = ice_ids(current);
+ OutputStream* ostr = inS.startWriteParams();
+ ostr->write(&ret[0], &ret[0] + ret.size(), false);
+ inS.endWriteParams();
+ return false;
}
-Ice::Int
-Ice::Object::ice_operationAttributes(const string&) const
+bool
+Ice::Object::_iceD_ice_id(Incoming& inS, const Current& current)
{
- return 0;
+ inS.readEmptyParams();
+ string ret = ice_id(current);
+ OutputStream* ostr = inS.startWriteParams();
+ ostr->write(ret, false);
+ inS.endWriteParams();
+ return false;
}
-string Ice::Object::__all[] =
-{
- "ice_id",
- "ice_ids",
- "ice_isA",
- "ice_ping"
-};
-
-
-DispatchStatus
+bool
+#ifdef ICE_CPP11_MAPPING
+Ice::Object::ice_dispatch(Request& request, std::function<bool()> r, std::function<bool(std::exception_ptr)> e)
+#else
Ice::Object::ice_dispatch(Request& request, const DispatchInterceptorAsyncCallbackPtr& cb)
+#endif
{
- class PushCb
+ IceInternal::Incoming& in = dynamic_cast<IceInternal::IncomingRequest&>(request)._in;
+ in.startOver();
+#ifdef ICE_CPP11_MAPPING
+ if(r || e)
+ {
+ in.push(r, e);
+#else
+ if(cb)
{
- public:
- PushCb(IceInternal::Incoming& in, const DispatchInterceptorAsyncCallbackPtr& cb) :
- _in(in),
- _cb(cb)
+ in.push(cb);
+#endif
+ try
{
- if(_cb != 0)
- {
- _in.push(_cb);
- }
+ return _iceDispatch(in, in.getCurrent());
+ in.pop();
}
-
- ~PushCb()
+ catch(...)
{
- if(_cb != 0)
- {
- _in.pop();
- }
+ in.pop();
+ throw;
}
- private:
- IceInternal::Incoming& _in;
- const DispatchInterceptorAsyncCallbackPtr& _cb;
- };
-
-
- IceInternal::Incoming& in = dynamic_cast<IceInternal::IncomingRequest&>(request)._in;
-
- PushCb pusbCb(in, cb);
- in.startOver(); // may raise ResponseSentException
- return __dispatch(in, in.getCurrent());
+ }
+ else
+ {
+ return _iceDispatch(in, in.getCurrent());
+ }
}
-DispatchStatus
-Ice::Object::__dispatch(Incoming& in, const Current& current)
+bool
+Ice::Object::_iceDispatch(Incoming& in, const Current& current)
{
- pair<string*, string*> r =
- equal_range(__all, __all + sizeof(__all) / sizeof(string), current.operation);
+ pair<const string*, const string*> r = equal_range(object_all, object_all + sizeof(object_all) / sizeof(string), current.operation);
if(r.first == r.second)
{
throw OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);
- }
+ }
- switch(r.first - __all)
+ switch(r.first - object_all)
{
case 0:
{
- return ___ice_id(in, current);
+ return _iceD_ice_id(in, current);
}
case 1:
{
- return ___ice_ids(in, current);
+ return _iceD_ice_ids(in, current);
}
case 2:
{
- return ___ice_isA(in, current);
+ return _iceD_ice_isA(in, current);
}
case 3:
{
- return ___ice_ping(in, current);
+ return _iceD_ice_ping(in, current);
+ }
+ default:
+ {
+ assert(false);
+ throw OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);
}
}
-
- assert(false);
- throw OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);
}
+#ifndef ICE_CPP11_MAPPING
void
-Ice::Object::__write(IceInternal::BasicStream* os) const
-{
- os->startWriteObject(0);
- __writeImpl(os);
- os->endWriteObject();
-}
-
-void
-Ice::Object::__read(IceInternal::BasicStream* is)
+Ice::Object::ice_preMarshal()
{
- is->startReadObject();
- __readImpl(is);
- is->endReadObject(false);
}
-
-void
-Ice::Object::__write(const OutputStreamPtr& os) const
+
+void
+Ice::Object::ice_postUnmarshal()
{
- os->startObject(0);
- __writeImpl(os);
- os->endObject();
}
-
-void
-Ice::Object::__read(const InputStreamPtr& is)
+
+void
+Ice::Object::_iceWrite(Ice::OutputStream* os) const
{
- is->startObject();
- __readImpl(is);
- is->endObject(false);
+ os->startValue(0);
+ _iceWriteImpl(os);
+ os->endValue();
}
-
-void
-Ice::Object::__writeImpl(const OutputStreamPtr&) const
+
+void
+Ice::Object::_iceRead(Ice::InputStream* is)
{
- throw MarshalException(__FILE__, __LINE__, "class was not generated with stream support");
+ is->startValue();
+ _iceReadImpl(is);
+ is->endValue(false);
}
-
-void
-Ice::Object::__readImpl(const InputStreamPtr&)
+
+Ice::Int
+Ice::Object::ice_operationAttributes(const string&) const
{
- throw MarshalException(__FILE__, __LINE__, "class was not generated with stream support");
+ return 0;
}
+#endif
namespace
{
@@ -281,34 +285,41 @@ operationModeToString(OperationMode mode)
{
switch(mode)
{
- case Normal:
+ case ICE_ENUM(OperationMode, Normal):
return "::Ice::Normal";
- case Nonmutating:
+ case ICE_ENUM(OperationMode, Nonmutating):
return "::Ice::Nonmutating";
- case Idempotent:
+ case ICE_ENUM(OperationMode, Idempotent):
return "::Ice::Idempotent";
}
-
+ //
+ // This could not happen with C++11 strong type enums
+ //
+#ifdef ICE_CPP11_MAPPING
+ assert(false);
+ return "";
+#else
ostringstream os;
os << "unknown value (" << mode << ")";
return os.str();
+#endif
}
}
void
-Ice::Object::__checkMode(OperationMode expected, OperationMode received)
+Ice::Object::_iceCheckMode(OperationMode expected, OperationMode received)
{
if(expected != received)
{
- if(expected == Idempotent && received == Nonmutating)
+ if(expected == ICE_ENUM(OperationMode, Idempotent) && received == ICE_ENUM(OperationMode, Nonmutating))
{
- //
+ //
// Fine: typically an old client still using the deprecated nonmutating keyword
//
-
+
//
// Note that expected == Nonmutating and received == Idempotent is not ok:
// the server may still use the deprecated nonmutating keyword to detect updates
@@ -318,19 +329,19 @@ Ice::Object::__checkMode(OperationMode expected, OperationMode received)
else
{
Ice::MarshalException ex(__FILE__, __LINE__);
- std::ostringstream __reason;
- __reason << "unexpected operation mode. expected = "
- << operationModeToString(expected)
- << " received = "
- << operationModeToString(received);
- ex.reason = __reason.str();
+ std::ostringstream reason;
+ reason << "unexpected operation mode. expected = "
+ << operationModeToString(expected)
+ << " received = "
+ << operationModeToString(received);
+ ex.reason = reason.str();
throw ex;
}
}
}
-DispatchStatus
-Ice::Blobject::__dispatch(Incoming& in, const Current& current)
+bool
+Ice::Blobject::_iceDispatch(Incoming& in, const Current& current)
{
const Byte* inEncaps;
Int sz;
@@ -339,24 +350,17 @@ Ice::Blobject::__dispatch(Incoming& in, const Current& current)
bool ok = ice_invoke(vector<Byte>(inEncaps, inEncaps + sz), outEncaps, current);
if(outEncaps.empty())
{
- in.__writeParamEncaps(0, 0, ok);
- }
- else
- {
- in.__writeParamEncaps(&outEncaps[0], static_cast<Ice::Int>(outEncaps.size()), ok);
- }
- if(ok)
- {
- return DispatchOK;
+ in.writeParamEncaps(0, 0, ok);
}
else
{
- return DispatchUserException;
+ in.writeParamEncaps(&outEncaps[0], static_cast<Ice::Int>(outEncaps.size()), ok);
}
+ return false;
}
-DispatchStatus
-Ice::BlobjectArray::__dispatch(Incoming& in, const Current& current)
+bool
+Ice::BlobjectArray::_iceDispatch(Incoming& in, const Current& current)
{
pair<const Byte*, const Byte*> inEncaps;
Int sz;
@@ -366,75 +370,61 @@ Ice::BlobjectArray::__dispatch(Incoming& in, const Current& current)
bool ok = ice_invoke(inEncaps, outEncaps, current);
if(outEncaps.empty())
{
- in.__writeParamEncaps(0, 0, ok);
- }
- else
- {
- in.__writeParamEncaps(&outEncaps[0], static_cast<Ice::Int>(outEncaps.size()), ok);
- }
- if(ok)
- {
- return DispatchOK;
+ in.writeParamEncaps(0, 0, ok);
}
else
{
- return DispatchUserException;
+ in.writeParamEncaps(&outEncaps[0], static_cast<Ice::Int>(outEncaps.size()), ok);
}
+ return false;
}
-DispatchStatus
-Ice::BlobjectAsync::__dispatch(Incoming& in, const Current& current)
+bool
+Ice::BlobjectAsync::_iceDispatch(Incoming& in, const Current& current)
{
const Byte* inEncaps;
Int sz;
in.readParamEncaps(inEncaps, sz);
- AMD_Object_ice_invokePtr cb = new ::IceAsync::Ice::AMD_Object_ice_invoke(in);
- try
- {
- ice_invoke_async(cb, vector<Byte>(inEncaps, inEncaps + sz), current);
- }
- catch(const ::std::exception& ex)
- {
- cb->ice_exception(ex);
- }
- catch(...)
- {
- cb->ice_exception();
- }
- return DispatchAsync;
+#ifdef ICE_CPP11_MAPPING
+ auto async = IncomingAsync::create(in);
+ ice_invokeAsync(vector<Byte>(inEncaps, inEncaps + sz),
+ [async](bool ok, const vector<Byte>& outEncaps)
+ {
+ if(outEncaps.empty())
+ {
+ async->writeParamEncaps(0, 0, ok);
+ }
+ else
+ {
+ async->writeParamEncaps(&outEncaps[0], static_cast<Int>(outEncaps.size()), ok);
+ }
+ async->completed();
+ },
+ async->exception(), current);
+#else
+ ice_invoke_async(new ::IceAsync::Ice::AMD_Object_ice_invoke(in), vector<Byte>(inEncaps, inEncaps + sz), current);
+#endif
+ return true;
}
-DispatchStatus
-Ice::BlobjectArrayAsync::__dispatch(Incoming& in, const Current& current)
+bool
+Ice::BlobjectArrayAsync::_iceDispatch(Incoming& in, const Current& current)
{
pair<const Byte*, const Byte*> inEncaps;
Int sz;
in.readParamEncaps(inEncaps.first, sz);
inEncaps.second = inEncaps.first + sz;
- AMD_Object_ice_invokePtr cb = new ::IceAsync::Ice::AMD_Object_ice_invoke(in);
- try
- {
- ice_invoke_async(cb, inEncaps, current);
- }
- catch(const ::std::exception& ex)
- {
- cb->ice_exception(ex);
- }
- catch(...)
- {
- cb->ice_exception();
- }
- return DispatchAsync;
-}
-
-void
-Ice::ice_writeObject(const OutputStreamPtr& out, const ObjectPtr& p)
-{
- out->write(p);
-}
-
-void
-Ice::ice_readObject(const InputStreamPtr& in, ObjectPtr& p)
-{
- in->read(p);
+#ifdef ICE_CPP11_MAPPING
+ auto async = IncomingAsync::create(in);
+ ice_invokeAsync(inEncaps,
+ [async](bool ok, const pair<const Byte*, const Byte*>& outE)
+ {
+ async->writeParamEncaps(outE.first, static_cast<Int>(outE.second - outE.first), ok);
+ async->completed();
+ },
+ async->exception(), current);
+#else
+ ice_invoke_async(new ::IceAsync::Ice::AMD_Object_ice_invoke(in), inEncaps, current);
+#endif
+ return true;
}