00001 // -*- C++ -*- 00002 00003 // =================================================================== 00004 /** 00005 * @file Service_Context.h 00006 * 00007 * $Id: Service_Context.h 80861 2008-03-07 13:48:34Z johnnyw $ 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 /// = Generic components 00072 00073 /// Insert the component into the list, making a copy of the octet 00074 /// sequence. 00075 void set_context (const IOP::ServiceContext &context); 00076 00077 /// Insert the component into the list, making a copy of the octet 00078 /// sequence. Search the list before insertion so that the 00079 /// insertion does not cause a duplicate context to be in the list. 00080 /// If the replace flag is true, update the specified context. 00081 /// Return 0 if the component was present and the replace flag 00082 /// was not set to true. 00083 int set_context (const IOP::ServiceContext &context, CORBA::Boolean replace); 00084 00085 /// Insert the component into the list, but efficiently stealing the 00086 /// contents of the octet sequence. 00087 void set_context (IOP::ServiceContext &context); 00088 00089 /// Get a copy of the context identified by <context.context_id>, return 00090 /// 0 if the component is not present. 00091 int get_context (IOP::ServiceContext &context) const; 00092 00093 /// Get a reference to a context identified by id, return 00094 /// 0 if the component is not present. 00095 int get_context (IOP::ServiceId id, const IOP::ServiceContext **context) const; 00096 00097 /// Get a copy of the Service Context corresponding to the given 00098 /// ServiceId. The caller owns the returned Service Context. 00099 /** 00100 * @return 0 If a Service Context with the given ServiceId doesn't 00101 * exist. 00102 */ 00103 int get_context (IOP::ServiceId id, IOP::ServiceContext_out context); 00104 00105 /// Set the context from the CDR stream and add that to the service 00106 /// Context list 00107 void set_context (IOP::ServiceId id, TAO_OutputCDR &cdr); 00108 00109 /// Set the context from the CDR stream and return the context back 00110 /// to the caller. *Does not* modify the underlying service context 00111 /// list. 00112 void set_context (IOP::ServiceContext &context, TAO_OutputCDR &cdr); 00113 00114 /// Is the @a id available in the underlying service context list? If 00115 /// so return true, else return false 00116 bool is_service_id (IOP::ServiceId id); 00117 00118 /// = Marshaling and demarshaling the list 00119 int encode (TAO_OutputCDR& cdr) const; 00120 int decode (TAO_InputCDR& cdr); 00121 00122 /// Return the underlying service context list 00123 IOP::ServiceContextList &service_info (void); 00124 00125 /// @note This method is only for backward comptiblity. We 00126 /// need to get this removed once RT folks have their service 00127 /// addition info done through this interface 00128 const IOP::ServiceContextList &service_info (void) const; 00129 00130 private: 00131 /// Helper methods to implement set_context() 00132 void set_context_i (const IOP::ServiceContext &context); 00133 void set_context_i (IOP::ServiceContext &context); 00134 void add_context_i (const IOP::ServiceContext &context); 00135 void add_context_i (IOP::ServiceContext &context); 00136 void set_context_i (IOP::ServiceId id, TAO_OutputCDR &cdr); 00137 void set_context_i (IOP::ServiceContext &context, TAO_OutputCDR &cdr); 00138 00139 /// Helper methods to implement get_context() 00140 int get_context_i (IOP::ServiceContext &context) const; 00141 00142 // Prevent copying 00143 TAO_Service_Context (const TAO_Service_Context &); 00144 TAO_Service_Context &operator= (const TAO_Service_Context &); 00145 00146 private: 00147 /// The ServiceContextList info. 00148 IOP::ServiceContextList service_context_; 00149 }; 00150 00151 TAO_END_VERSIONED_NAMESPACE_DECL 00152 00153 #if defined (__ACE_INLINE__) 00154 # include "tao/Service_Context.inl" 00155 #endif /* ! __ACE_INLINE__ */ 00156 00157 #include /**/ "ace/post.h" 00158 00159 #endif /* TAO_SERVICE_CONTEXT_H */