00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef SEMAINE_CMS_IOBASE_H
00011 #define SEMAINE_CMS_IOBASE_H
00012
00013 #include <semaine/config.h>
00014
00015 #include <cms/Connection.h>
00016 #include <cms/Session.h>
00017 #include <cms/TextMessage.h>
00018 #include <cms/BytesMessage.h>
00019 #include <cms/MapMessage.h>
00020 #include <cms/CMSException.h>
00021 #include <cms/ExceptionListener.h>
00022 #include <cms/MessageListener.h>
00023 #include <stdlib.h>
00024 #include <iostream>
00025
00026 #include <semaine/cms/event.h>
00027
00028 #include "CMSLogger.h"
00029
00030 using namespace cms;
00031
00032 namespace semaine {
00033 namespace cms {
00034
00035 class ExcListener;
00036
00038
00039
00047 class IOBase {
00048 protected:
00049 const std::string cmsUrl;
00050 const std::string cmsUser;
00051 const std::string cmsPassword;
00052 Connection * connection;
00053 Session * session;
00054 Topic * topic;
00055 bool isConnectionStarted;
00056 const CMSException * exception;
00057
00058 public:
00070 IOBase(const std::string & topicName)
00071 throw (CMSException);
00072
00073 virtual ~IOBase();
00074
00083 IOBase(const std::string & cmsUrl, const std::string & cmsUser, const std::string & cmsPassword, const std::string & topicName)
00084 throw (CMSException);
00085
00091 std::string getTopicName()
00092 throw (CMSException);
00093
00094 void startConnection()
00095 throw (CMSException);
00096
00101 std::string getCMSUrl()
00102 {
00103 return cmsUrl;
00104 }
00105
00106 Connection* getConnection()
00107 {
00108 return connection;
00109 }
00110
00111 Session* getSession()
00112 {
00113 return session;
00114 }
00115
00116 Topic* getTopic()
00117 {
00118 return topic;
00119 }
00120
00121
00122
00123 friend class ExcListener;
00124
00125 private:
00126 void initialise(const std::string & topicName) throw (CMSException);
00127 void setException(const CMSException & ex);
00128 ExcListener * excListener;
00129
00130 };
00131
00133
00134 class ExcListener : public ExceptionListener {
00135 public:
00136 ExcListener(IOBase * iobase) :
00137 iobase(iobase)
00138 {}
00139 virtual void onException(const CMSException & ex) {
00140 CMSLogger::getLog("Connection")->error(std::string("Exception Listener: "), &ex);
00141 iobase->setException(ex);
00142 }
00143 private:
00144 IOBase * iobase;
00145 };
00146
00147
00148
00149 }
00150 }
00151 #endif
00152
00153