1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
12 |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
17 |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
23 |
|
24 |
/********************************************************* |
25 |
* This class helps to constuct valid events per |
26 |
* LSCP protocol specification |
27 |
* |
28 |
* It also helps LSCPServer lookup the events when |
29 |
* a client is trying to subscribe to an event |
30 |
* |
31 |
* ******************************************************/ |
32 |
|
33 |
#include "lscpevent.h" |
34 |
|
35 |
#include "../common/global_private.h" |
36 |
|
37 |
std::map<LSCPEvent::event_t, String> LSCPEvent::EventNames = std::map<LSCPEvent::event_t, String>(); |
38 |
|
39 |
LSCPEvent::LSCPEvent(String eventName) throw (Exception) { |
40 |
for (std::map<event_t, String>::iterator iter = EventNames.begin(); iter != EventNames.end(); iter++) { |
41 |
if (iter->second == eventName) { |
42 |
this->type = iter->first; |
43 |
return; |
44 |
} |
45 |
} |
46 |
throw Exception("Event does not exist"); |
47 |
} |
48 |
|
49 |
LSCPEvent::LSCPEvent(event_t eventType, int uiData) { |
50 |
this->type = eventType; |
51 |
this->storage = ToString(uiData); |
52 |
} |
53 |
|
54 |
LSCPEvent::LSCPEvent(event_t eventType, String sData) { |
55 |
this->type = eventType; |
56 |
this->storage = sData; |
57 |
} |
58 |
|
59 |
LSCPEvent::LSCPEvent(event_t eventType, int uiData1, int uiData2) { |
60 |
this->type = eventType; |
61 |
this->storage = ToString(uiData1) + " " + ToString(uiData2); |
62 |
} |
63 |
|
64 |
LSCPEvent::LSCPEvent(event_t eventType, int uiData1, int uiData2, String sData3, int uiData4, int uiData5) { |
65 |
this->type = eventType; |
66 |
this->storage = ToString(uiData1) + " " + ToString(uiData2) + " " + |
67 |
sData3 + " " + ToString(uiData4) + " " + ToString(uiData5); |
68 |
} |
69 |
|
70 |
LSCPEvent::LSCPEvent(event_t eventType, String sData, int uiData) { |
71 |
this->type = eventType; |
72 |
this->storage = sData + " " + ToString(uiData); |
73 |
} |
74 |
|
75 |
LSCPEvent::LSCPEvent(event_t eventType, String sData, double dData) { |
76 |
this->type = eventType; |
77 |
this->storage = sData + " " + ToString(dData); |
78 |
} |
79 |
|
80 |
LSCPEvent::LSCPEvent(event_t eventType, int uiData, String sData) { |
81 |
this->type = eventType; |
82 |
this->storage = ToString(uiData) + " " + sData; |
83 |
} |
84 |
|
85 |
LSCPEvent::LSCPEvent(event_t eventType, int uiData1, String sData2, int uiData3, int uiData4) { |
86 |
this->type = eventType; |
87 |
this->storage = ToString(uiData1) + " " + sData2 + " " + |
88 |
ToString(uiData3) + " " + ToString(uiData4); |
89 |
} |
90 |
|
91 |
LSCPEvent::LSCPEvent(event_t eventType, int uiData1, int uiData2, int uiData3) { |
92 |
this->type = eventType; |
93 |
this->storage = ToString(uiData1) + " " + ToString(uiData2) + " " + ToString(uiData3); |
94 |
} |
95 |
|
96 |
LSCPEvent::LSCPEvent(event_t eventType, String sData1, String sData2, String sData3) { |
97 |
this->type = eventType; |
98 |
this->storage = sData1 + " " + sData2 + " " + sData3; |
99 |
} |
100 |
|
101 |
//Produce event string |
102 |
String LSCPEvent::Produce(void) { |
103 |
String result = "NOTIFY:"; |
104 |
result += EventNames[type]; |
105 |
result += ":"; |
106 |
result += storage; |
107 |
result += "\r\n"; |
108 |
return result; |
109 |
} |
110 |
|
111 |
//This can later return handle and then we can get rid of event_t enum |
112 |
//and make events fully dynamic |
113 |
void LSCPEvent::RegisterEvent(event_t eventType, String EventName) { |
114 |
EventNames[eventType] = EventName; |
115 |
} |
116 |
|
117 |
void LSCPEvent::UnregisterEvent(event_t eventType) { |
118 |
EventNames.erase(eventType); |
119 |
} |
120 |
|
121 |
//The following static method is used to get names from types |
122 |
String LSCPEvent::Name(event_t eventType) { |
123 |
if (EventNames.count(eventType)) |
124 |
return EventNames[eventType]; |
125 |
return "UNKNOWN"; |
126 |
} |
127 |
|
128 |
std::list<LSCPEvent::event_t> LSCPEvent::List( void ) { |
129 |
std::list<event_t> result; |
130 |
for (std::map<event_t, String>::iterator iter = EventNames.begin(); iter != EventNames.end(); iter++) |
131 |
result.push_back(iter->first); |
132 |
return result; |
133 |
} |
134 |
|