00001 #ifndef loggingClient_H 00002 #define loggingClient_H 00003 00004 /******************************************************************************* 00005 * ALMA - Atacama Large Millimiter Array 00006 * (c) European Southern Observatory, 2002 00007 * Copyright by ESO (in the framework of the ALMA collaboration) 00008 * and Cosylab 2002, All rights reserved 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 * 00024 * "@(#) $Id: loggingClient.h,v 1.44 2008/09/29 08:36:42 cparedes Exp $" 00025 * 00026 * who when what 00027 * -------- ---------- ---------------------------------------------- 00028 * msekoran 2001-07-12 created 00029 */ 00030 00031 #ifndef __cplusplus 00032 #error This is a C++ include file and cannot be used from plain C 00033 #endif 00034 00035 #include <string> 00036 00037 #include <acsutil.h> 00038 00039 #include <orbsvcs/CosNamingC.h> 00040 00041 #include <orbsvcs/CosNotifyChannelAdminS.h> 00042 #include <orbsvcs/CosNotifyCommC.h> 00043 00044 #include "logging_idlC.h" 00045 00046 #define LOG_BIN_TYPE 0 00047 #define LOG_XML_TYPE 1 00048 // The syslog facility to use while logging messages throwgh the 00049 // kernel logger 00050 // Its value depends on the running ACS_INSTANCE 00051 // For instance 0-4 we use LOG_LOCAL0 to LOG_LOCAL4 00052 // Messages for all the other instances are written in LOG_LOCAL5 00053 // 00054 // All the messages are logged at level LOG_INFO 00055 int syslogFacility; 00056 00057 // Return the syslog facility depending on the running ACS instance 00058 int getSyslogFacility(); 00059 00060 // If true the output is redirected to the syslog 00061 bool toSyslog; 00062 00063 // The name of the channel to connect to 00064 std::string channelName; 00065 00066 FILE * outputFile; 00067 std::string fileName; 00068 bool toFile=false; 00069 00070 // Read the command line params into local variables 00071 void getParams(int argc, char *argv []); 00072 00073 // Prints the usage message on the stdout 00074 void printUsage(const char* prgName); 00075 00076 // Write a message to the kernel log 00077 void writeSyslogMsg(const char* msg); 00078 00079 class ACSStructuredPushConsumer; 00080 00081 class Subscribe 00082 { 00083 // = TITLE 00084 // Subscribe 00085 // = DESCRIPTION 00086 // Shows how consumers subscribe for events. 00087 00088 public: 00089 // = Initialization and Termination 00090 Subscribe (void); 00091 ~Subscribe (); 00092 00093 void init (int argc, char *argv [], std::string channel); 00094 // Init the Client. 00095 00096 void run (); 00097 // Run the demo. 00098 00099 void shutdown (); 00100 // Shutdown the logging client. 00101 00102 protected: 00103 void init_ORB (int argc, char *argv []); 00104 // Initializes the ORB. 00105 00106 void resolve_naming_service (); 00107 // Try to get hold of a running naming service. 00108 00109 void resolve_notify_channel (const char * channel_name); 00110 // Try to resolve the Notify Channel from the Naming service. 00111 00112 void create_consumeradmin (); 00113 // Create the Consumer Admin. 00114 00115 void create_consumers (); 00116 // Create and initialize the consumers. 00117 00118 void setup_events (); 00119 // Setup events 00120 00121 void teardown_events(); 00122 // Tear down (remove) events 00123 00124 // = Data Members 00125 PortableServer::POA_var root_poa_; 00126 // Reference to the root poa. 00127 00128 CORBA::ORB_var orb_; 00129 // The ORB that we use. 00130 00131 CosNaming::NamingContext_var naming_context_; 00132 // Handle to the name service. 00133 00134 CosNotifyChannelAdmin::EventChannel_var ec_; 00135 // The one channel that we create using the factory. 00136 00137 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop_; 00138 // The group operator between admin-proxy's. 00139 00140 CosNotification::QoSProperties initial_qos_; 00141 // Initial qos specified to the factory when creating the EC. 00142 00143 CosNotification::AdminProperties initial_admin_; 00144 // Initial admin props specified to the factory when creating the EC. 00145 00146 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin_; 00147 // The consumer admin used by consumers. 00148 00149 ACSStructuredPushConsumer* consumer_; 00150 // The consumer 00151 }; 00152 00153 /*****************************************************************/ 00154 00155 class ACSStructuredPushConsumer : public POA_CosNotifyComm::StructuredPushConsumer, 00156 public PortableServer::RefCountServantBase 00157 { 00158 // = TITLE 00159 // ACSStructuredPushConsumer 00160 // 00161 // = DESCRIPTION 00162 // Structured Push Consumer 00163 // 00164 00165 public: 00166 // = Initialization and Termination code 00167 ACSStructuredPushConsumer (Subscribe* subscribe); 00168 // Constructor. 00169 00170 void connect (CosNotifyChannelAdmin::ConsumerAdmin_ptr consumer_admin); 00171 // Connect the Consumer to the EventChannel. 00172 // Creates a new proxy supplier and connects to it. 00173 00174 virtual void disconnect (); 00175 // Disconnect from the supplier. 00176 00177 CosNotifyChannelAdmin::StructuredProxyPushSupplier_ptr get_proxy_supplier (void); 00178 // Accessor for the Proxy that we're connected to. 00179 00180 protected: 00181 // = Data members 00182 CosNotifyChannelAdmin::StructuredProxyPushSupplier_var proxy_supplier_; 00183 // The proxy that we are connected to. 00184 00185 CosNotifyChannelAdmin::ProxyID proxy_supplier_id_; 00186 // The proxy_supplier id. 00187 00188 Subscribe* subscribe_; 00189 // callback <done> 00190 00191 00192 // = Methods 00193 virtual ~ACSStructuredPushConsumer (void); 00194 // Destructor 00195 00196 /* 00197 * = NotifyPublish method 00198 * \throw CosNotifyComm::InvalidEventType 00199 */ 00200 virtual void offer_change(const CosNotification::EventTypeSeq & added, 00201 const CosNotification::EventTypeSeq & removed); 00202 00203 /* 00204 * = StructuredPushSupplier methods 00205 * \throw CosEventComm::Disconnected 00206 */ 00207 virtual void push_structured_event (const CosNotification::StructuredEvent & notification); 00208 00209 virtual void disconnect_structured_push_consumer (); 00210 00211 bool m_logBin; 00212 static ACE_TCHAR* m_LogEntryTypeName[]; 00213 }; 00214 00215 #endif /* loggingClient_H */ 00216