Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

DelegateMixin.hh

Go to the documentation of this file.
00001 /*
00002  * DelegateMixin.hh
00003  *
00004  * Copyright (c) 2003, 2004 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file DelegateMixin.hh
00014  *
00015  * Header file for the DelegateMixin class.
00016  */
00017 
00018 #ifndef _delegate_mixin_hh
00019 #define _delegate_mixin_hh
00020 
00021 #include "DelegateS.h"
00022 
00023 /**
00024  * Base class for objects that wish to act as a delegate.
00025  *
00026  * @param T The main object type.
00027  * @param T_var The object's _var type.
00028  */
00029 template <class T, class T_var> class DelegateMixin :
00030     public virtual POA_BrokerDelegates::Delegate
00031 {
00032 
00033 public:
00034 
00035     /**
00036      * Construct a DelegateMixin with the default values.
00037      */
00038     DelegateMixin(void)
00039     {
00040     };
00041 
00042     /**
00043      * Deconstruct a DelegateMixin.
00044      */
00045     virtual ~DelegateMixin(void)
00046     {
00047     };
00048 
00049     /** @copydoc BrokerDelegates::Delegate::SetDelegateAttribute */
00050     virtual void SetDelegateAttribute(const char *id,
00051                                       const CORBA::Any &value)
00052         throw (CORBA::SystemException)
00053     {
00054         if( id == NULL )
00055         {
00056             throw CORBA::BAD_PARAM();
00057         }
00058         else if( strcasecmp(id, "remote-object") == 0 )
00059         {
00060             CORBA::Object_var obj;
00061 
00062             if( value >>= CORBA::Any::to_object(obj) )
00063             {
00064                 this->dm_RemoteObject = T::_narrow(obj.in());
00065             }
00066             else
00067             {
00068                 throw CORBA::BAD_PARAM();
00069             }
00070         }
00071         else
00072         {
00073             throw CORBA::BAD_PARAM();
00074         }
00075     };
00076 
00077     /** @copydoc BrokerDelegates::Delegate::GetDelegateAttribute */
00078     virtual CORBA::Any_ptr GetDelegateAttribute(const char *id)
00079         throw (CORBA::SystemException)
00080     {
00081         CORBA::Any_var retval = new CORBA::Any();
00082 
00083         if( id == NULL )
00084         {
00085             throw CORBA::BAD_PARAM();
00086         }
00087         else if( strcasecmp(id, "remote-object") == 0 )
00088         {
00089             *retval <<= this->dm_RemoteObject.in();
00090         }
00091         else
00092         {
00093             throw CORBA::BAD_PARAM();
00094         }
00095         return( retval._retn() );
00096     };
00097 
00098     /* XXX BEGIN HACK MODE */
00099     virtual void SetDelegateAttributeObject(const char *id,
00100                                             const CORBA::Object_ptr value)
00101         throw (CORBA::SystemException)
00102     {
00103         if( id == NULL )
00104         {
00105             throw CORBA::BAD_PARAM();
00106         }
00107         else if( strcasecmp(id, "remote-object") == 0 )
00108         {
00109             if( CORBA::is_nil(value) )
00110             {
00111                 this->dm_RemoteObject = T::_nil();
00112             }
00113             else
00114             {
00115                 T_var tmp = T::_narrow(value);
00116 
00117                 if( CORBA::is_nil(tmp.in()) )
00118                 {
00119                     throw CORBA::BAD_PARAM();
00120                 }
00121                 else
00122                 {
00123                     this->dm_RemoteObject = tmp;
00124                 }
00125             }
00126         }
00127         else
00128         {
00129             throw CORBA::BAD_PARAM();
00130         }
00131     };
00132 
00133     virtual CORBA::Object_ptr GetDelegateAttributeObject(const char *id)
00134         throw (CORBA::SystemException)
00135     {
00136         CORBA::Object_var retval;
00137 
00138         if( id == NULL )
00139         {
00140             throw CORBA::BAD_PARAM();
00141         }
00142         else if( strcasecmp(id, "remote-object") == 0 )
00143         {
00144             retval = T::_duplicate(this->dm_RemoteObject.in());
00145         }
00146         else
00147         {
00148             throw CORBA::BAD_PARAM();
00149         }
00150         return( retval._retn() );
00151     };
00152     /* XXX END HACK MODE */
00153 
00154 protected:
00155 
00156     /**
00157      * Reference to the remote object that operations will be delegated to.
00158      */
00159     T_var dm_RemoteObject;
00160     
00161 };
00162 
00163 #endif

Generated on Tue Jun 22 14:50:08 2004 for CPU Broker by doxygen 1.3.6