Server code -- event
class event_srv : public handler_srv, _crob(hush,event) {
public:
event_srv(event* e) : handler_srv(e) { }
event_srv() { _type = 0; _x = 0; _y = 0; }
virtual void type( long t, ENV ) { _type = t; }
virtual long type( ENV ) { return _type; }
virtual void x( long t, ENV ) { _x = t; }
virtual long x( ENV ) { return _x; }
virtual void y( long t, ENV ) { _y = t; }
virtual long y( ENV ) { return _y; }
protected:
event* _body() { return (event*) handler_srv::_body(); }
long _type, _x, _y;
};
slide: Server code - event
Client adaptor - event
class event_clt : public event {
public:
event_clt(hush::event* x) : _bdy(x), event(this) { }
hush::event* operator->() { return _body(); }
virtual int type() const { return (int) _body()->type(); }
virtual int x() const { return (int) _body()->x(); }
virtual int y() const { return (int) _body()->y(); }
virtual void type(int n) { _body()->type( (long) n ); }
virtual void x(int n) { _body()->x( (long) n ); }
virtual void y(int n) { _body()->y( (long) n ); }
/* Orbix 2.0
virtual void type(int n) { _body()->type( (CORBA::Long) n ); }
virtual void x(int n) { _body()->x( (CORBA::Long) n ); }
virtual void y(int n) { _body()->y( (CORBA::Long) n ); }
*/
private:
void* _bdy;
hush::event* _body() const { return (hush::event*) _bdy; }
};
slide: Client adaptor - event
The kit
Both the server and client-side implementations of
kit delegate the calls to their embedded objects,
respectively a hush kit object and a CORBA IDL
kit object.
Server code - kit
class kit_srv : public handler_srv, _crob(hush,kit) {
public:
kit_srv(kit* tk) : handler_srv(tk) { }
virtual void source( const char* s, ENV ) {
char* p = new char[strlen(s)+1]; strcpy(p,s);
_body()->source(p);
}
virtual void eval( const char* s, ENV ) {
_body()->eval(s);
}
virtual hush::term* result( ENV ) {
term* x = (term*) _body()->result();
hush::term* res = new term_srv(x);
res->_duplicate(); // orbix 1.3
return res;
}
virtual void update( ENV ) { _body()->update(); }
virtual hush::widget* root( ENV );
protected:
kit* _body() { return (kit*) handler_srv::_body(); }
};
slide: Server code - kit
Client adaptor
class kit_clt : public kit {
public:
kit_clt(hush::kit* x) : _bdy(x) { }
virtual int eval( const char* s ) { _body()->eval(s); return 0; }
virtual widget* root( ) const;
private:
void* _bdy;
hush::kit* _body() const { return (hush::kit*) _bdy; }
};
slide: Client-adaptor - kit
Lists
The implementation of lists and iterators as template
C++ classes are taken from the work by John Caspers,
reported in Isis.
Server code -- list
template<class T>
class list_srv : _crob(hush,container) {
public:
list_srv(list<T>* it = 0) : _bdy(it) {
this->_duplicate();
}
hush::iterator* walk( ENV ) {
iter<void>* it = ((list<void>*) _body())->walk();
iter_srv* x = new iter_srv(it);
x->_duplicate();
return x;
}
long length( ENV ) {
return (long) _body()->length();
}
CORBA::Object* first( ENV ) {
T* x = _body()->first();
//dummy->_duplicate(x); // Orbix 2.0
x->_duplicate();
return x;
}
CORBA::Object* current( ENV ) {
T* x = _body()->current();
x->_duplicate();
return x;
}
CORBA::Object* next( ENV ) {
T* x = _body()->next();
x->_duplicate();
return x;
}
protected:
T* dummy; // for duplication in 2.0
list<T>* _bdy;
list<T>* _body() const { return (list<T>*) _bdy; }
};
slide: Server code -- list
Client adaptor - list
template<class T>
class list_clt : public list<T> {
public:
list_clt(hush::container* it = 0, T* = 0) : _bdy(it) { }
list_clt<T>* operator->() { return this; }
void operator=(hush::container* it) { _bdy = it; }
T* first() {
CORBA::Object* x = _body()->first();
if (x)
return (T*) dummy->_narrow(x);
else return 0;
}
T* next() {
CORBA::Object* x = _body()->next();
if (x)
return (T*) dummy->_narrow(x);
else return 0;
}
protected:
hush::container* _bdy;
hush::container* _body() const { return (hush::container*) _bdy; }
private:
static T* dummy;
};
};
slide: Client adaptor - list
Iterators
The implementation of the iter class follows
the same schema as the list implementation.
In particular for narrowing CORBA Objects to the actual
type T of the template client adaptor a static instance variable
dummy has been introduced.
This solution is again due to John Caspers.
Server code - iter
class iter_srv : _crob(hush,iterator) {
public:
iter_srv(void* it) : _bdy(it) { }
CORBA::Object* next( ENV ) {
return _body()->operator()();
}
protected:
void* _bdy;
iter<CORBA::Object>* _body() const { return (iter<CORBA::Object>*) _bdy; }
};
slide: Server code - iter
Client adaptor - iter
class iter_clt : public iter<T> {
public:
iter_clt(hush::iterator* it = 0, T* = 0) : _bdy(it) { }
hush::iterator* operator->() { return _body(); }
void operator=(hush::iterator* it) { _bdy = it; }
T* operator()() {
CORBA::Object* x = _body()->next();
if (x)
return (T*) dummy._narrow(x);
else return 0;
}
protected:
hush::iterator* _bdy;
hush::iterator* _body() const { return (hush::iterator*) _bdy; }
private:
static T dummy;
};
slide: Client adaptor - iter
[]
introduction,
legacy,
interfaces,
examples,
conclusions,
references,
appendix