7f9f21d90889847665398223cf552a693bb3c640
3 Copyright (C) 2011 Grame
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France
28 #include "MessageDriven.h"
29 #include "OSCAddress.h"
30 #include "OSCFError.h"
31 #include "OSCRegexp.h"
37 static const char * kGetMsg
= "get";
39 //--------------------------------------------------------------------------
40 void MessageDriven::processMessage( const Message
* msg
)
42 const string addr
= msg
->address();
44 // create a regular expression
45 OSCRegexp
r (OSCAddress::addressFirst(addr
).c_str());
46 // and call propose with this regexp and with the dest osc address tail
47 propose (msg
, &r
, OSCAddress::addressTail (addr
));
50 // search for alias root (fixme : could be stored in a field)
51 MessageDriven
* aliasroot
= 0;
52 for (int i
=0; i
<size(); i
++) {
53 if (subnode(i
)->name() == "alias") {
54 aliasroot
= subnode(i
);
58 // if we have aliases in the tree
59 // we need to check if the message if for an alias address
61 OSCRegexp
r2 ("alias");
63 if (msg
->size() == 1) {
64 aliasroot
->propose (msg
, &r2
, addr
);
65 } else if (msg
->size() > 1) {
66 // we simulated several messages
67 for (int i
=0; i
< msg
->size(); i
++) {
68 ostringstream as
; as
<< addr
<< '/' << i
;
75 aliasroot
->propose (&m
, &r2
, a
);
82 //--------------------------------------------------------------------------
83 // the full OSC address is simply the prefix + '/' + name
84 string
MessageDriven::getOSCAddress() const
86 string
address(fOSCPrefix
);
92 //--------------------------------------------------------------------------
93 // terminal nodes should override the get method
94 void MessageDriven::get (unsigned long ipdest
) const
96 // basic get handler propagates the get call to subnodes
97 for (vector
<SMessageDriven
>::const_iterator i
= fSubNodes
.begin(); i
!= fSubNodes
.end(); i
++)
101 //--------------------------------------------------------------------------
102 bool MessageDriven::accept( const Message
* msg
)
105 // the basic accept method only checks for the 'get' message
106 if ((msg
->size() == 1) && (msg
->param(0, val
)) && (val
== kGetMsg
)) {
113 //--------------------------------------------------------------------------
114 void MessageDriven::propose( const Message
* msg
, const OSCRegexp
* r
, const std::string addrTail
)
116 if (r
->match(getName())) { // try to match the regular expression with the object name.
117 if (addrTail
.empty()) { // it matches and the tail is empty
118 accept(msg
); // then call accept()
120 else { // it matches but the tail is not empty
121 OSCRegexp
rtail (OSCAddress::addressFirst(addrTail
).c_str());
122 for (vector
<SMessageDriven
>::iterator i
= fSubNodes
.begin(); i
!= fSubNodes
.end(); i
++) {
123 // then propagate propose() to subnodes with a new regexp and a new tail
124 (*i
)->propose (msg
, &rtail
, OSCAddress::addressTail(addrTail
));