summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp/include/Ice/Buffer.h6
-rw-r--r--cpp/include/Ice/Exception.h3
-rw-r--r--cpp/include/Ice/InputStream.h5
-rw-r--r--cpp/include/Ice/OutputStream.h3
-rw-r--r--cpp/src/Ice/Buffer.cpp10
-rw-r--r--cpp/src/Ice/CollocatedRequestHandler.cpp7
-rw-r--r--cpp/src/Ice/InputStream.cpp19
-rw-r--r--cpp/src/Ice/OutputStream.cpp24
-rw-r--r--csharp/src/Ice/BasicStream.cs2
-rw-r--r--java/src/Ice/src/main/java/Ice/InputStream.java2
-rw-r--r--objective-c/include/objc/Ice/Initialize.h2
-rw-r--r--objective-c/include/objc/Ice/Stream.h7
-rw-r--r--objective-c/include/objc/Ice/ValueFactory.h6
-rw-r--r--objective-c/src/Ice/CommunicatorI.h9
-rw-r--r--objective-c/src/Ice/CommunicatorI.mm156
-rw-r--r--objective-c/src/Ice/Initialize.mm104
-rw-r--r--objective-c/src/Ice/Makefile1
-rw-r--r--objective-c/src/Ice/Object.mm58
-rw-r--r--objective-c/src/Ice/ObjectAdapterI.mm28
-rw-r--r--objective-c/src/Ice/ObjectI.h12
-rw-r--r--objective-c/src/Ice/PropertiesI.h2
-rw-r--r--objective-c/src/Ice/Proxy.mm173
-rw-r--r--objective-c/src/Ice/Stream.mm377
-rw-r--r--objective-c/src/Ice/StreamI.h18
-rw-r--r--objective-c/src/Ice/Util.mm8
-rw-r--r--objective-c/src/Ice/ValueFactoryI.h19
-rw-r--r--objective-c/src/Ice/ValueFactoryI.mm161
-rw-r--r--objective-c/test/Ice/objects/AllTests.m2
-rw-r--r--objective-c/test/Ice/objects/Client.m33
-rw-r--r--objective-c/test/Ice/objects/Collocated.m33
-rw-r--r--objective-c/test/Ice/objects/Server.m12
-rw-r--r--objective-c/test/Ice/optional/AllTests.m3
-rw-r--r--objective-c/test/Ice/servantLocator/AllTests.m6
-rw-r--r--objective-c/test/Ice/stream/Client.m8
34 files changed, 651 insertions, 668 deletions
diff --git a/cpp/include/Ice/Buffer.h b/cpp/include/Ice/Buffer.h
index 56966089c06..95f599bb467 100644
--- a/cpp/include/Ice/Buffer.h
+++ b/cpp/include/Ice/Buffer.h
@@ -81,7 +81,7 @@ public:
}
void swap(Container&);
-
+
void clear();
void resize(size_type n) // Inlined for performance reasons.
@@ -98,7 +98,7 @@ public:
}
_size = n;
}
-
+
void reset()
{
assert(!_buf || _capacity > 0);
@@ -141,7 +141,7 @@ public:
assert(n < _size);
return _buf[n];
}
-
+
private:
Container(const Container&);
diff --git a/cpp/include/Ice/Exception.h b/cpp/include/Ice/Exception.h
index c4477bb8000..003d1947cdc 100644
--- a/cpp/include/Ice/Exception.h
+++ b/cpp/include/Ice/Exception.h
@@ -47,7 +47,7 @@ public:
virtual ~LocalException() ICE_NOEXCEPT;
virtual std::string ice_id() const = 0;
-#ifndef ICE_CPP11_MAPPING
+#ifndef ICE_CPP11_MAPPING
virtual LocalException* ice_clone() const = 0;
#endif
virtual void ice_throw() const = 0;
@@ -57,7 +57,6 @@ class ICE_API UserException : public IceUtil::Exception
{
public:
-
virtual std::string ice_id() const = 0;
#ifndef ICE_CPP11_MAPPING
virtual UserException* ice_clone() const = 0;
diff --git a/cpp/include/Ice/InputStream.h b/cpp/include/Ice/InputStream.h
index b903f955b82..070d43e57a8 100644
--- a/cpp/include/Ice/InputStream.h
+++ b/cpp/include/Ice/InputStream.h
@@ -633,6 +633,11 @@ public:
return i - b.begin();
}
+ void pos(size_type p)
+ {
+ i = b.begin() + p;
+ }
+
InputStream(IceInternal::Instance*, const EncodingVersion&);
InputStream(IceInternal::Instance*, const EncodingVersion&, IceInternal::Buffer&, bool = false);
diff --git a/cpp/include/Ice/OutputStream.h b/cpp/include/Ice/OutputStream.h
index 5ba33bad8cc..0f0138e78f2 100644
--- a/cpp/include/Ice/OutputStream.h
+++ b/cpp/include/Ice/OutputStream.h
@@ -92,7 +92,6 @@ public:
void resize(Container::size_type sz)
{
b.resize(sz);
- i = b.end();
}
void startObject(const SlicedDataPtr& data)
@@ -468,7 +467,7 @@ public:
size_type pos()
{
- return i - b.begin();
+ return b.size();
}
void rewrite(Int value, size_type p)
diff --git a/cpp/src/Ice/Buffer.cpp b/cpp/src/Ice/Buffer.cpp
index b906c99ae74..382f852501f 100644
--- a/cpp/src/Ice/Buffer.cpp
+++ b/cpp/src/Ice/Buffer.cpp
@@ -87,10 +87,7 @@ IceInternal::Buffer::Container::~Container()
void
IceInternal::Buffer::Container::swap(Container& other)
{
- assert(!_buf || _capacity > 0);
-
std::swap(_buf, other._buf);
-
std::swap(_size, other._size);
std::swap(_capacity, other._capacity);
std::swap(_shrinkCounter, other._shrinkCounter);
@@ -99,9 +96,10 @@ IceInternal::Buffer::Container::swap(Container& other)
void
IceInternal::Buffer::Container::clear()
{
- assert(!_buf || _capacity > 0);
-
- free(_buf);
+ if(_buf && _capacity > 0)
+ {
+ free(_buf);
+ }
_buf = 0;
_size = 0;
_capacity = 0;
diff --git a/cpp/src/Ice/CollocatedRequestHandler.cpp b/cpp/src/Ice/CollocatedRequestHandler.cpp
index 4fbf0d0bc7b..377717018f6 100644
--- a/cpp/src/Ice/CollocatedRequestHandler.cpp
+++ b/cpp/src/Ice/CollocatedRequestHandler.cpp
@@ -335,8 +335,7 @@ CollocatedRequestHandler::sendResponse(Int requestId, OutputStream* os, Byte, bo
}
InputStream is(os->instance(), os->getEncoding(), *os, true); // Adopting the OutputStream's buffer.
-
- is.i = is.b.begin() + sizeof(replyHdr) + 4;
+ is.pos(sizeof(replyHdr) + 4);
if(_traceLevels->protocol >= 1)
{
@@ -469,11 +468,11 @@ CollocatedRequestHandler::invokeAll(OutputStream* os, Int requestId, Int batchRe
if(batchRequestNum > 0)
{
- is.i = is.b.begin() + sizeof(requestBatchHdr);
+ is.pos(sizeof(requestBatchHdr));
}
else
{
- is.i = is.b.begin() + sizeof(requestHdr);
+ is.pos(sizeof(requestHdr));
}
int invokeNum = batchRequestNum > 0 ? batchRequestNum : 1;
diff --git a/cpp/src/Ice/InputStream.cpp b/cpp/src/Ice/InputStream.cpp
index b89ce6e0177..5c73c51d6f1 100644
--- a/cpp/src/Ice/InputStream.cpp
+++ b/cpp/src/Ice/InputStream.cpp
@@ -179,12 +179,6 @@ Ice::InputStream::initialize(const EncodingVersion& encoding)
_sliceObjects = true;
_startSeq = -1;
_minSeqSize = 0;
-
- //
- // Initialize the encoding members of our pre-allocated encapsulation, in case
- // this stream is used without an explicit encapsulation.
- //
- _preAllocatedEncaps.encoding = encoding;
}
void
@@ -267,20 +261,15 @@ Ice::InputStream::setClosure(void* p)
void
Ice::InputStream::swap(InputStream& other)
{
- assert(_instance == other._instance);
-
swapBuffer(other);
+ std::swap(_instance, other._instance);
std::swap(_encoding, other._encoding);
-
#ifndef ICE_CPP11_MAPPING
std::swap(_collectObjects, other._collectObjects);
#endif
-
std::swap(_traceSlicing, other._traceSlicing);
-
std::swap(_closure, other._closure);
-
std::swap(_sliceObjects, other._sliceObjects);
//
@@ -1278,6 +1267,10 @@ Ice::InputStream::skipOpt(OptionalFormat type)
{
Int sz;
read(sz);
+ if(sz < 0)
+ {
+ throw UnmarshalOutOfBoundsException(__FILE__, __LINE__);
+ }
skip(sz);
break;
}
@@ -1321,7 +1314,6 @@ Ice::InputStream::skipOpts()
void
Ice::InputStream::throwUnmarshalOutOfBoundsException(const char* file, int line)
{
- assert(false);
throw UnmarshalOutOfBoundsException(file, line);
}
@@ -1487,6 +1479,7 @@ Ice::InputStream::initEncaps()
if(!_currentEncaps) // Lazy initialization.
{
_currentEncaps = &_preAllocatedEncaps;
+ _currentEncaps->encoding = _encoding;
_currentEncaps->sz = static_cast<Ice::Int>(b.size());
}
diff --git a/cpp/src/Ice/OutputStream.cpp b/cpp/src/Ice/OutputStream.cpp
index 1f784ad3675..318f411cc4a 100644
--- a/cpp/src/Ice/OutputStream.cpp
+++ b/cpp/src/Ice/OutputStream.cpp
@@ -79,11 +79,6 @@ Ice::OutputStream::OutputStream() :
_format(CompactFormat),
_currentEncaps(0)
{
- //
- // Initialize the encoding member of our pre-allocated encapsulation, in case
- // this stream is used without an explicit encapsulation.
- //
- _preAllocatedEncaps.encoding = _encoding;
}
Ice::OutputStream::OutputStream(const CommunicatorPtr& communicator) :
@@ -111,16 +106,15 @@ void
Ice::OutputStream::initialize(const CommunicatorPtr& communicator)
{
assert(communicator);
- InstancePtr instance = getInstance(communicator);
- initialize(instance.get(), instance->defaultsAndOverrides()->defaultEncoding);
+ Instance* instance = getInstance(communicator).get();
+ initialize(instance, instance->defaultsAndOverrides()->defaultEncoding);
}
void
Ice::OutputStream::initialize(const CommunicatorPtr& communicator, const EncodingVersion& encoding)
{
assert(communicator);
- InstancePtr instance = getInstance(communicator);
- initialize(instance.get(), encoding);
+ initialize(getInstance(communicator).get(), encoding);
}
void
@@ -135,12 +129,6 @@ Ice::OutputStream::initialize(Instance* instance, const EncodingVersion& encodin
_wstringConverter = _instance->getWstringConverter();
_format = _instance->defaultsAndOverrides()->defaultFormat;
-
- //
- // Initialize the encoding member of our pre-allocated encapsulation, in case
- // this stream is used without an explicit encapsulation.
- //
- _preAllocatedEncaps.encoding = encoding;
}
void
@@ -184,11 +172,12 @@ Ice::OutputStream::setClosure(void* p)
void
Ice::OutputStream::swap(OutputStream& other)
{
- assert(_instance == other._instance);
-
swapBuffer(other);
+ std::swap(_instance, other._instance);
std::swap(_closure, other._closure);
+ std::swap(_encoding, other._encoding);
+ std::swap(_format, other._format);
//
// Swap is never called for streams that have encapsulations being written. However,
@@ -877,6 +866,7 @@ Ice::OutputStream::initEncaps()
{
_currentEncaps = &_preAllocatedEncaps;
_currentEncaps->start = b.size();
+ _currentEncaps->encoding = _encoding;
}
if(_currentEncaps->format == Ice::DefaultFormat)
diff --git a/csharp/src/Ice/BasicStream.cs b/csharp/src/Ice/BasicStream.cs
index b2ae159dc5f..336afcc6b80 100644
--- a/csharp/src/Ice/BasicStream.cs
+++ b/csharp/src/Ice/BasicStream.cs
@@ -3217,7 +3217,7 @@ namespace IceInternal
public void skip(int size)
{
- if(size > _buf.b.remaining())
+ if(size < 0 || size > _buf.b.remaining())
{
throw new Ice.UnmarshalOutOfBoundsException();
}
diff --git a/java/src/Ice/src/main/java/Ice/InputStream.java b/java/src/Ice/src/main/java/Ice/InputStream.java
index 472288e253b..e1556e924c3 100644
--- a/java/src/Ice/src/main/java/Ice/InputStream.java
+++ b/java/src/Ice/src/main/java/Ice/InputStream.java
@@ -2016,7 +2016,7 @@ public class InputStream
**/
public void skip(int size)
{
- if(size > _buf.b.remaining())
+ if(size < 0 || size > _buf.b.remaining())
{
throw new UnmarshalOutOfBoundsException();
}
diff --git a/objective-c/include/objc/Ice/Initialize.h b/objective-c/include/objc/Ice/Initialize.h
index 633f8a37d03..c7ab1459522 100644
--- a/objective-c/include/objc/Ice/Initialize.h
+++ b/objective-c/include/objc/Ice/Initialize.h
@@ -71,8 +71,6 @@ ICE_API @interface ICEUtil : NSObject
+(id<ICECommunicator>) createCommunicator:(int*)argc argv:(char*[])argv initData:(ICEInitializationData *)initData;
+(id<ICEInputStream>) createInputStream:(id<ICECommunicator>)communicator data:(NSData*)data;
+(id<ICEInputStream>) createInputStream:(id<ICECommunicator>)c data:(NSData*)data encoding:(ICEEncodingVersion*)e;
-+(id<ICEInputStream>) wrapInputStream:(id<ICECommunicator>)communicator data:(NSData*)data;
-+(id<ICEInputStream>) wrapInputStream:(id<ICECommunicator>)c data:(NSData*)data encoding:(ICEEncodingVersion*)e;
+(id<ICEOutputStream>) createOutputStream:(id<ICECommunicator>)communicator;
+(id<ICEOutputStream>) createOutputStream:(id<ICECommunicator>)c encoding:(ICEEncodingVersion*)e;
+(NSString*) generateUUID;
diff --git a/objective-c/include/objc/Ice/Stream.h b/objective-c/include/objc/Ice/Stream.h
index 71dd4c87b2b..500e704cba6 100644
--- a/objective-c/include/objc/Ice/Stream.h
+++ b/objective-c/include/objc/Ice/Stream.h
@@ -17,7 +17,6 @@
//
@class ICEObject;
@protocol ICEObjectPrx;
-@protocol ICECommunicator;
@protocol ICESlicedData;
@class ICEUserException;
@class ICEEncodingVersion;
@@ -54,9 +53,7 @@ typedef struct
ICE_API @protocol ICEInputStream <NSObject>
--(id<ICECommunicator>) communicator;
-
--(void) sliceObjects:(BOOL)b;
+-(void) setSliceObjects:(BOOL)b;
-(BOOL) readBool;
-(NSMutableData*) newBoolSeq;
@@ -146,8 +143,6 @@ ICE_API @protocol ICEInputStream <NSObject>
ICE_API @protocol ICEOutputStream <NSObject>
--(id<ICECommunicator>) communicator;
-
-(void) writeBool:(BOOL)v;
-(void) writeBoolSeq:(NSData*)v;
diff --git a/objective-c/include/objc/Ice/ValueFactory.h b/objective-c/include/objc/Ice/ValueFactory.h
index b7733ce439a..15127a81253 100644
--- a/objective-c/include/objc/Ice/ValueFactory.h
+++ b/objective-c/include/objc/Ice/ValueFactory.h
@@ -8,5 +8,11 @@
// **********************************************************************
#import <objc/Ice/Config.h>
+#import <objc/Ice/Object.h>
+
typedef ICEObject* (^ICEValueFactory)(NSString*);
+ICE_API @protocol ICEValueFactoryManager <NSObject>
+-(void) add:(ICEValueFactory)factory sliceId:(NSString*)id_;
+-(ICEValueFactory) find:(NSString*)id_;
+@end
diff --git a/objective-c/src/Ice/CommunicatorI.h b/objective-c/src/Ice/CommunicatorI.h
index f1900a4f0e9..f29a5e58c8d 100644
--- a/objective-c/src/Ice/CommunicatorI.h
+++ b/objective-c/src/Ice/CommunicatorI.h
@@ -8,7 +8,6 @@
// **********************************************************************
#import <objc/Ice/Communicator.h>
-
#import <objc/Ice/LocalObject.h>
#import <Foundation/NSSet.h>
@@ -16,15 +15,17 @@
#include <Ice/Communicator.h>
@class ICEObjectAdapter;
+@class ICEValueFactoryManager;
+@class ICEInitializationData;
@interface ICECommunicator : ICELocalObject<ICECommunicator>
{
- NSMutableDictionary* valueFactories_;
- NSMutableDictionary* objectFactories_;
NSDictionary* prefixTable_;
NSMutableDictionary* adminFacets_;
+ ICEValueFactoryManager* valueFactoryManager_;
+ NSMutableDictionary* objectFactories_;
}
--(void)setup:(NSDictionary*)prefixTable;
+-(void)setup:(ICEInitializationData*)prefixTable;
-(Ice::Communicator*)communicator;
-(NSDictionary*)getPrefixTable;
@end
diff --git a/objective-c/src/Ice/CommunicatorI.mm b/objective-c/src/Ice/CommunicatorI.mm
index 56f4a2bcd87..d6e1338ba69 100644
--- a/objective-c/src/Ice/CommunicatorI.mm
+++ b/objective-c/src/Ice/CommunicatorI.mm
@@ -20,120 +20,19 @@
#import <ProxyI.h>
#import <LocalObjectI.h>
#import <ObjectI.h>
+#import <ValueFactoryI.h>
#include <Ice/Router.h>
#include <Ice/Locator.h>
-#include <Ice/ObjectFactory.h>
-#include <Ice/ValueFactory.h>
#import <objc/Ice/Router.h>
#import <objc/Ice/Locator.h>
-#import <objc/Ice/ObjectFactory.h>
-#import <objc/Ice/ValueFactory.h>
+#import <objc/Ice/Initialize.h>
#import <objc/runtime.h>
#define COMMUNICATOR dynamic_cast<Ice::Communicator*>(static_cast<IceUtil::Shared*>(cxxObject_))
-namespace IceObjC
-{
-
-class UnknownSlicedValueFactoryI : public Ice::ValueFactory
-{
-public:
-
- virtual Ice::ObjectPtr
- create(const std::string&)
- {
- ICEUnknownSlicedObject* obj = [[ICEUnknownSlicedObject alloc] init];
- Ice::ObjectPtr o = [ICEInputStream createObjectReader:obj];
- [obj release];
- return o;
- }
-};
-
-class ValueFactoryI : public Ice::ValueFactory
-{
-public:
-
- // We must explicitely CFRetain/CFRelease so that the garbage
- // collector does not trash the dictionaries.
- ValueFactoryI(NSDictionary* factories, NSDictionary* prefixTable) :
- _factories(factories), _prefixTable(prefixTable)
- {
- CFRetain(_factories);
- CFRetain(_prefixTable);
- }
-
- ~ValueFactoryI()
- {
- CFRelease(_factories);
- CFRelease(_prefixTable);
- }
-
- virtual Ice::ObjectPtr
- create(const std::string& type)
- {
- NSString* sliceId = [[NSString alloc] initWithUTF8String:type.c_str()];
- @try
- {
- ICEValueFactory factory = nil;
- @synchronized(_factories)
- {
- factory = [_factories objectForKey:sliceId];
- if(factory == nil)
- {
- factory = [_factories objectForKey:@""];
- }
- }
-
- ICEObject* obj = nil;
- if(factory != nil)
- {
- obj = [factory(sliceId) retain];
- }
-
- if(obj == nil)
- {
- std::string tId = toObjCSliceId(type, _prefixTable);
- Class c = objc_lookUpClass(tId.c_str());
- if(c == nil)
- {
- return 0; // No value factory.
- }
- if([c isSubclassOfClass:[ICEObject class]])
- {
- obj = (ICEObject*)[[c alloc] init];
- }
- }
-
- Ice::ObjectPtr o;
- if(obj != nil)
- {
- o = [ICEInputStream createObjectReader:obj];
- [obj release];
- }
- return o;
- }
- @catch(id ex)
- {
- rethrowCxxException(ex);
- }
- @finally
- {
- [sliceId release];
- }
- return nil; // Keep the compiler happy.
- }
-
-private:
-
- NSDictionary* _factories;
- NSDictionary* _prefixTable;
-};
-
-}
-
@interface ICEInternalPrefixTable(ICEInternal)
+(NSDictionary*) newPrefixTable;
@end
@@ -161,27 +60,26 @@ private:
@end
@implementation ICECommunicator
--(void)setup:(NSDictionary*)prefixTable
+-(void)setup:(ICEInitializationData*)initData
{
- valueFactories_ = [[NSMutableDictionary alloc] init];
- objectFactories_ = [[NSMutableDictionary alloc] init];
- if(prefixTable)
+ if(initData.prefixTable__)
{
- prefixTable_ = [prefixTable retain];
+ prefixTable_ = [initData.prefixTable__ retain];
}
else
{
prefixTable_ = [ICEInternalPrefixTable newPrefixTable];
}
adminFacets_ = [[NSMutableDictionary alloc] init];
- COMMUNICATOR->addValueFactory(new IceObjC::UnknownSlicedValueFactoryI, "::Ice::Object");
- COMMUNICATOR->addValueFactory(new IceObjC::ValueFactoryI(valueFactories_, prefixTable_), "");
+
+ valueFactoryManager_ = [[ICEValueFactoryManager alloc] init:COMMUNICATOR prefixTable:prefixTable_];
+ objectFactories_ = [[NSMutableDictionary alloc] init];
}
-(void) dealloc
{
- [prefixTable_ release];
- [valueFactories_ release];
+ [valueFactoryManager_ release];
[objectFactories_ release];
+ [prefixTable_ release];
[adminFacets_ release];
[super dealloc];
}
@@ -421,44 +319,32 @@ private:
@throw nsex;
return nil; // Keep the compiler happy.
}
+
-(void) addObjectFactory:(id<ICEObjectFactory>)factory sliceId:(NSString*)sliceId
{
- @synchronized(valueFactories_)
+ @synchronized(objectFactories_)
{
[objectFactories_ setObject:factory forKey:sliceId];
-
- ICEValueFactory valueFactoryWrapper = ^(NSString* s)
- {
- return [factory create:s];
- };
-
- [valueFactories_ setObject:ICE_AUTORELEASE([valueFactoryWrapper copy]) forKey:sliceId];
}
+ ICEValueFactory valueFactoryWrapper = ^(NSString* s)
+ {
+ return [factory create:s];
+ };
+ [valueFactoryManager_ add:valueFactoryWrapper sliceId:sliceId];
}
+
-(id<ICEObjectFactory>) findObjectFactory:(NSString*)sliceId
{
- @synchronized(valueFactories_)
+ @synchronized(objectFactories_)
{
return [objectFactories_ objectForKey:sliceId];
}
return nil; // Keep the compiler happy.
}
--(void) addValueFactory:(ICEValueFactory)factory sliceId:(NSString*)sliceId
-{
- @synchronized(valueFactories_)
- {
- [valueFactories_ setObject:ICE_AUTORELEASE([factory copy]) forKey:sliceId];
- }
-}
-
--(ICEValueFactory) findValueFactory:(NSString*)sliceId
+-(id<ICEValueFactoryManager>) getValueFactoryManager
{
- @synchronized(valueFactories_)
- {
- return [valueFactories_ objectForKey:sliceId];
- }
- return nil; // Keep the compiler happy.
+ return valueFactoryManager_;
}
-(id<ICEImplicitContext>) getImplicitContext
diff --git a/objective-c/src/Ice/Initialize.mm b/objective-c/src/Ice/Initialize.mm
index f4bd535d367..07c5fba8bbb 100644
--- a/objective-c/src/Ice/Initialize.mm
+++ b/objective-c/src/Ice/Initialize.mm
@@ -389,7 +389,7 @@ private:
}
ICECommunicator* c = [ICECommunicator localObjectWithCxxObject:communicator.get()];
- [c setup:initData.prefixTable__];
+ [c setup:initData];
return c;
}
catch(const std::exception& ex)
@@ -400,23 +400,12 @@ private:
return nil; // Keep the compiler happy.
}
-+(id<ICEInputStream>) createInputStream:(id<ICECommunicator>)communicator data:(NSData*)data
++(id<ICEInputStream>) createInputStream:(id<ICECommunicator>)c data:(NSData*)data
{
NSException* nsex = nil;
try
{
- Ice::CommunicatorPtr com = [(ICECommunicator*)communicator communicator];
- Ice::Byte* start = (Ice::Byte*)[data bytes];
- Ice::Byte* end = (Ice::Byte*)[data bytes] + [data length];
- Ice::InputStreamPtr is = Ice::createInputStream(com, std::make_pair(start, end));
- if(is)
- {
- return [ICEInputStream localObjectWithCxxObject:is.get()];
- }
- else
- {
- return nil;
- }
+ return [[[ICEInputStream alloc] initWithCommunicator:c data:data encoding:nil] autorelease];
}
catch(const std::exception& ex)
{
@@ -431,70 +420,7 @@ private:
NSException* nsex = nil;
try
{
- Ice::CommunicatorPtr com = [(ICECommunicator*)c communicator];
- Ice::Byte* start = (Ice::Byte*)[data bytes];
- Ice::Byte* end = (Ice::Byte*)[data bytes] + [data length];
- Ice::InputStreamPtr is = Ice::createInputStream(com, std::make_pair(start, end), [e encodingVersion]);
- if(is)
- {
- return [ICEInputStream localObjectWithCxxObject:is.get()];
- }
- else
- {
- return nil;
- }
- }
- catch(const std::exception& ex)
- {
- nsex = toObjCException(ex);
- }
- @throw nsex;
- return nil; // Keep the compiler happy.
-}
-
-+(id<ICEInputStream>) wrapInputStream:(id<ICECommunicator>)communicator data:(NSData*)data
-{
- NSException* nsex = nil;
- try
- {
- Ice::CommunicatorPtr com = [(ICECommunicator*)communicator communicator];
- Ice::Byte* start = (Ice::Byte*)[data bytes];
- Ice::Byte* end = (Ice::Byte*)[data bytes] + [data length];
- Ice::InputStreamPtr is = Ice::wrapInputStream(com, std::make_pair(start, end));
- if(is)
- {
- return [ICEInputStream localObjectWithCxxObject:is.get()];
- }
- else
- {
- return nil;
- }
- }
- catch(const std::exception& ex)
- {
- nsex = toObjCException(ex);
- }
- @throw nsex;
- return nil; // Keep the compiler happy.
-}
-
-+(id<ICEInputStream>) wrapInputStream:(id<ICECommunicator>)c data:(NSData*)data encoding:(ICEEncodingVersion*)e
-{
- NSException* nsex = nil;
- try
- {
- Ice::CommunicatorPtr com = [(ICECommunicator*)c communicator];
- Ice::Byte* start = (Ice::Byte*)[data bytes];
- Ice::Byte* end = (Ice::Byte*)[data bytes] + [data length];
- Ice::InputStreamPtr is = Ice::wrapInputStream(com, std::make_pair(start, end), [e encodingVersion]);
- if(is)
- {
- return [ICEInputStream localObjectWithCxxObject:is.get()];
- }
- else
- {
- return nil;
- }
+ return [[[ICEInputStream alloc] initWithCommunicator:c data:data encoding:e] autorelease];
}
catch(const std::exception& ex)
{
@@ -509,16 +435,7 @@ private:
NSException* nsex = nil;
try
{
- Ice::CommunicatorPtr com = [(ICECommunicator*)communicator communicator];
- Ice::OutputStreamPtr os = Ice::createOutputStream(com);
- if(os)
- {
- return [ICEOutputStream localObjectWithCxxObject:os.get()];
- }
- else
- {
- return nil;
- }
+ return [[[ICEOutputStream alloc] initWithCommunicator:communicator encoding:nil] autorelease];
}
catch(const std::exception& ex)
{
@@ -533,16 +450,7 @@ private:
NSException* nsex = nil;
try
{
- Ice::CommunicatorPtr com = [(ICECommunicator*)communicator communicator];
- Ice::OutputStreamPtr os = Ice::createOutputStream(com, [encoding encodingVersion]);
- if(os)
- {
- return [ICEOutputStream localObjectWithCxxObject:os.get()];
- }
- else
- {
- return nil;
- }
+ return [[[ICEOutputStream alloc] initWithCommunicator:communicator encoding:encoding] autorelease];
}
catch(const std::exception& ex)
{
diff --git a/objective-c/src/Ice/Makefile b/objective-c/src/Ice/Makefile
index cd1c5e0b9fc..10879dc6774 100644
--- a/objective-c/src/Ice/Makefile
+++ b/objective-c/src/Ice/Makefile
@@ -74,6 +74,7 @@ OBJCXX_OBJS = BatchRequestInterceptor.o \
Stream.o \
SlicedData.o \
Util.o \
+ ValueFactoryI.o \
VersionI.o
OBJS := $(OBJC_OBJS) $(OBJCXX_OBJS)
diff --git a/objective-c/src/Ice/Object.mm b/objective-c/src/Ice/Object.mm
index 3f571a7b084..466791070b3 100644
--- a/objective-c/src/Ice/Object.mm
+++ b/objective-c/src/Ice/Object.mm
@@ -25,7 +25,7 @@
namespace
{
-std::map<Ice::Object*, ICEObjectWrapper*> cachedObjects;
+std::map<Ice::Object*, ICEServantWrapper*> cachedObjects;
NSString*
operationModeToString(ICEOperationMode mode)
@@ -46,7 +46,7 @@ operationModeToString(ICEOperationMode mode)
}
}
-class ObjectI : public IceObjC::ObjectWrapper, public Ice::BlobjectArrayAsync
+class ObjectI : public IceObjC::ServantWrapper, public Ice::BlobjectArrayAsync
{
public:
@@ -56,7 +56,7 @@ public:
const std::pair<const Ice::Byte*, const Ice::Byte*>&,
const Ice::Current&);
- virtual ICEObject* getObject()
+ virtual ICEObject* getServant()
{
return _object;
}
@@ -78,7 +78,7 @@ private:
ICEServant* _object;
};
-class BlobjectI : public IceObjC::ObjectWrapper, public Ice::BlobjectArrayAsync
+class BlobjectI : public IceObjC::ServantWrapper, public Ice::BlobjectArrayAsync
{
public:
@@ -88,7 +88,7 @@ public:
const std::pair<const Ice::Byte*, const Ice::Byte*>&,
const Ice::Current&);
- virtual ICEObject* getObject()
+ virtual ICEObject* getServant()
{
return _blobject;
}
@@ -117,19 +117,12 @@ ObjectI::ObjectI(ICEServant* object) : _object(object)
void
ObjectI::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& cb,
- const std::pair<const Ice::Byte*, const Ice::Byte*>& inParams,
- const Ice::Current& current)
+ const std::pair<const Ice::Byte*, const Ice::Byte*>& inParams,
+ const Ice::Current& current)
{
- ICEInputStream* is = nil;
- ICEOutputStream* os = nil;
- {
- Ice::InputStreamPtr s = Ice::createInputStream(current.adapter->getCommunicator(), inParams);
- is = [ICEInputStream localObjectWithCxxObjectNoAutoRelease:s.get()];
- }
- {
- Ice::OutputStreamPtr s = Ice::createOutputStream(current.adapter->getCommunicator());
- os = [ICEOutputStream localObjectWithCxxObjectNoAutoRelease:s.get()];
- }
+ Ice::Communicator* communicator = current.adapter->getCommunicator().get();
+ ICEInputStream* is = [[ICEInputStream alloc] initWithCxxCommunicator:communicator data:inParams];
+ ICEOutputStream* os = [[ICEOutputStream alloc] initWithCxxCommunicator:communicator];
NSException* exception = nil;
BOOL ok = YES; // Keep the compiler happy
@@ -157,11 +150,8 @@ ObjectI::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& cb,
rethrowCxxException(exception, true); // True = release the exception.
}
- std::vector<Ice::Byte> outParams;
- [os os]->finished(outParams);
+ cb->ice_response(ok, [os os]->finished());
[os release];
-
- cb->ice_response(ok, std::make_pair(&outParams[0], &outParams[0] + outParams.size()));
}
BlobjectI::BlobjectI(ICEBlobject* blobject) : _blobject(blobject), _target([blobject target__])
@@ -170,8 +160,8 @@ BlobjectI::BlobjectI(ICEBlobject* blobject) : _blobject(blobject), _target([blob
void
BlobjectI::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& cb,
- const std::pair<const Ice::Byte*, const Ice::Byte*>& inEncaps,
- const Ice::Current& current)
+ const std::pair<const Ice::Byte*, const Ice::Byte*>& inEncaps,
+ const Ice::Current& current)
{
NSException* exception = nil;
BOOL ok = YES; // Keep the compiler happy.
@@ -412,7 +402,7 @@ static NSString* ICEObject_all__[4] =
{
if(object__)
{
- delete static_cast<IceObjC::ObjectWrapper*>(object__);
+ delete static_cast<IceObjC::ServantWrapper*>(object__);
object__ = 0;
}
[delegate__ release];
@@ -570,10 +560,10 @@ static NSString* ICEObject_all__[4] =
// reference to the object (without this, servants added to the object adapter
// couldn't be retained or released easily).
//
- object__ = static_cast<IceObjC::ObjectWrapper*>(new ObjectI(self));
+ object__ = static_cast<IceObjC::ServantWrapper*>(new ObjectI(self));
}
}
- return static_cast<IceObjC::ObjectWrapper*>(object__);
+ return static_cast<IceObjC::ServantWrapper*>(object__);
}
@end
@@ -592,14 +582,14 @@ static NSString* ICEObject_all__[4] =
// reference to the object (without this, servants added to the object adapter
// couldn't be retained or released easily).
//
- object__ = static_cast<IceObjC::ObjectWrapper*>(new BlobjectI(self));
+ object__ = static_cast<IceObjC::ServantWrapper*>(new BlobjectI(self));
}
}
- return static_cast<IceObjC::ObjectWrapper*>(object__);
+ return static_cast<IceObjC::ServantWrapper*>(object__);
}
@end
-@implementation ICEObjectWrapper
+@implementation ICEServantWrapper
-(id) initWithCxxObject:(Ice::Object*)arg
{
self = [super init];
@@ -620,18 +610,18 @@ static NSString* ICEObject_all__[4] =
object__->__decRef();
[super dealloc];
}
-+(id) objectWrapperWithCxxObject:(Ice::Object*)arg
++(id) servantWrapperWithCxxObject:(Ice::Object*)arg
{
- @synchronized([ICEObjectWrapper class])
+ @synchronized([ICEServantWrapper class])
{
- std::map<Ice::Object*, ICEObjectWrapper*>::const_iterator p = cachedObjects.find(arg);
+ std::map<Ice::Object*, ICEServantWrapper*>::const_iterator p = cachedObjects.find(arg);
if(p != cachedObjects.end())
{
return [p->second retain];
}
else
{
- return [[(ICEObjectWrapper*)[self alloc] initWithCxxObject:arg] autorelease];
+ return [[(ICEServantWrapper*)[self alloc] initWithCxxObject:arg] autorelease];
}
}
}
@@ -642,7 +632,7 @@ static NSString* ICEObject_all__[4] =
}
-(oneway void) release
{
- @synchronized([ICEObjectWrapper class])
+ @synchronized([ICEServantWrapper class])
{
if(NSDecrementExtraRefCountWasZero(self))
{
diff --git a/objective-c/src/Ice/ObjectAdapterI.mm b/objective-c/src/Ice/ObjectAdapterI.mm
index 8038bdd4f7b..911cec91c07 100644
--- a/objective-c/src/Ice/ObjectAdapterI.mm
+++ b/objective-c/src/Ice/ObjectAdapterI.mm
@@ -23,7 +23,7 @@
#include <Ice/Locator.h>
#include <Ice/ServantLocator.h>
-#include <Ice/Stream.h>
+#include <Ice/OutputStream.h>
namespace
{
@@ -88,12 +88,11 @@ private:
};
typedef IceUtil::Handle<Cookie> CookiePtr;
-class ExceptionWriter : public Ice::UserExceptionWriter
+class ExceptionWriter : public Ice::UserException
{
public:
- ExceptionWriter(const Ice::CommunicatorPtr& communicator, ICEUserException* ex) :
- Ice::UserExceptionWriter(communicator), _ex(ex)
+ ExceptionWriter(ICEUserException* ex) : _ex(ex)
{
}
@@ -103,15 +102,21 @@ public:
}
void
- write(const Ice::OutputStreamPtr& s) const
+ __write(Ice::OutputStream* s) const
{
- ICEOutputStream* os = [ICEOutputStream localObjectWithCxxObjectNoAutoRelease:s.get()];
+ ICEOutputStream* os = [[ICEOutputStream alloc] initWithCxxStream:s];
[_ex write__:os];
[os release];
}
+ void
+ __read(Ice::InputStream*)
+ {
+ assert(false);
+ }
+
bool
- usesClasses() const
+ __usesClasses() const
{
return [_ex usesClasses__];
}
@@ -134,6 +139,11 @@ public:
throw *this;
}
+protected:
+
+ virtual void __writeImpl(Ice::OutputStream*) const {}
+ virtual void __readImpl(Ice::InputStream*) {}
+
private:
ICEUserException* _ex;
@@ -184,7 +194,7 @@ public:
{
if([ex isKindOfClass:[ICEUserException class]])
{
- throw ExceptionWriter(current.adapter->getCommunicator(), (ICEUserException*)ex);
+ throw ExceptionWriter((ICEUserException*)ex);
}
rethrowCxxException(ex, true); // True = release the exception.
}
@@ -215,7 +225,7 @@ public:
{
if([ex isKindOfClass:[ICEUserException class]])
{
- throw ExceptionWriter(current.adapter->getCommunicator(), (ICEUserException*)ex);
+ throw ExceptionWriter((ICEUserException*)ex);
}
rethrowCxxException(ex, true); // True = release the exception.
}
diff --git a/objective-c/src/Ice/ObjectI.h b/objective-c/src/Ice/ObjectI.h
index 87e9d01bd7a..672514a7a15 100644
--- a/objective-c/src/Ice/ObjectI.h
+++ b/objective-c/src/Ice/ObjectI.h
@@ -21,14 +21,14 @@
namespace IceObjC
{
-class ObjectWrapper : virtual public Ice::Object
+class ServantWrapper : virtual public Ice::Object
{
public:
- virtual ~ObjectWrapper() { }
- virtual ICEObject* getObject() = 0;
+ virtual ~ServantWrapper() { }
+ virtual ICEObject* getServant() = 0;
};
-typedef IceUtil::Handle<ObjectWrapper> ObjectWrapperPtr;
+typedef IceUtil::Handle<ServantWrapper> ServantWrapperPtr;
};
@@ -36,9 +36,9 @@ typedef IceUtil::Handle<ObjectWrapper> ObjectWrapperPtr;
-(Ice::Object*) object__;
@end
-@interface ICEObjectWrapper : ICEObject
+@interface ICEServantWrapper : ICEObject
{
Ice::Object* object__;
}
-+(id) objectWrapperWithCxxObject:(Ice::Object*)arg;
++(id) servantWrapperWithCxxObject:(Ice::Object*)arg;
@end
diff --git a/objective-c/src/Ice/PropertiesI.h b/objective-c/src/Ice/PropertiesI.h
index c7d54756cbc..8ceb643e235 100644
--- a/objective-c/src/Ice/PropertiesI.h
+++ b/objective-c/src/Ice/PropertiesI.h
@@ -24,7 +24,7 @@
-(Ice::Properties*)properties;
@end
-@interface ICENativePropertiesAdmin : ICEObjectWrapper<ICENativePropertiesAdmin>
+@interface ICENativePropertiesAdmin : ICEServantWrapper<ICENativePropertiesAdmin>
{
IceUtil::Mutex mutex_;
std::vector<Ice::PropertiesAdminUpdateCallbackPtr> callbacks_;
diff --git a/objective-c/src/Ice/Proxy.mm b/objective-c/src/Ice/Proxy.mm
index fbc246f9dc9..d8473dd84f3 100644
--- a/objective-c/src/Ice/Proxy.mm
+++ b/objective-c/src/Ice/Proxy.mm
@@ -45,10 +45,12 @@ class BeginInvokeAsyncCallback : public IceUtil::Shared
{
public:
-BeginInvokeAsyncCallback(void (^completed)(id<ICEInputStream>, BOOL),
+BeginInvokeAsyncCallback(const Ice::CommunicatorPtr& communicator,
+ void (^completed)(id<ICEInputStream>, BOOL),
void (^exception)(ICEException*),
void (^sent)(BOOL),
BOOL returnsData) :
+ _communicator(communicator),
_completed(Block_copy(completed)),
_exception(Block_copy(exception)),
_sent(Block_copy(sent)),
@@ -63,41 +65,36 @@ virtual ~BeginInvokeAsyncCallback()
Block_release(_sent);
}
-void completed(const Ice::AsyncResultPtr& result)
+void response(bool ok, const std::pair<const Ice::Byte*, const Ice::Byte*>& outParams)
{
- BOOL ok = YES; // Keep the compiler happy.
id<ICEInputStream> is = nil;
NSException* nsex = nil;
- Ice::ObjectPrx proxy = result->getProxy();
try
{
- std::vector<Ice::Byte> outParams;
- ok = proxy->end_ice_invoke(outParams, result);
if(_returnsData)
{
- Ice::InputStreamPtr s = Ice::createInputStream(proxy->ice_getCommunicator(), outParams);
- is = [ICEInputStream localObjectWithCxxObjectNoAutoRelease:s.get()];
+ is = [[ICEInputStream alloc] initWithCxxCommunicator:_communicator.get() data:outParams];
}
- else if(!outParams.empty())
+ else if(outParams.first != outParams.second)
{
if(ok)
{
- if(outParams.size() != 6)
+ if((outParams.second - outParams.first) != 6)
{
throw Ice::EncapsulationException(__FILE__, __LINE__);
}
}
else
{
- Ice::InputStreamPtr s = Ice::createInputStream(proxy->ice_getCommunicator(), outParams);
+ Ice::InputStream s(_communicator.get(), outParams);
try
{
- s->startEncapsulation();
- s->throwException();
+ s.startEncapsulation();
+ s.throwException();
}
catch(const Ice::UserException& ex)
{
- s->endEncapsulation();
+ s.endEncapsulation();
throw Ice::UnknownUserException(__FILE__, __LINE__, ex.ice_id());
}
}
@@ -152,7 +149,38 @@ void completed(const Ice::AsyncResultPtr& result)
}
}
-void sent(const Ice::AsyncResultPtr& result)
+void exception(const Ice::Exception& ex)
+{
+ NSException* exception = nil;
+ @autoreleasepool
+ {
+ @try
+ {
+ @throw toObjCException(ex);
+ }
+ @catch(ICEException* ex)
+ {
+ if(_exception)
+ {
+ @try
+ {
+ _exception(ex);
+ }
+ @catch(id e)
+ {
+ exception = [e retain];
+ }
+ }
+ return;
+ }
+ }
+ if(exception != nil)
+ {
+ rethrowCxxException(exception, true); // True = release the exception.
+ }
+}
+
+void sent(bool sentSynchronously)
{
if(!_sent)
{
@@ -164,7 +192,7 @@ void sent(const Ice::AsyncResultPtr& result)
{
@try
{
- _sent(result->sentSynchronously());
+ _sent(sentSynchronously);
}
@catch(id e)
{
@@ -180,6 +208,7 @@ void sent(const Ice::AsyncResultPtr& result)
private:
+const Ice::CommunicatorPtr _communicator;
void (^_completed)(id<ICEInputStream>, BOOL);
void (^_exception)(ICEException*);
void (^_sent)(BOOL);
@@ -444,8 +473,7 @@ BOOL _returnsData;
NSException* nsex = nil;
try
{
- Ice::OutputStreamPtr os = Ice::createOutputStream(OBJECTPRX->ice_getCommunicator());
- return [ICEOutputStream localObjectWithCxxObjectNoAutoRelease:os.get()];
+ return [[ICEOutputStream alloc] initWithCxxCommunicator:OBJECTPRX->ice_getCommunicator().get()];
}
catch(const std::exception& ex)
{
@@ -507,8 +535,6 @@ BOOL _returnsData;
}
}
- BOOL ok = YES; // Keep the compiler happy.
- ICEInputStream<ICEInputStream>* is = nil;
NSException* nsex = nil;
try
{
@@ -521,6 +547,7 @@ BOOL _returnsData;
os = nil;
}
+ BOOL ok = YES; // Keep the compiler happy.
std::vector<Ice::Byte> outParams;
if(context != nil)
{
@@ -535,8 +562,22 @@ BOOL _returnsData;
if(unmarshal)
{
- Ice::InputStreamPtr s = Ice::createInputStream(OBJECTPRX->ice_getCommunicator(), outParams);
- is = [ICEInputStream localObjectWithCxxObjectNoAutoRelease:s.get()];
+ if(outParams.empty())
+ {
+ throw Ice::EncapsulationException(__FILE__, __LINE__);
+ }
+ std::pair<const Ice::Byte*, const Ice::Byte*> p(&outParams[0], &outParams[0] + outParams.size());
+ ICEInputStream<ICEInputStream>* is;
+ is = [[ICEInputStream alloc] initWithCxxCommunicator:OBJECTPRX->ice_getCommunicator().get() data:p];
+ @try
+ {
+ unmarshal(is, ok);
+ }
+ @catch(id e)
+ {
+ nsex = [e retain];
+ }
+ [is release];
}
else if(!outParams.empty())
{
@@ -549,15 +590,15 @@ BOOL _returnsData;
}
else
{
- Ice::InputStreamPtr s = Ice::createInputStream(OBJECTPRX->ice_getCommunicator(), outParams);
+ Ice::InputStream s(OBJECTPRX->ice_getCommunicator(), outParams);
try
{
- s->startEncapsulation();
- s->throwException();
+ s.startEncapsulation();
+ s.throwException();
}
catch(const Ice::UserException& ex)
{
- s->endEncapsulation();
+ s.endEncapsulation();
throw Ice::UnknownUserException(__FILE__, __LINE__, ex.ice_id());
}
}
@@ -570,11 +611,6 @@ BOOL _returnsData;
[os release];
os = nil;
}
- if(is != nil)
- {
- [is release];
- is = nil;
- }
nsex = toObjCException(ex);
}
if(nsex != nil)
@@ -583,17 +619,6 @@ BOOL _returnsData;
}
NSAssert(os == nil, @"output stream not cleared");
- if(is)
- {
- @try
- {
- unmarshal(is, ok);
- }
- @finally
- {
- [is release];
- }
- }
}
-(id<ICEAsyncResult>) begin_invoke__:(NSString*)operation
@@ -742,9 +767,12 @@ BOOL _returnsData;
os = nil;
}
- Ice::CallbackPtr cb = Ice::newCallback(new BeginInvokeAsyncCallback(completed, exception, sent, returnsData),
- &BeginInvokeAsyncCallback::completed,
- &BeginInvokeAsyncCallback::sent);
+ Ice::Callback_Object_ice_invokePtr cb = Ice::newCallback_Object_ice_invoke(
+ new BeginInvokeAsyncCallback(OBJECTPRX->ice_getCommunicator(), completed, exception, sent, returnsData),
+ &BeginInvokeAsyncCallback::response,
+ &BeginInvokeAsyncCallback::exception,
+ &BeginInvokeAsyncCallback::sent);
+
Ice::AsyncResultPtr r;
if(context != nil)
{
@@ -843,34 +871,33 @@ BOOL _returnsData;
ICEInputStream* is = nil;
try
{
- std::vector<Ice::Byte> outParams;
- ok = OBJECTPRX->end_ice_invoke(outParams, [result asyncResult__]);
+ std::pair<const Ice::Byte*, const Ice::Byte*> outParams;
+ ok = OBJECTPRX->___end_ice_invoke(outParams, [result asyncResult__]);
if(unmarshal)
{
- Ice::InputStreamPtr s = Ice::createInputStream(OBJECTPRX->ice_getCommunicator(), outParams);
- is = [ICEInputStream localObjectWithCxxObjectNoAutoRelease:s.get()];
+ is = [[ICEInputStream alloc] initWithCxxCommunicator:OBJECTPRX->ice_getCommunicator().get() data:outParams];
}
- else if(!outParams.empty())
+ else if(outParams.first != outParams.second)
{
if(ok)
{
- if(outParams.size() != 6)
+ if((outParams.second - outParams.first) != 6)
{
throw Ice::EncapsulationException(__FILE__, __LINE__);
}
}
else
{
- Ice::InputStreamPtr s = Ice::createInputStream(OBJECTPRX->ice_getCommunicator(), outParams);
+ Ice::InputStream s(OBJECTPRX->ice_getCommunicator(), outParams);
try
{
- s->startEncapsulation();
- s->throwException();
+ s.startEncapsulation();
+ s.throwException();
}
catch(const Ice::UserException& ex)
{
- s->endEncapsulation();
+ s.endEncapsulation();
throw Ice::UnknownUserException(__FILE__, __LINE__, ex.ice_id());
}
}
@@ -1294,15 +1321,7 @@ BOOL _returnsData;
inEncaps:(NSData*)inEncaps
outEncaps:(NSMutableData**)outEncaps
{
- __block BOOL ret__;
- cppCall(^ {
- std::pair<const Ice::Byte*, const Ice::Byte*> inP((ICEByte*)[inEncaps bytes],
- (ICEByte*)[inEncaps bytes] + [inEncaps length]);
- std::vector<Ice::Byte> outP;
- ret__ = OBJECTPRX->ice_invoke(fromNSString(operation), (Ice::OperationMode)mode, inP, outP);
- *outEncaps = [NSMutableData dataWithBytes:&outP[0] length:outP.size()];
- });
- return ret__;
+ return [self end_ice_invoke:outEncaps result:[self begin_ice_invoke:operation mode:mode inEncaps:inEncaps]];
}
-(BOOL) ice_invoke:(NSString*)operation
@@ -1311,16 +1330,10 @@ BOOL _returnsData;
outEncaps:(NSMutableData**)outEncaps
context:(ICEContext*)context
{
- __block BOOL ret__;
- cppCall(^(const Ice::Context& ctx) {
- std::pair<const Ice::Byte*, const Ice::Byte*> inP((ICEByte*)[inEncaps bytes],
- (ICEByte*)[inEncaps bytes] + [inEncaps length]);
- std::vector<Ice::Byte> outP;
- ret__ = OBJECTPRX->ice_invoke(fromNSString(operation), (Ice::OperationMode)mode, inP, outP, ctx);
- *outEncaps = [NSMutableData dataWithBytes:&outP[0] length:outP.size()];
- }, context);
- return ret__;
+ return [self end_ice_invoke:outEncaps
+ result:[self begin_ice_invoke:operation mode:mode inEncaps:inEncaps context:context]];
}
+
-(id<ICEAsyncResult>) begin_ice_invoke:(NSString*)operation mode:(ICEOperationMode)mode inEncaps:(NSData*)inEncaps
{
return beginCppCall(^(Ice::AsyncResultPtr& result)
@@ -1384,10 +1397,10 @@ BOOL _returnsData;
^(const Ice::AsyncResultPtr& result) {
std::pair<const ::Ice::Byte*, const ::Ice::Byte*> outP;
BOOL ret__ = OBJECTPRX->___end_ice_invoke(outP, result);
- NSMutableData* outEncaps =
- [NSMutableData dataWithBytes:outP.first length:(outP.second - outP.first)];
if(response)
{
+ NSMutableData* outEncaps =
+ [NSMutableData dataWithBytes:outP.first length:(outP.second - outP.first)];
response(ret__, outEncaps);
}
},
@@ -1415,10 +1428,10 @@ BOOL _returnsData;
^(const Ice::AsyncResultPtr& result) {
std::pair<const ::Ice::Byte*, const ::Ice::Byte*> outP;
BOOL ret__ = OBJECTPRX->___end_ice_invoke(outP, result);
- NSMutableData* outEncaps =
- [NSMutableData dataWithBytes:outP.first length:(outP.second - outP.first)];
if(response)
{
+ NSMutableData* outEncaps =
+ [NSMutableData dataWithBytes:outP.first length:(outP.second - outP.first)];
response(ret__, outEncaps);
}
},
@@ -1430,9 +1443,9 @@ BOOL _returnsData;
__block BOOL ret__;
endCppCall(^(const Ice::AsyncResultPtr& r)
{
- std::vector<Ice::Byte> outP;
- ret__ = OBJECTPRX->end_ice_invoke(outP, r);
- *outEncaps = [NSMutableData dataWithBytes:&outP[0] length:outP.size()];
+ std::pair<const ::Ice::Byte*, const ::Ice::Byte*> outP;
+ ret__ = OBJECTPRX->___end_ice_invoke(outP, r);
+ *outEncaps = [NSMutableData dataWithBytes:outP.first length:(outP.second - outP.first)];
}, result);
return ret__;
}
diff --git a/objective-c/src/Ice/Stream.mm b/objective-c/src/Ice/Stream.mm
index 9654fea4cc7..93b9d2260ce 100644
--- a/objective-c/src/Ice/Stream.mm
+++ b/objective-c/src/Ice/Stream.mm
@@ -18,7 +18,8 @@
#import <objc/Ice/LocalException.h>
-#include <Ice/Stream.h>
+#include <Ice/OutputStream.h>
+#include <Ice/InputStream.h>
#include <Ice/SlicedData.h>
#import <objc/runtime.h>
@@ -28,20 +29,28 @@ ICE_API id ICENone = nil;
namespace IceObjC
{
-class ObjectWriter : public Ice::ObjectWriter
+class ValueWrapper : public Ice::Object
{
public:
- ObjectWriter(ICEObject* obj, ICEOutputStream* stream) : _obj(obj), _stream(stream)
+ // We must explicitely CFRetain/CFRelease so that the garbage
+ // collector does not trash the _obj.
+ ValueWrapper(ICEObject* obj) : _obj(obj)
{
+ CFRetain(_obj);
+ }
+
+ virtual ~ValueWrapper()
+ {
+ CFRelease(_obj);
}
virtual void
- write(const Ice::OutputStreamPtr& stream) const
+ __write(Ice::OutputStream* stream) const
{
@try
{
- [_obj write__:_stream];
+ [_obj write__:static_cast<ICEOutputStream*>(stream->getClosure())];
}
@catch(id ex)
{
@@ -49,44 +58,12 @@ public:
}
}
- virtual void ice_preMarshal()
- {
- [_obj ice_preMarshal];
- }
-
-private:
-
- ICEObject* _obj;
- ICEOutputStream* _stream;
-};
-
-class ObjectReader : public Ice::ObjectReader
-{
-public:
-
- // We must explicitely CFRetain/CFRelease so that the garbage
- // collector does not trash the _obj.
- ObjectReader(ICEObject* obj) : _obj(obj)
- {
- CFRetain(_obj);
- }
-
- virtual ~ObjectReader()
- {
- CFRelease(_obj);
- }
-
virtual void
- read(const Ice::InputStreamPtr& stream)
+ __read(Ice::InputStream* stream)
{
@try
{
- //
- // TODO: explain why calling getLocalObjectWithCxxObjectNoAutoRelease is safe here
- //
- ICEInputStream* is = [ICEInputStream getLocalObjectWithCxxObjectNoAutoRelease:stream.get()];
- assert(is != 0);
- [_obj read__:is];
+ [_obj read__:static_cast<ICEInputStream*>(stream->getClosure())];
}
@catch(id ex)
{
@@ -94,10 +71,9 @@ public:
}
}
- ICEObject*
- getObject()
+ virtual void ice_preMarshal()
{
- return _obj;
+ [_obj ice_preMarshal];
}
virtual void ice_postUnmarshal()
@@ -105,20 +81,32 @@ public:
[_obj ice_postUnmarshal];
}
+ ICEObject*
+ getValue()
+ {
+ return _obj;
+ }
+
private:
ICEObject* _obj;
};
-typedef IceUtil::Handle<ObjectReader> ObjectReaderPtr;
+typedef IceUtil::Handle<ValueWrapper> ValueWrapperPtr;
-class ReadObjectBase : public Ice::ReadObjectCallback
+class ReadValueBase
{
public:
- ReadObjectBase(Class expectedType) : _expectedType(expectedType)
+ ReadValueBase(Class expectedType) : _expectedType(expectedType)
{
}
+ virtual
+ ~ReadValueBase()
+ {
+ }
+
+ virtual void invoke(const Ice::ValuePtr&) = 0;
void checkType(ICEObject*);
private:
@@ -127,7 +115,15 @@ private:
};
void
-ReadObjectBase::checkType(ICEObject* o)
+patchFunc(void* obj, const Ice::ValuePtr& value)
+{
+ ReadValueBase* reader = static_cast<ReadValueBase*>(obj);
+ reader->invoke(value);
+ delete reader;
+}
+
+void
+ReadValueBase::checkType(ICEObject* o)
{
if(o != nil && ![o isKindOfClass:_expectedType])
{
@@ -144,23 +140,23 @@ ReadObjectBase::checkType(ICEObject* o)
}
}
-class ReadObject : public ReadObjectBase
+class ReadValue : public ReadValueBase
{
public:
- ReadObject(ICEObject** addr, Class expectedType, bool autorelease) :
- ReadObjectBase(expectedType), _addr(addr), _autorelease(autorelease)
+ ReadValue(ICEObject** addr, Class expectedType, bool autorelease) :
+ ReadValueBase(expectedType), _addr(addr), _autorelease(autorelease)
{
}
virtual void
- invoke(const Ice::ObjectPtr& obj)
+ invoke(const Ice::ValuePtr& obj)
{
@try
{
if(obj)
{
- ICEObject* o = ObjectReaderPtr::dynamicCast(obj)->getObject();
+ ICEObject* o = ValueWrapperPtr::dynamicCast(obj)->getValue();
checkType(o);
*_addr = [o retain];
if(_autorelease)
@@ -185,23 +181,23 @@ private:
bool _autorelease;
};
-class ReadObjectAtIndex : public ReadObjectBase
+class ReadValueAtIndex : public ReadValueBase
{
public:
- ReadObjectAtIndex(NSMutableArray* array, ICEInt index, Class expectedType) :
- ReadObjectBase(expectedType), _array(array), _index(index)
+ ReadValueAtIndex(NSMutableArray* array, ICEInt index, Class expectedType) :
+ ReadValueBase(expectedType), _array(array), _index(index)
{
}
virtual void
- invoke(const Ice::ObjectPtr& obj)
+ invoke(const Ice::ValuePtr& obj)
{
@try
{
if(obj)
{
- ICEObject* o = ObjectReaderPtr::dynamicCast(obj)->getObject();
+ ICEObject* o = ValueWrapperPtr::dynamicCast(obj)->getValue();
checkType(o);
[_array replaceObjectAtIndex:_index withObject:o];
}
@@ -218,31 +214,31 @@ private:
ICEInt _index;
};
-class ReadObjectForKey : public ReadObjectBase
+class ReadValueForKey : public ReadValueBase
{
public:
// We must explicitely CFRetain/CFRelease so that the garbage
// collector does not trash the _key.
- ReadObjectForKey(NSMutableDictionary* dict, id key, Class expectedType) :
- ReadObjectBase(expectedType), _dict(dict), _key(key)
+ ReadValueForKey(NSMutableDictionary* dict, id key, Class expectedType) :
+ ReadValueBase(expectedType), _dict(dict), _key(key)
{
CFRetain(_key);
}
- virtual ~ReadObjectForKey()
+ virtual ~ReadValueForKey()
{
CFRelease(_key);
}
virtual void
- invoke(const Ice::ObjectPtr& obj)
+ invoke(const Ice::ValuePtr& obj)
{
@try
{
if(obj)
{
- ICEObject* o = ObjectReaderPtr::dynamicCast(obj)->getObject();
+ ICEObject* o = ValueWrapperPtr::dynamicCast(obj)->getValue();
checkType(o);
[_dict setObject:o forKey:_key];
}
@@ -263,20 +259,16 @@ private:
id _key;
};
-class ExceptionWriter : public Ice::UserExceptionWriter
+class ExceptionWrapper : public Ice::UserException
{
public:
- ExceptionWriter(const Ice::CommunicatorPtr& communicator, ICEOutputStream* stream, ICEUserException* ex) :
- Ice::UserExceptionWriter(communicator),
- _stream(stream),
- _ex(ex)
+ ExceptionWrapper(ICEUserException* ex) : _ex(ex)
{
-
}
virtual bool
- usesClasses() const
+ __usesClasses() const
{
return [_ex usesClasses__];
}
@@ -290,7 +282,7 @@ public:
virtual Ice::UserException*
ice_clone() const
{
- return new ExceptionWriter(*this);
+ return new ExceptionWrapper(*this);
}
virtual void
@@ -300,97 +292,55 @@ public:
}
virtual void
- write(const Ice::OutputStreamPtr& stream) const
- {
- [_ex write__:_stream];
- }
-
-private:
-
- ICEOutputStream* _stream;
- ICEUserException* _ex;
-};
-
-class ExceptionReader : public Ice::UserExceptionReader
-{
-public:
-
- ExceptionReader(const Ice::CommunicatorPtr& communicator, ICEInputStream* stream, ICEUserException* ex) :
- Ice::UserExceptionReader(communicator),
- _stream(stream),
- _ex(ex)
- {
- }
-
- void
- read(const Ice::InputStreamPtr& stream) const
- {
- [_ex read__:_stream];
- }
-
- virtual std::string
- ice_id() const
- {
- return [[_ex ice_id] UTF8String];
- }
-
- virtual bool
- usesClasses() const
- {
- return [_ex usesClasses__];
- }
-
- virtual Ice::UserException*
- ice_clone() const
+ __write(Ice::OutputStream* s) const
{
- assert(false);
- return 0;
+ [_ex write__:static_cast<ICEOutputStream*>(s->getClosure())];
}
virtual void
- ice_throw() const
+ __read(Ice::InputStream* s)
{
- throw *this;
+ [_ex read__:static_cast<ICEInputStream*>(s->getClosure())];
}
- ICEUserException* getException() const
+ ICEUserException*
+ getException() const
{
return _ex;
}
+protected:
+
+ virtual void __writeImpl(Ice::OutputStream*) const {}
+ virtual void __readImpl(Ice::InputStream*) {}
+
private:
- ICEInputStream* _stream;
ICEUserException* _ex;
};
-class UserExceptionReaderFactoryI : public Ice::UserExceptionReaderFactory
+class UserExceptionFactoryI : public Ice::UserExceptionFactory
{
public:
- UserExceptionReaderFactoryI(const Ice::CommunicatorPtr& communicator, ICEInputStream* is) :
- _communicator(communicator),
- _is(is)
+ UserExceptionFactoryI(NSDictionary* prefixTable) : _prefixTable(prefixTable)
{
}
- virtual void createAndThrow(const std::string& typeId) const
+ virtual void createAndThrow(const std::string& typeId)
{
ICEUserException* ex = nil;
- std::string objcId = toObjCSliceId(typeId,
- [[ICECommunicator localObjectWithCxxObject:_communicator.get()] getPrefixTable]);
- Class c = objc_lookUpClass(objcId.c_str());
+ Class c = objc_lookUpClass(toObjCSliceId(typeId, _prefixTable).c_str());
if(c != nil)
{
ex = [[c alloc] init];
- throw ExceptionReader(_communicator, _is, ex);
+ throw ExceptionWrapper(ex);
}
}
private:
- Ice::CommunicatorPtr _communicator;
- ICEInputStream* _is;
+ NSDictionary* _prefixTable;
};
}
@@ -428,20 +378,55 @@ private:
@end
@implementation ICEInputStream
--(id) initWithCxxObject:(IceUtil::Shared*)cxxObject
+-(id) initWithCxxCommunicator:(Ice::Communicator*)com data:(const std::pair<const Byte*, const Byte*>&)data
+{
+ self = [super init];
+ if(!self)
+ {
+ return nil;
+ }
+ Ice::InputStream(com, data).swap(stream_);
+ is_ = &stream_;
+ is_->setClosure(self);
+ data_ = nil;
+ prefixTable_ = [[[ICECommunicator localObjectWithCxxObject:com] getPrefixTable] retain];
+ return self;
+}
+
+-(id) initWithCommunicator:(id<ICECommunicator>)communicator data:(NSData*)data encoding:(ICEEncodingVersion*)e
{
- self = [super initWithCxxObject:cxxObject];
+ self = [super init];
if(!self)
{
return nil;
}
- is_ = dynamic_cast<Ice::InputStream*>(cxxObject);
+ ICECommunicator* com = (ICECommunicator*)communicator;
+ std::pair<const Ice::Byte*, const Ice::Byte*> p((Ice::Byte*)[data bytes], (Ice::Byte*)[data bytes] + [data length]);
+ if(e != nil)
+ {
+ Ice::InputStream([com communicator], [e encodingVersion], p).swap(stream_);
+ }
+ else
+ {
+ Ice::InputStream([com communicator], p).swap(stream_);
+ }
+ is_ = &stream_;
+ is_->setClosure(self);
+ data_ = [data retain];
+ prefixTable_ = [[com getPrefixTable] retain];
return self;
}
+-(void) dealloc
+{
+ [data_ release];
+ [prefixTable_ release];
+ [super dealloc];
+}
+
+(Ice::Object*)createObjectReader:(ICEObject*)obj
{
- return new IceObjC::ObjectReader(obj);
+ return new IceObjC::ValueWrapper(obj);
}
-(Ice::InputStream*) is
@@ -451,17 +436,12 @@ private:
// @protocol ICEInputStream methods
--(id<ICECommunicator>) communicator
-{
- return [ICECommunicator localObjectWithCxxObject:is_->communicator().get()];
-}
-
--(void) sliceObjects:(BOOL)b
+-(void) setSliceObjects:(BOOL)b
{
NSException* nsex = nil;
try
{
- is_->sliceObjects(b);
+ is_->setSliceObjects(b);
}
catch(const std::exception& ex)
{
@@ -934,15 +914,9 @@ private:
NSException* nsex = nil;
try
{
- Ice::ObjectPrx p = is_->readProxy();
- if(!p)
- {
- return nil;
- }
- else
- {
- return [[type alloc] initWithObjectPrx__:p];
- }
+ Ice::ObjectPrx p;
+ is_->read(p);
+ return p ? [[type alloc] initWithObjectPrx__:p] : nil;
}
catch(const std::exception& ex)
{
@@ -960,7 +934,7 @@ private:
NSException* nsex = nil;
try
{
- is_->readObject(new IceObjC::ReadObject(object, type, true));
+ is_->read(IceObjC::patchFunc, new IceObjC::ReadValue(object, type, true));
}
catch(const std::exception& ex)
{
@@ -980,7 +954,7 @@ private:
NSException* nsex = nil;
try
{
- is_->readObject(new IceObjC::ReadObject(object, type, false));
+ is_->read(IceObjC::patchFunc, new IceObjC::ReadValue(object, type, false));
}
catch(const std::exception& ex)
{
@@ -1009,7 +983,7 @@ private:
for(i = 0; i < sz; i++)
{
[arr addObject:null];
- is_->readObject(new IceObjC::ReadObjectAtIndex(arr, i, type));
+ is_->read(IceObjC::patchFunc, new IceObjC::ReadValueAtIndex(arr, i, type));
}
}
catch(const std::exception& ex)
@@ -1049,7 +1023,7 @@ private:
NSException* nsex = nil;
try
{
- is_->readObject(new IceObjC::ReadObjectForKey(dictionary, key, type));
+ is_->read(IceObjC::patchFunc, new IceObjC::ReadValueForKey(dictionary, key, type));
}
catch(const std::exception& ex)
{
@@ -1145,7 +1119,7 @@ private:
NSException* nsex = nil;
try
{
- return is_->readOptional(tag, static_cast<Ice::OptionalFormat>(format));
+ return is_->readOpt(tag, static_cast<Ice::OptionalFormat>(format));
}
catch(const std::exception& ex)
{
@@ -1164,13 +1138,11 @@ private:
NSException* nsex = nil;
try
{
- Ice::UserExceptionReaderFactoryPtr factory =
- new IceObjC::UserExceptionReaderFactoryI(is_->communicator().get(), self);
- is_->throwException(factory);
+ is_->throwException(new IceObjC::UserExceptionFactoryI(prefixTable_));
}
- catch(const IceObjC::ExceptionReader& reader)
+ catch(const IceObjC::ExceptionWrapper& e)
{
- ex = reader.getException();
+ ex = e.getException();
@throw [ex autorelease]; // NOTE: exceptions are always auto-released, no need for the caller to do it.
}
catch(const std::exception& ex)
@@ -1383,7 +1355,8 @@ private:
NSException* nsex = nil;
try
{
- is_->rewind();
+ is_->pos(0);
+ is_->clear();
}
catch(const std::exception& ex)
{
@@ -1395,6 +1368,7 @@ private:
}
}
+
-(void) skip:(ICEInt)sz
{
NSException* nsex = nil;
@@ -1432,14 +1406,51 @@ private:
@end
@implementation ICEOutputStream
--(id) initWithCxxObject:(IceUtil::Shared*)cxxObject
+-(id) initWithCxxCommunicator:(Ice::Communicator*)com
+{
+ self = [super init];
+ if(!self)
+ {
+ return nil;
+ }
+ Ice::OutputStream(com).swap(stream_);
+ os_ = &stream_;
+ os_->setClosure(self);
+ objectWriters_ = 0;
+ return self;
+}
+
+-(id) initWithCxxStream:(Ice::OutputStream*)stream
+{
+ self = [super init];
+ if(!self)
+ {
+ return nil;
+ }
+ os_ = stream;
+ os_->setClosure(self);
+ objectWriters_ = 0;
+ return self;
+}
+
+-(id) initWithCommunicator:(id<ICECommunicator>)communicator encoding:(ICEEncodingVersion*)e
{
- self = [super initWithCxxObject:cxxObject];
+ self = [super init];
if(!self)
{
return nil;
}
- os_ = dynamic_cast<Ice::OutputStream*>(cxxObject);
+ ICECommunicator* com = (ICECommunicator*)communicator;
+ if(e != nil)
+ {
+ Ice::OutputStream([com communicator], [e encodingVersion]).swap(stream_);
+ }
+ else
+ {
+ Ice::OutputStream([com communicator]).swap(stream_);
+ }
+ os_ = &stream_;
+ os_->setClosure(self);
objectWriters_ = 0;
return self;
}
@@ -1460,11 +1471,6 @@ private:
// @protocol ICEOutputStream methods
--(id<ICECommunicator>) communicator
-{
- return [ICECommunicator localObjectWithCxxObject:os_->communicator().get()];
-}
-
-(void)writeBool:(BOOL)v
{
NSException* nsex = nil;
@@ -1487,8 +1493,7 @@ private:
NSException* nsex = nil;
try
{
- v == nil ? os_->writeSize(0)
- : os_->write((bool*)[v bytes], (bool*)[v bytes] + [v length] / sizeof(BOOL));
+ v == nil ? os_->writeSize(0) : os_->write((bool*)[v bytes], (bool*)[v bytes] + [v length] / sizeof(BOOL));
}
catch(const std::exception& ex)
{
@@ -1522,8 +1527,7 @@ private:
NSException* nsex = nil;
try
{
- v == nil ? os_->writeSize(0)
- : os_->write((ICEByte*)[v bytes], (ICEByte*)[v bytes] + [v length]);
+ v == nil ? os_->writeSize(0) : os_->write((ICEByte*)[v bytes], (ICEByte*)[v bytes] + [v length]);
}
catch(const std::exception& ex)
{
@@ -1789,7 +1793,7 @@ private:
NSException* nsex = nil;
try
{
- return os_->writeOptional(tag, static_cast<Ice::OptionalFormat>(format));
+ return os_->writeOpt(tag, static_cast<Ice::OptionalFormat>(format));
}
catch(const std::exception& ex)
{
@@ -1899,7 +1903,7 @@ private:
NSException* nsex = nil;
try
{
- os_->writeProxy([(ICEObjectPrx*)v objectPrx__]);
+ os_->write(Ice::ObjectPrx([(ICEObjectPrx*)v objectPrx__]));
}
catch(const std::exception& ex)
{
@@ -1918,11 +1922,11 @@ private:
{
if(v == nil)
{
- os_->writeObject(0);
+ os_->write(Ice::ValuePtr());
}
else
{
- os_->writeObject([self addObject:v]);
+ os_->write(Ice::ValuePtr([self addObject:v]));
}
}
catch(const std::exception& ex)
@@ -1975,7 +1979,7 @@ private:
-(void) writeException:(ICEUserException*)ex
{
- IceObjC::ExceptionWriter writer(os_->communicator().get(), self, ex);
+ IceObjC::ExceptionWrapper writer(ex);
os_->writeException(writer);
}
@@ -2206,7 +2210,8 @@ private:
NSException* nsex = nil;
try
{
- os_->reset(clearBuffer);
+ os_->clear();
+ os_->resize(0);
}
catch(const std::exception& ex)
{
@@ -2221,23 +2226,23 @@ private:
-(Ice::Object*) addObject:(ICEObject*)object
{
//
- // Ice::ObjectWriter is a subclass of Ice::Object that wraps an Objective-C object for marshaling.
+ // Ice::ValueWrapper is a subclass of Ice::Object that wraps an Objective-C object for marshaling.
// It is possible that this Objective-C object has already been marshaled, therefore we first must
- // check the object map to see if this object is present. If so, we use the existing ObjectWriter,
+ // check the object map to see if this object is present. If so, we use the existing ValueWrapper,
// otherwise we create a new one.
//
if(!objectWriters_)
{
- objectWriters_ = new std::map<ICEObject*, Ice::ObjectPtr>();
+ objectWriters_ = new std::map<ICEObject*, Ice::ValuePtr>();
}
- std::map<ICEObject*, Ice::ObjectPtr>::const_iterator p = objectWriters_->find(object);
+ std::map<ICEObject*, Ice::ValuePtr>::const_iterator p = objectWriters_->find(object);
if(p != objectWriters_->end())
{
return p->second.get();
}
else
{
- Ice::ObjectWriterPtr writer = new IceObjC::ObjectWriter(object, self);
+ IceObjC::ValueWrapperPtr writer = new IceObjC::ValueWrapper(object);
objectWriters_->insert(std::make_pair(object, writer));
return writer.get();
}
@@ -2257,12 +2262,12 @@ private:
info->hasOptionalMembers = (*p)->hasOptionalMembers;
info->isLastSlice = (*p)->isLastSlice;
- for(std::vector<Ice::ObjectPtr>::const_iterator q = (*p)->objects.begin(); q != (*p)->objects.end(); ++q)
+ for(std::vector<Ice::ValuePtr>::const_iterator q = (*p)->objects.begin(); q != (*p)->objects.end(); ++q)
{
if(*q)
{
- assert(IceObjC::ObjectReaderPtr::dynamicCast(*q));
- info->objects.push_back([self addObject:IceObjC::ObjectReaderPtr::dynamicCast(*q)->getObject()]);
+ assert(IceObjC::ValueWrapperPtr::dynamicCast(*q));
+ info->objects.push_back([self addObject:IceObjC::ValueWrapperPtr::dynamicCast(*q)->getValue()]);
}
else
{
diff --git a/objective-c/src/Ice/StreamI.h b/objective-c/src/Ice/StreamI.h
index 650e9c4eefb..564781c9f8d 100644
--- a/objective-c/src/Ice/StreamI.h
+++ b/objective-c/src/Ice/StreamI.h
@@ -10,20 +10,32 @@
#import <objc/Ice/Stream.h>
#import <objc/Ice/LocalObject.h>
-#include <Ice/Stream.h>
+#include <Ice/InputStream.h>
+#include <Ice/OutputStream.h>
-@interface ICEInputStream : ICELocalObject<ICEInputStream>
+@protocol ICECommunicator;
+
+@interface ICEInputStream : NSObject<ICEInputStream>
{
Ice::InputStream* is_;
+ Ice::InputStream stream_;
+ NSDictionary* prefixTable_;
+ NSData* data_;
}
+(Ice::Object*)createObjectReader:(ICEObject*)obj;
+-initWithCxxCommunicator:(Ice::Communicator*)com data:(const std::pair<const Byte*, const Byte*>&)data;
+-initWithCommunicator:(id<ICECommunicator>)com data:(NSData*)data encoding:(ICEEncodingVersion*)e;
-(Ice::InputStream*) is;
@end
-@interface ICEOutputStream : ICELocalObject<ICEOutputStream>
+@interface ICEOutputStream : NSObject<ICEOutputStream>
{
Ice::OutputStream* os_;
+ Ice::OutputStream stream_;
std::map<ICEObject*, Ice::ObjectPtr>* objectWriters_;
}
+-initWithCxxCommunicator:(Ice::Communicator*)communicator;
+-initWithCxxStream:(Ice::OutputStream*)stream;
+-initWithCommunicator:(id<ICECommunicator>)com encoding:(ICEEncodingVersion*)e;
-(Ice::OutputStream*) os;
@end
diff --git a/objective-c/src/Ice/Util.mm b/objective-c/src/Ice/Util.mm
index 8ac8aa3f14b..27a555ff040 100644
--- a/objective-c/src/Ice/Util.mm
+++ b/objective-c/src/Ice/Util.mm
@@ -455,14 +455,14 @@ toObjC(const Ice::ObjectPtr& object)
return nil;
}
- IceObjC::ObjectWrapperPtr wrapper = IceObjC::ObjectWrapperPtr::dynamicCast(object);
+ IceObjC::ServantWrapperPtr wrapper = IceObjC::ServantWrapperPtr::dynamicCast(object);
if(wrapper)
{
//
// Given object is an Objective-C servant wrapped into a C++
// object, return the wrapped Objective-C object.
//
- return [[wrapper->getObject() retain] autorelease];
+ return [[wrapper->getServant() retain] autorelease];
}
else if(Ice::NativePropertiesAdminPtr::dynamicCast(object))
{
@@ -470,13 +470,13 @@ toObjC(const Ice::ObjectPtr& object)
// Given object is a properties admin facet, return the
// Objective-C wrapper.
//
- return [ICENativePropertiesAdmin objectWrapperWithCxxObject:object.get()];
+ return [ICENativePropertiesAdmin servantWrapperWithCxxObject:object.get()];
}
else
{
//
// Given object is a C++ servant, return an Objective-C wrapper.
//
- return [ICEObjectWrapper objectWrapperWithCxxObject:object.get()];
+ return [ICEServantWrapper servantWrapperWithCxxObject:object.get()];
}
}
diff --git a/objective-c/src/Ice/ValueFactoryI.h b/objective-c/src/Ice/ValueFactoryI.h
new file mode 100644
index 00000000000..94fd250e015
--- /dev/null
+++ b/objective-c/src/Ice/ValueFactoryI.h
@@ -0,0 +1,19 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#import <objc/Ice/ValueFactory.h>
+
+#include <Ice/Communicator.h>
+
+@interface ICEValueFactoryManager : NSObject<ICEValueFactoryManager>
+{
+ NSMutableDictionary* valueFactories_;
+}
+-(id) init:(Ice::Communicator*)communicator prefixTable:(NSDictionary*)prefixTable;
+@end
diff --git a/objective-c/src/Ice/ValueFactoryI.mm b/objective-c/src/Ice/ValueFactoryI.mm
new file mode 100644
index 00000000000..9468d009f0b
--- /dev/null
+++ b/objective-c/src/Ice/ValueFactoryI.mm
@@ -0,0 +1,161 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <Ice/ObjectFactory.h>
+
+#import <ValueFactoryI.h>
+#import <LocalObjectI.h>
+#import <StreamI.h>
+#import <Util.h>
+
+#import <objc/Ice/ObjectFactory.h>
+#import <objc/Ice/SlicedData.h>
+
+#import <objc/runtime.h>
+
+namespace IceObjC
+{
+
+class UnknownSlicedValueFactoryI : public Ice::ValueFactory
+{
+public:
+
+ virtual Ice::ObjectPtr
+ create(const std::string&)
+ {
+ ICEUnknownSlicedObject* obj = [[ICEUnknownSlicedObject alloc] init];
+ Ice::ObjectPtr o = [ICEInputStream createObjectReader:obj];
+ [obj release];
+ return o;
+ }
+};
+
+class ValueFactoryI : public Ice::ValueFactory
+{
+public:
+
+ // We must explicitely CFRetain/CFRelease so that the garbage
+ // collector does not trash the dictionaries.
+ ValueFactoryI(NSDictionary* factories, NSDictionary* prefixTable) :
+ _factories(factories), _prefixTable(prefixTable)
+ {
+ CFRetain(_factories);
+ CFRetain(_prefixTable);
+ }
+
+ ~ValueFactoryI()
+ {
+ CFRelease(_factories);
+ CFRelease(_prefixTable);
+ }
+
+ virtual Ice::ObjectPtr
+ create(const std::string& type)
+ {
+ NSString* sliceId = [[NSString alloc] initWithUTF8String:type.c_str()];
+ @try
+ {
+ ICEValueFactory factory = nil;
+ @synchronized(_factories)
+ {
+ factory = [_factories objectForKey:sliceId];
+ if(factory == nil)
+ {
+ factory = [_factories objectForKey:@""];
+ }
+ }
+
+ ICEObject* obj = nil;
+ if(factory != nil)
+ {
+ obj = [factory(sliceId) retain];
+ }
+
+ if(obj == nil)
+ {
+ std::string tId = toObjCSliceId(type, _prefixTable);
+ Class c = objc_lookUpClass(tId.c_str());
+ if(c == nil)
+ {
+ return 0; // No value factory.
+ }
+ if([c isSubclassOfClass:[ICEObject class]])
+ {
+ obj = (ICEObject*)[[c alloc] init];
+ }
+ }
+
+ Ice::ObjectPtr o;
+ if(obj != nil)
+ {
+ o = [ICEInputStream createObjectReader:obj];
+ [obj release];
+ }
+ return o;
+ }
+ @catch(id ex)
+ {
+ rethrowCxxException(ex);
+ }
+ @finally
+ {
+ [sliceId release];
+ }
+ return nil; // Keep the compiler happy.
+ }
+
+private:
+
+ NSDictionary* _factories;
+ NSDictionary* _prefixTable;
+};
+
+}
+
+@implementation ICEValueFactoryManager
+-(id) init:(Ice::Communicator*)com prefixTable:(NSDictionary*)prefixTable
+{
+ self = [super init];
+ if(!self)
+ {
+ return nil;
+ }
+
+ valueFactories_ = [[NSMutableDictionary alloc] init];
+
+ com->getValueFactoryManager()->add(new IceObjC::UnknownSlicedValueFactoryI, "::Ice::Object");
+ com->getValueFactoryManager()->add(new IceObjC::ValueFactoryI(valueFactories_, prefixTable), "");
+
+ return self;
+}
+
+-(void) dealloc
+{
+ [valueFactories_ release];
+ [super dealloc];
+}
+
+-(void) add:(ICEValueFactory)factory sliceId:(NSString*)sliceId
+{
+ @synchronized(valueFactories_)
+ {
+ [valueFactories_ setObject:ICE_AUTORELEASE([factory copy]) forKey:sliceId];
+ }
+}
+
+-(ICEValueFactory) find:(NSString*)sliceId
+{
+ @synchronized(valueFactories_)
+ {
+ return [valueFactories_ objectForKey:sliceId];
+ }
+ return nil; // Keep the compiler happy.
+}
+
+@end
diff --git a/objective-c/test/Ice/objects/AllTests.m b/objective-c/test/Ice/objects/AllTests.m
index 4c296575049..ffbb46053d1 100644
--- a/objective-c/test/Ice/objects/AllTests.m
+++ b/objective-c/test/Ice/objects/AllTests.m
@@ -516,7 +516,7 @@ objectsAllTests(id<ICECommunicator> communicator, BOOL collocated)
tprintf("ok\n");
tprintf("testing getting ObjectFactory as ValueFactory... ");
- test([communicator findValueFactory:@"TestOF"] != nil);
+ test([[communicator getValueFactoryManager] find:@"TestOF"] != nil);
tprintf("ok\n");
}
diff --git a/objective-c/test/Ice/objects/Client.m b/objective-c/test/Ice/objects/Client.m
index 56f27534553..f2ded88aae0 100644
--- a/objective-c/test/Ice/objects/Client.m
+++ b/objective-c/test/Ice/objects/Client.m
@@ -21,35 +21,35 @@ ICEValueFactory factory = ^ICEObject* (NSString* type)
{
if([type isEqualToString:@"::Test::B"])
{
- return [[TestObjectsBI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsBI alloc] init]);
}
else if([type isEqualToString:@"::Test::C"])
{
- return [[TestObjectsCI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsCI alloc] init]);
}
else if([type isEqualToString:@"::Test::D"])
{
- return [[TestObjectsDI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsDI alloc] init]);
}
else if([type isEqualToString:@"::Test::E"])
{
- return [[TestObjectsEI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsEI alloc] init]);
}
else if([type isEqualToString:@"::Test::F"])
{
- return [[TestObjectsFI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsFI alloc] init]);
}
else if([type isEqualToString:@"::Test::I"])
{
- return [[TestObjectsI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsI alloc] init]);
}
else if([type isEqualToString:@"::Test::J"])
{
- return [[TestObjectsJI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsJI alloc] init]);
}
else if([type isEqualToString:@"::Test::H"])
{
- return [[TestObjectsHI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsHI alloc] init]);
}
else
{
@@ -77,14 +77,15 @@ ICEValueFactory factory = ^ICEObject* (NSString* type)
static int
run(id<ICECommunicator> communicator)
{
- [communicator addValueFactory:factory sliceId:@"::Test::B"];
- [communicator addValueFactory:factory sliceId:@"::Test::C"];
- [communicator addValueFactory:factory sliceId:@"::Test::D"];
- [communicator addValueFactory:factory sliceId:@"::Test::E"];
- [communicator addValueFactory:factory sliceId:@"::Test::F"];
- [communicator addValueFactory:factory sliceId:@"::Test::I"];
- [communicator addValueFactory:factory sliceId:@"::Test::J"];
- [communicator addValueFactory:factory sliceId:@"::Test::H"];
+ id<ICEValueFactoryManager> manager = [communicator getValueFactoryManager];
+ [manager add:factory sliceId:@"::Test::B"];
+ [manager add:factory sliceId:@"::Test::C"];
+ [manager add:factory sliceId:@"::Test::D"];
+ [manager add:factory sliceId:@"::Test::E"];
+ [manager add:factory sliceId:@"::Test::F"];
+ [manager add:factory sliceId:@"::Test::I"];
+ [manager add:factory sliceId:@"::Test::J"];
+ [manager add:factory sliceId:@"::Test::H"];
id<ICEObjectFactory> objectFactory = ICE_AUTORELEASE([[ClientMyObjectFactory alloc] init]);
[communicator addObjectFactory:objectFactory sliceId:@"TestOF" ];
diff --git a/objective-c/test/Ice/objects/Collocated.m b/objective-c/test/Ice/objects/Collocated.m
index 63d4d4a0430..cf187299013 100644
--- a/objective-c/test/Ice/objects/Collocated.m
+++ b/objective-c/test/Ice/objects/Collocated.m
@@ -17,35 +17,35 @@ ICEValueFactory factory = ^ICEObject* (NSString* type)
{
if([type isEqualToString:@"::Test::B"])
{
- return [[TestObjectsBI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsBI alloc] init]);
}
else if([type isEqualToString:@"::Test::C"])
{
- return [[TestObjectsCI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsCI alloc] init]);
}
else if([type isEqualToString:@"::Test::D"])
{
- return [[TestObjectsDI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsDI alloc] init]);
}
else if([type isEqualToString:@"::Test::E"])
{
- return [[TestObjectsEI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsEI alloc] init]);
}
else if([type isEqualToString:@"::Test::F"])
{
- return [[TestObjectsFI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsFI alloc] init]);
}
else if([type isEqualToString:@"::Test::I"])
{
- return [[TestObjectsI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsI alloc] init]);
}
else if([type isEqualToString:@"::Test::J"])
{
- return [[TestObjectsJI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsJI alloc] init]);
}
else if([type isEqualToString:@"::Test::H"])
{
- return [[TestObjectsHI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsHI alloc] init]);
}
else
{
@@ -73,14 +73,15 @@ ICEValueFactory factory = ^ICEObject* (NSString* type)
static int
run(id<ICECommunicator> communicator)
{
- [communicator addValueFactory:factory sliceId:@"::Test::B"];
- [communicator addValueFactory:factory sliceId:@"::Test::C"];
- [communicator addValueFactory:factory sliceId:@"::Test::D"];
- [communicator addValueFactory:factory sliceId:@"::Test::E"];
- [communicator addValueFactory:factory sliceId:@"::Test::F"];
- [communicator addValueFactory:factory sliceId:@"::Test::I"];
- [communicator addValueFactory:factory sliceId:@"::Test::J"];
- [communicator addValueFactory:factory sliceId:@"::Test::H"];
+ id<ICEValueFactoryManager> manager = [communicator getValueFactoryManager];
+ [manager add:factory sliceId:@"::Test::B"];
+ [manager add:factory sliceId:@"::Test::C"];
+ [manager add:factory sliceId:@"::Test::D"];
+ [manager add:factory sliceId:@"::Test::E"];
+ [manager add:factory sliceId:@"::Test::F"];
+ [manager add:factory sliceId:@"::Test::I"];
+ [manager add:factory sliceId:@"::Test::J"];
+ [manager add:factory sliceId:@"::Test::H"];
id<ICEObjectFactory> objectFactory = ICE_AUTORELEASE([[ClientMyObjectFactory alloc] init]);
[communicator addObjectFactory:objectFactory sliceId:@"TestOF" ];
diff --git a/objective-c/test/Ice/objects/Server.m b/objective-c/test/Ice/objects/Server.m
index f006cb342be..3a3bc6ddd40 100644
--- a/objective-c/test/Ice/objects/Server.m
+++ b/objective-c/test/Ice/objects/Server.m
@@ -17,15 +17,15 @@ ICEValueFactory factory = ^ICEObject* (NSString* type)
{
if([type isEqualToString:@"::Test::I"])
{
- return [[TestObjectsI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsI alloc] init]);
}
else if([type isEqualToString:@"::Test::J"])
{
- return [[TestObjectsJI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsJI alloc] init]);
}
else if([type isEqualToString:@"::Test::H"])
{
- return [[TestObjectsHI alloc] init];
+ return ICE_AUTORELEASE([[TestObjectsHI alloc] init]);
}
else
{
@@ -37,9 +37,9 @@ ICEValueFactory factory = ^ICEObject* (NSString* type)
static int
run(id<ICECommunicator> communicator)
{
- [communicator addValueFactory:factory sliceId:@"::Test::I"];
- [communicator addValueFactory:factory sliceId:@"::Test::J"];
- [communicator addValueFactory:factory sliceId:@"::Test::H"];
+ [[communicator getValueFactoryManager] add:factory sliceId:@"::Test::I"];
+ [[communicator getValueFactoryManager] add:factory sliceId:@"::Test::J"];
+ [[communicator getValueFactoryManager] add:factory sliceId:@"::Test::H"];
[[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"];
id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"];
diff --git a/objective-c/test/Ice/optional/AllTests.m b/objective-c/test/Ice/optional/AllTests.m
index 331ca79e479..07647b3b5f8 100644
--- a/objective-c/test/Ice/optional/AllTests.m
+++ b/objective-c/test/Ice/optional/AllTests.m
@@ -277,8 +277,7 @@ id<TestOptionalInitialPrx>
optionalAllTests(id<ICECommunicator> communicator)
{
FactoryI* factory = [FactoryI factoryI];
- [communicator addValueFactory:^(id s) { return [factory create:s]; }
- sliceId:@""];
+ [[communicator getValueFactoryManager] add:^(id s) { return [factory create:s]; } sliceId:@""];
tprintf("testing stringToProxy... ");
NSString* sref = @"initial:default -p 12010";
diff --git a/objective-c/test/Ice/servantLocator/AllTests.m b/objective-c/test/Ice/servantLocator/AllTests.m
index a390d456fc1..5761025cde0 100644
--- a/objective-c/test/Ice/servantLocator/AllTests.m
+++ b/objective-c/test/Ice/servantLocator/AllTests.m
@@ -79,7 +79,7 @@ testExceptions(id<TestServantLocatorTestIntfPrx> obj)
}
@catch(ICEUnknownUserException* ex)
{
- test([ex.unknown isEqual:@"Test::TestIntfUserException"]);
+ test([ex.unknown isEqual:@"::Test::TestIntfUserException"]);
}
@catch(ICEOperationNotExistException*)
{
@@ -197,7 +197,7 @@ servantLocatorAllTests(id<ICECommunicator> communicator)
}
@catch(ICEUnknownUserException* ex)
{
- test([ex.unknown isEqual:@"Test::TestIntfUserException"]);
+ test([ex.unknown isEqual:@"::Test::TestIntfUserException"]);
}
@catch(id)
{
@@ -212,7 +212,7 @@ servantLocatorAllTests(id<ICECommunicator> communicator)
}
@catch(ICEUnknownUserException* ex)
{
- test([ex.unknown isEqual:@"Test::TestIntfUserException"]);
+ test([ex.unknown isEqual:@"::Test::TestIntfUserException"]);
}
@catch(id)
{
diff --git a/objective-c/test/Ice/stream/Client.m b/objective-c/test/Ice/stream/Client.m
index a05ca4ecf9c..dd1a0b445da 100644
--- a/objective-c/test/Ice/stream/Client.m
+++ b/objective-c/test/Ice/stream/Client.m
@@ -44,12 +44,6 @@ run(id<ICECommunicator> communicator)
v = [in readBool];
test(v);
[in endEncapsulation];
-
- in = [ICEUtil wrapInputStream:communicator data:data];
- [in startEncapsulation];
- v = [in readBool];
- test(v);
- [in endEncapsulation];
}
{
@@ -236,7 +230,7 @@ run(id<ICECommunicator> communicator)
}
{
- BOOL buf[] = { YES, YES, NO, YES };
+ BOOL buf[] = { YES, YES, NO, YES };
ICEBoolSeq* arr = [ICEBoolSeq dataWithBytes:buf length:sizeof(buf)];
out = [ICEUtil createOutputStream:communicator];