2 * Open Sound Control UDP server support
4 * Copyright (C) 2007-2009 Krzysztof Foltman
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <calf/osctl.h>
23 #include <calf/osctlserv.h>
25 #include <arpa/inet.h>
26 #include <sys/socket.h>
30 using namespace osctl
;
33 void osc_server::parse_message(const char *buffer
, int len
)
35 osctl::string_buffer
buf(string(buffer
, len
));
36 osc_strstream
str(buf
);
37 string address
, type_tag
;
40 // cout << "Address " << address << " type tag " << type_tag << endl << flush;
41 if (!address
.empty() && address
[0] == '/'
42 &&!type_tag
.empty() && type_tag
[0] == ',')
44 sink
->receive_osc_message(address
, type_tag
.substr(1), str
);
48 void osc_server::on_bind()
50 ioch
= g_io_channel_unix_new(socket
);
51 srcid
= g_io_add_watch(ioch
, G_IO_IN
, on_data
, this);
54 gboolean
osc_server::on_data(GIOChannel
*channel
, GIOCondition cond
, void *obj
)
56 osc_server
*self
= (osc_server
*)obj
;
58 int len
= recv(self
->socket
, buf
, 16384, 0);
63 self
->parse_message(buf
, len
);
67 // XXXKF bundles are not supported yet
73 osc_server::~osc_server()
76 g_source_remove(srcid
);