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.cpp331
1 files changed, 161 insertions, 170 deletions
diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp
index fa39befdd9d..197c54e1918 100644
--- a/cpp/src/Ice/Object.cpp
+++ b/cpp/src/Ice/Object.cpp
@@ -12,16 +12,21 @@
#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
+void
Ice::__patch(ObjectPtr& obj, const ObjectPtr& v)
{
obj = v;
@@ -38,7 +43,7 @@ Ice::Object::operator<(const Object& r) const
{
return this < &r;
}
-
+#endif
namespace
{
@@ -50,8 +55,24 @@ const string __Ice__Object_ids[] =
}
+#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];
}
@@ -68,7 +89,11 @@ Ice::Object::ice_ids(const Current&) const
return vector<string>(&__Ice__Object_ids[0], &__Ice__Object_ids[1]);
}
+#ifdef ICE_CPP11_MAPPING
+string
+#else
const string&
+#endif
Ice::Object::ice_id(const Current&) const
{
return __Ice__Object_ids[0];
@@ -80,72 +105,62 @@ Ice::Object::ice_staticId()
return __Ice__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
+bool
Ice::Object::___ice_isA(Incoming& __inS, const Current& __current)
{
- BasicStream* __is = __inS.startReadParams();
+ InputStream* __is = __inS.startReadParams();
string __id;
__is->read(__id, false);
__inS.endReadParams();
+#ifdef ICE_CPP11_MAPPING
+ bool __ret = ice_isA(move(__id), __current);
+#else
bool __ret = ice_isA(__id, __current);
- BasicStream* __os = __inS.__startWriteParams(DefaultFormat);
+#endif
+ OutputStream* __os = __inS.startWriteParams();
__os->write(__ret);
- __inS.__endWriteParams(true);
- return DispatchOK;
+ __inS.endWriteParams();
+ return false;
}
-DispatchStatus
+bool
Ice::Object::___ice_ping(Incoming& __inS, const Current& __current)
{
__inS.readEmptyParams();
ice_ping(__current);
- __inS.__writeEmptyParams();
- return DispatchOK;
+ __inS.writeEmptyParams();
+ return false;
}
-DispatchStatus
+bool
Ice::Object::___ice_ids(Incoming& __inS, const Current& __current)
{
__inS.readEmptyParams();
vector<string> __ret = ice_ids(__current);
- BasicStream* __os = __inS.__startWriteParams(DefaultFormat);
+ OutputStream* __os = __inS.startWriteParams();
__os->write(&__ret[0], &__ret[0] + __ret.size(), false);
- __inS.__endWriteParams(true);
- return DispatchOK;
+ __inS.endWriteParams();
+ return false;
}
-DispatchStatus
+bool
Ice::Object::___ice_id(Incoming& __inS, const Current& __current)
{
__inS.readEmptyParams();
string __ret = ice_id(__current);
- BasicStream* __os = __inS.__startWriteParams(DefaultFormat);
+ OutputStream* __os = __inS.startWriteParams();
__os->write(__ret, false);
- __inS.__endWriteParams(true);
- return DispatchOK;
-}
-
-Ice::Int
-Ice::Object::ice_operationAttributes(const string&) const
-{
- return 0;
+ __inS.endWriteParams();
+ return false;
}
@@ -158,52 +173,50 @@ string Ice::Object::__all[] =
};
-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 __dispatch(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 __dispatch(in, in.getCurrent());
+ }
}
-DispatchStatus
+bool
Ice::Object::__dispatch(Incoming& in, const Current& current)
{
- pair<string*, string*> r =
- equal_range(__all, __all + sizeof(__all) / sizeof(string), current.operation);
+ pair<string*, string*> r = equal_range(__all, __all + sizeof(__all) / sizeof(string), current.operation);
if(r.first == r.second)
{
throw OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);
- }
+ }
switch(r.first - __all)
{
@@ -223,55 +236,47 @@ Ice::Object::__dispatch(Incoming& in, const Current& current)
{
return ___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
+Ice::Object::ice_preMarshal()
{
- os->startWriteObject(0);
- __writeImpl(os);
- os->endWriteObject();
}
-
-void
-Ice::Object::__read(IceInternal::BasicStream* is)
+
+void
+Ice::Object::ice_postUnmarshal()
{
- is->startReadObject();
- __readImpl(is);
- is->endReadObject(false);
}
-
-void
-Ice::Object::__write(const OutputStreamPtr& os) const
+
+void
+Ice::Object::__write(Ice::OutputStream* os) const
{
- os->startObject(0);
+ os->startValue(0);
__writeImpl(os);
- os->endObject();
+ os->endValue();
}
-
-void
-Ice::Object::__read(const InputStreamPtr& is)
+
+void
+Ice::Object::__read(Ice::InputStream* is)
{
- is->startObject();
+ is->startValue();
__readImpl(is);
- is->endObject(false);
+ is->endValue(false);
}
-
-void
-Ice::Object::__writeImpl(const OutputStreamPtr&) const
-{
- throw MarshalException(__FILE__, __LINE__, "class was not generated with stream support");
-}
-
-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,19 +286,26 @@ 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
}
}
@@ -303,12 +315,12 @@ Ice::Object::__checkMode(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
@@ -329,7 +341,7 @@ Ice::Object::__checkMode(OperationMode expected, OperationMode received)
}
}
-DispatchStatus
+bool
Ice::Blobject::__dispatch(Incoming& in, const Current& current)
{
const Byte* inEncaps;
@@ -339,23 +351,16 @@ 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);
+ in.writeParamEncaps(0, 0, ok);
}
else
{
- in.__writeParamEncaps(&outEncaps[0], static_cast<Ice::Int>(outEncaps.size()), ok);
- }
- if(ok)
- {
- return DispatchOK;
- }
- else
- {
- return DispatchUserException;
+ in.writeParamEncaps(&outEncaps[0], static_cast<Ice::Int>(outEncaps.size()), ok);
}
+ return false;
}
-DispatchStatus
+bool
Ice::BlobjectArray::__dispatch(Incoming& in, const Current& current)
{
pair<const Byte*, const Byte*> inEncaps;
@@ -366,75 +371,61 @@ Ice::BlobjectArray::__dispatch(Incoming& in, const Current& current)
bool ok = ice_invoke(inEncaps, outEncaps, current);
if(outEncaps.empty())
{
- in.__writeParamEncaps(0, 0, ok);
+ in.writeParamEncaps(0, 0, ok);
}
else
{
- in.__writeParamEncaps(&outEncaps[0], static_cast<Ice::Int>(outEncaps.size()), ok);
- }
- if(ok)
- {
- return DispatchOK;
- }
- else
- {
- return DispatchUserException;
+ in.writeParamEncaps(&outEncaps[0], static_cast<Ice::Int>(outEncaps.size()), ok);
}
+ return false;
}
-DispatchStatus
+bool
Ice::BlobjectAsync::__dispatch(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
+bool
Ice::BlobjectArrayAsync::__dispatch(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;
}