00001 // -*- C++ -*- 00002 00003 // =================================================================== 00004 /** 00005 * @file Service_Context.h 00006 * 00007 * Service_Context.h,v 1.11 2005/11/02 11:03:27 ossama Exp 00008 * 00009 * @author Balachandran Natarajan <bala@cs.wustl.edu> 00010 */ 00011 // =================================================================== 00012 00013 #ifndef TAO_SERVICE_CONTEXT_H 00014 #define TAO_SERVICE_CONTEXT_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "tao/IOPC.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00025 00026 namespace TAO 00027 { 00028 namespace CSD 00029 { 00030 class FW_Server_Request_Wrapper; 00031 } 00032 } 00033 00034 /** 00035 * @class TAO_Service_Context 00036 * 00037 * @brief Helper class for managing the service context list 00038 * information. 00039 * 00040 * This class is used to manipulate and access the service context 00041 * list that is passed around with every GIOP request/reply. The 00042 * definition of the service context list is simply a sequence of the 00043 * following structures: 00044 * typedef unsigned long ServiceId; 00045 * struct ServiceContext 00046 * { 00047 * ServiceId context_id; 00048 * sequence <octet> context_data; 00049 * }; 00050 * typedef sequence <ServiceContext> ServiceContextList; 00051 * 00052 * the real motivation behind this class is to consolidate all the 00053 * marshalling and unmarshalling information pertaining to service 00054 * context list 00055 * 00056 * @note Somewhere down the line we may want to use this class for 00057 * fast access to the info that we need from the Service Context 00058 * List. 00059 */ 00060 class TAO_Export TAO_Service_Context 00061 { 00062 public: 00063 /// Declare FW_Server_Request_Wrapper a friend 00064 /// This friendship makes the FW_Server_Request_Wrapper be able to 00065 /// clone the TAO_Service_Context data member in TAO_ServerRequest. 00066 friend class TAO::CSD::FW_Server_Request_Wrapper; 00067 00068 /// Constructor 00069 TAO_Service_Context (void); 00070 00071 00072 /// = Generic components 00073 00074 /// Insert the component into the list, making a copy of the octet 00075 /// sequence. 00076 void set_context (const IOP::ServiceContext &context); 00077 00078 /// Insert the component into the list, making a copy of the octet 00079 /// sequence. Search the list before insertion so that the 00080 /// insertion does not cause a duplicate context to be in the list. 00081 /// If the replace flag is true, update the specified context. 00082 /// Return 0 if the component was present and the replace flag 00083 /// was not set to true. 00084 int set_context (const IOP::ServiceContext &context, 00085 CORBA::Boolean replace); 00086 00087 /// Insert the component into the list, but efficiently stealing the 00088 /// contents of the octet sequence. 00089 void set_context (IOP::ServiceContext &context); 00090 00091 /// Get a copy of the context identified by <context.context_id>, return 00092 /// 0 if the component is not present. 00093 int get_context (IOP::ServiceContext &context) const; 00094 00095 /// Get a reference to a context identified by id, return 00096 /// 0 if the component is not present. 00097 int get_context (IOP::ServiceId id, const IOP::ServiceContext **context) const; 00098 00099 /// Get a copy of the Service Context corresponding to the given 00100 /// ServiceId. The caller owns the returned Service Context. 00101 /** 00102 * @return 0 If a Service Context with the given ServiceId doesn't 00103 * exist. 00104 */ 00105 int get_context (IOP::ServiceId id, IOP::ServiceContext_out context); 00106 00107 /// Set the context from the CDR stream and add that to the service 00108 /// Context list 00109 void set_context (IOP::ServiceId id, TAO_OutputCDR &cdr); 00110 00111 /// Set the context from the CDR stream and return the context back 00112 /// to the caller. *Does not* modify the underlying service context 00113 /// list. 00114 void set_context (IOP::ServiceContext &context, TAO_OutputCDR &cdr); 00115 00116 /// Is the <id> available in the underlying service context list? If 00117 /// so return 1, else return 0 00118 int is_service_id (IOP::ServiceId id); 00119 00120 /// = Marshaling and demarshaling the list 00121 int encode (TAO_OutputCDR& cdr) const; 00122 int decode (TAO_InputCDR& cdr); 00123 00124 /// Return the underlying service context list 00125 IOP::ServiceContextList &service_info (void); 00126 const IOP::ServiceContextList &service_info (void) const; 00127 00128 // @@ Note: The above method is only for backward comptiblity. We 00129 // need to get this removed once RT folks have their service 00130 // addition info done through this interface 00131 00132 private: 00133 /// Helper methods to implement set_context() 00134 void set_context_i (const IOP::ServiceContext &context); 00135 void set_context_i (IOP::ServiceContext &context); 00136 void add_context_i (const IOP::ServiceContext &context); 00137 void add_context_i (IOP::ServiceContext &context); 00138 void set_context_i (IOP::ServiceId id, TAO_OutputCDR &cdr); 00139 void set_context_i (IOP::ServiceContext &context, TAO_OutputCDR &cdr); 00140 00141 /// Helper methods to implement get_context() 00142 int get_context_i (IOP::ServiceContext &context) const; 00143 00144 // Prevent copying 00145 TAO_Service_Context (const TAO_Service_Context &); 00146 TAO_Service_Context &operator= (const TAO_Service_Context &); 00147 00148 private: 00149 /// The ServiceContextList info. 00150 IOP::ServiceContextList service_context_; 00151 }; 00152 00153 TAO_END_VERSIONED_NAMESPACE_DECL 00154 00155 #if defined (__ACE_INLINE__) 00156 # include "tao/Service_Context.inl" 00157 #endif /* ! __ACE_INLINE__ */ 00158 00159 #include /**/ "ace/post.h" 00160 00161 #endif /* TAO_SERVICE_CONTEXT_H */