/[svn]/linuxsampler/trunk/src/network/lscpevent.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/network/lscpevent.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 170 - (hide annotations) (download)
Sat Jul 3 20:08:07 2004 UTC (19 years, 10 months ago) by senkov
File size: 3953 byte(s)
* moved ToString to common
* Implemented handling of multiple connections
* Implemented guts for event subscription/unsubscription
* Illustrated event notification sending by sending MISC events
when connections are established or terminated.

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

  ViewVC Help
Powered by ViewVC