00001 /* 00002 * SEMAINEMessage.h 00003 * semaine 00004 * 00005 * Created by Marc Schröder on 09.09.08. 00006 * Copyright 2008 DFKI GmbH. All rights reserved. 00007 * 00008 */ 00009 00010 00011 #ifndef SEMAINE_CMS_MESSAGE_SEMAINEMESSAGE_H 00012 #define SEMAINE_CMS_MESSAGE_SEMAINEMESSAGE_H 00013 00014 #include <typeinfo> 00015 00016 #include <semaine/config.h> 00017 00018 #include <semaine/cms/exceptions/MessageFormatException.h> 00019 00020 #include <cms/Message.h> 00021 #include <cms/TextMessage.h> 00022 #include <cms/BytesMessage.h> 00023 #include <cms/Destination.h> 00024 #include <cms/Topic.h> 00025 00026 using namespace cms; 00027 00028 namespace semaine { 00029 namespace cms { 00030 namespace message { 00031 00047 class SEMAINEMessage 00048 { 00049 public: 00053 static const std::string USERTIME; 00057 static const std::string DATATYPE; 00061 static const std::string SOURCE; 00065 static const std::string EVENT; 00069 static const std::string PERIOD; 00070 00074 static const std::string CONTENT_ID; 00075 00079 static const std::string CONTENT_CREATION_TIME; 00080 00084 static const std::string CONTENT_TYPE; 00085 00089 static const std::string CONTENT_TYPE_UTTERANCE; 00090 00094 static const std::string CONTENT_TYPE_LISTENERVOCALISATION; 00095 00099 static const std::string CONTENT_TYPE_VISUALONLY; 00100 00107 SEMAINEMessage(const Message * message) throw(semaine::cms::exceptions::MessageFormatException); 00108 00109 virtual ~SEMAINEMessage(); 00110 00116 long long getUsertime() throw(CMSException) 00117 { 00118 return message->getLongProperty(USERTIME); 00119 } 00120 00126 std::string getDatatype() throw(CMSException) 00127 { 00128 return message->getStringProperty(DATATYPE); 00129 } 00130 00136 std::string getSource() throw(CMSException) 00137 { 00138 return message->getStringProperty(SOURCE); 00139 } 00140 00148 bool isPeriodic() throw(CMSException) 00149 { 00150 return message->propertyExists(PERIOD); 00151 } 00152 00160 bool isEventBased() throw(CMSException) 00161 { 00162 return message->propertyExists(EVENT); 00163 } 00164 00172 std::string getEventType() throw (CMSException, semaine::cms::exceptions::MessageFormatException) 00173 { 00174 if (!message->propertyExists(EVENT)) 00175 throw semaine::cms::exceptions::MessageFormatException("Message is not event-based, cannot provide event type"); 00176 std::string eventString = message->getStringProperty(EVENT); 00177 return eventString; 00178 } 00179 00186 int getPeriod() throw (CMSException, semaine::cms::exceptions::MessageFormatException) 00187 { 00188 if (!message->propertyExists(PERIOD)) 00189 throw semaine::cms::exceptions::MessageFormatException("Message is not periodic, cannot provide period length"); 00190 return message->getIntProperty(PERIOD); 00191 } 00192 00198 std::string getContentID() throw (CMSException) 00199 { 00200 if (message->propertyExists(CONTENT_ID)) { 00201 return message->getStringProperty(CONTENT_ID); 00202 } 00203 return ""; 00204 } 00205 00213 std::string getContentType() throw (CMSException) 00214 { 00215 if (message->propertyExists(CONTENT_TYPE)) { 00216 return message->getStringProperty(CONTENT_TYPE); 00217 } 00218 return ""; 00219 } 00220 00226 long long getContentCreationTime() throw (CMSException) 00227 { 00228 if (message->propertyExists(CONTENT_CREATION_TIME)) { 00229 return message->getLongProperty(CONTENT_CREATION_TIME); 00230 } 00231 return -1; 00232 } 00233 00238 bool isTextMessage() 00239 { 00240 return dynamic_cast<const TextMessage*>(message) != NULL; 00241 } 00242 00247 bool isBytesMessage() 00248 { 00249 return dynamic_cast<const BytesMessage*>(message) != NULL; 00250 } 00251 00258 std::string getText() throw(CMSException, semaine::cms::exceptions::MessageFormatException) 00259 { 00260 const TextMessage * tm = dynamic_cast<const TextMessage*>(message); 00261 if (tm == NULL) { 00262 throw semaine::cms::exceptions::MessageFormatException(std::string("Cannot get text for a message of type ")+typeid(*message).name()); 00263 } 00264 return tm->getText(); 00265 } 00266 00267 std::string getTopicName() throw(CMSException) 00268 { 00269 const Destination * dest = message->getCMSDestination(); 00270 if (dest == NULL) return std::string("unknown"); 00271 const Topic * topic = dynamic_cast<const Topic *>(dest); 00272 if (topic == NULL) return std::string("unknown"); 00273 return topic->getTopicName(); 00274 } 00275 00280 const Message * getMessage() 00281 { 00282 return message; 00283 } 00284 00285 00286 00287 00288 protected: 00289 const Message * message; 00290 00291 private: 00299 void verifyProperties() throw(semaine::cms::exceptions::MessageFormatException); 00300 00301 00302 00303 }; 00304 00305 00306 } // namespace message 00307 } // namespace cms 00308 } // namespace semaine 00309 00310 00311 00312 #endif 00313