00001 /*************************************************************************** 00002 * Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider, * 00003 * Matthias Hardt, Guido Madaus * 00004 * * 00005 * Copyright (C) 2007-2008 BerLinux Solutions GbR * 00006 * Stefan Schwarzer & Guido Madaus * 00007 * * 00008 * Copyright (C) 2009-2013 BerLinux Solutions GmbH * 00009 * * 00010 * Authors: * 00011 * Stefan Schwarzer <stefan.schwarzer@diskohq.org>, * 00012 * Matthias Hardt <matthias.hardt@diskohq.org>, * 00013 * Jens Schneider <jens.schneider@diskohq.org>, * 00014 * Guido Madaus <guido.madaus@diskohq.org>, * 00015 * Patrick Helterhoff <patrick.helterhoff@diskohq.org>, * 00016 * René Bählkow <rene.baehlkow@diskohq.org> * 00017 * * 00018 * This library is free software; you can redistribute it and/or * 00019 * modify it under the terms of the GNU Lesser General Public * 00020 * License version 2.1 as published by the Free Software Foundation. * 00021 * * 00022 * This library is distributed in the hope that it will be useful, * 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00025 * Lesser General Public License for more details. * 00026 * * 00027 * You should have received a copy of the GNU Lesser General Public * 00028 * License along with this library; if not, write to the * 00029 * Free Software Foundation, Inc., * 00030 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00031 **************************************************************************/ 00032 00033 #ifndef MMSEVENT_H_ 00034 #define MMSEVENT_H_ 00035 00036 #include "mmsbase/interfaces/immseventdispatcher.h" 00037 #include <map> 00038 00039 /** 00040 * @file mmsevent.h 00041 * 00042 * Header file for MMSEvent class. 00043 * 00044 * @ingroup mmsbase 00045 */ 00046 00047 /** 00048 * Implementation of communication by using events. 00049 * 00050 * It is possible to create events by defining a heading 00051 * used to identify received events and additional parameters 00052 * by using key-value-pairs. 00053 * 00054 * @note This class implements the _IMMSEvent interface. 00055 */ 00056 class MMSEvent : public _IMMSEvent { 00057 public: 00058 /** 00059 * Constructor. 00060 * 00061 * @param heading identifier for event 00062 */ 00063 MMSEvent(string heading = "noreceiver"); 00064 00065 /** 00066 * Setter method to set heading to identify the created 00067 * event. 00068 * 00069 * @param heading identifier for event 00070 */ 00071 virtual void setHeading(string heading); 00072 00073 /** 00074 * Getter method to fetch heading to identify the event. 00075 * 00076 * @returns identifier of event 00077 */ 00078 virtual string getHeading(); 00079 00080 /** 00081 * Get additional event parameters. 00082 * 00083 * Parameters consist of key-value-pairs which are both 00084 * string objects. 00085 * 00086 * @param key key to get the value for 00087 * 00088 * @returns value for given key 00089 */ 00090 virtual string getData(string key); 00091 00092 /** 00093 * Set additional event parameters. 00094 * 00095 * Parameters consist of key-value-pairs which are both 00096 * string objects. 00097 * 00098 * @param key key to add 00099 * @param value value for given key 00100 */ 00101 virtual void setData(string key, string value); 00102 00103 /** 00104 * Clear given event parameters. 00105 * 00106 * All key-value-pairs set before are deleted. 00107 */ 00108 virtual void clear(); 00109 00110 /** 00111 * Send event. 00112 * 00113 * The event will be raised by the dispatcher set in 00114 * setDispatcher(). 00115 * 00116 * @note It is not possible to send events from inside 00117 * the method which receives events, since the 00118 * dispatcher will block. 00119 */ 00120 virtual void send(); 00121 00122 /** 00123 * Set dispatcher interface to raise events. 00124 * 00125 * @param dispatcher dispatcher interface 00126 */ 00127 void setDispatcher(IMMSEventDispatcher *dispatcher); 00128 00129 /** 00130 * Send event to given plugin. 00131 * 00132 * The event will be raised by the dispatcher set in 00133 * setDispatcher(). 00134 * 00135 * @param pluginid id of plugin to send event to 00136 * 00137 * @note It is not possible to send events from inside 00138 * the method which receives events, since the 00139 * dispatcher will block. 00140 */ 00141 void sendTo(int pluginid); 00142 00143 private: 00144 static IMMSEventDispatcher *dispatcher; /**< dispatcher interface used for raising events */ 00145 string heading; /**< identifier for event */ 00146 std::map<string,string> data; /**< additional key-value-pairs as event parameters */ 00147 }; 00148 00149 #endif /*MMSEVENT_H_*/