OSC: Fix some uninitialized values.

This commit is contained in:
Jonathan Moore Liles 2012-05-03 22:57:54 -07:00
parent f279f49b1e
commit ac30a5a4e2
3 changed files with 66 additions and 41 deletions

View File

@ -48,8 +48,6 @@
#include "OSC/Endpoint.H" #include "OSC/Endpoint.H"
#include <lo/lo.h> #include <lo/lo.h>
#include "OSC/Endpoint.H"
const double STATUS_UPDATE_FREQ = 0.2f; const double STATUS_UPDATE_FREQ = 0.2f;
extern char *user_config_dir; extern char *user_config_dir;

View File

@ -56,6 +56,22 @@ namespace OSC
int Signal::next_id = 0; int Signal::next_id = 0;
Signal::Signal ( const char *path, Direction dir )
{
_direction = dir;
_path = strdup( path );
_id = ++next_id;
_value = 0.0f;
_endpoint = NULL;
_peer = NULL;
_path = 0;
_documentation = 0;
_user_data = 0;
_connection_state_callback = 0;
_connection_state_userdata = 0;
}
Signal::~Signal ( ) Signal::~Signal ( )
{ {
if ( _endpoint ) if ( _endpoint )
@ -140,7 +156,9 @@ namespace OSC
return r; return r;
} }
void void
Endpoint::error_handler(int num, const char *msg, const char *path) Endpoint::error_handler(int num, const char *msg, const char *path)
{ {
@ -149,6 +167,11 @@ namespace OSC
Endpoint::Endpoint ( ) Endpoint::Endpoint ( )
{ {
_peer_scan_complete_callback = 0;
_peer_scan_complete_userdata = 0;
_server = 0;
_name = 0;
owner = 0;
} }
int int
@ -164,7 +187,6 @@ namespace OSC
return -1; return -1;
} }
add_method( "/signal/hello", "ss", &Endpoint::osc_sig_hello, this, "" ); add_method( "/signal/hello", "ss", &Endpoint::osc_sig_hello, this, "" );
add_method( "/signal/connect", "ii", &Endpoint::osc_sig_connect, this, "" ); add_method( "/signal/connect", "ii", &Endpoint::osc_sig_connect, this, "" );
add_method( "/signal/disconnect", "ii", &Endpoint::osc_sig_disconnect, this, "" ); add_method( "/signal/disconnect", "ii", &Endpoint::osc_sig_disconnect, this, "" );
@ -183,7 +205,11 @@ namespace OSC
Endpoint::~Endpoint ( ) Endpoint::~Endpoint ( )
{ {
// lo_server_thread_free( _st ); // lo_server_thread_free( _st );
lo_server_free( _server ); if ( _server )
{
lo_server_free( _server );
_server = 0;
}
} }
OSC::Signal * OSC::Signal *
@ -248,6 +274,8 @@ namespace OSC
void void
Endpoint::hello ( const char *url ) Endpoint::hello ( const char *url )
{ {
assert( name() );
lo_address addr = lo_address_new_from_url ( url ); lo_address addr = lo_address_new_from_url ( url );
char *our_url = this->url(); char *our_url = this->url();
@ -260,6 +288,7 @@ namespace OSC
int int
Endpoint::osc_sig_hello ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ) Endpoint::osc_sig_hello ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data )
{ {
Endpoint *ep = (Endpoint*)user_data; Endpoint *ep = (Endpoint*)user_data;
const char *peer_name = &argv[0]->s; const char *peer_name = &argv[0]->s;
@ -271,7 +300,14 @@ namespace OSC
{ {
ep->scan_peer( peer_name, peer_url ); ep->scan_peer( peer_name, peer_url );
ep->hello( peer_url ); if ( ep->name() )
{
ep->hello( peer_url );
}
else
{
DMESSAGE( "Not sending hello because we don't have a name yet!" );
}
} }
return 0; return 0;

View File

@ -166,22 +166,7 @@ namespace OSC
public: public:
Signal ( const char *path, Direction dir ) Signal ( const char *path, Direction dir );
{
_direction = dir;
_path = strdup( path );
_id = ++next_id;
_value = 0.0f;
_endpoint = NULL;
_peer = NULL;
}
void connection_state_callback ( void(*_cb)(OSC::Signal *, void*), void *userdata)
{
_connection_state_callback = _cb;
_connection_state_userdata = userdata;
}
~Signal ( ); ~Signal ( );
static Signal *get_peer_signal_by_id ( Peer *p, int signal_id ); static Signal *get_peer_signal_by_id ( Peer *p, int signal_id );
@ -203,6 +188,13 @@ namespace OSC
_value = default_value; _value = default_value;
} }
void connection_state_callback ( void(*_cb)(OSC::Signal *, void*), void *userdata)
{
_connection_state_callback = _cb;
_connection_state_userdata = userdata;
}
const Parameter_Limits& parameter_limits ( void ) const { return _parameter_limits; } const Parameter_Limits& parameter_limits ( void ) const { return _parameter_limits; }
const char *path ( void ) const { return _path; } const char *path ( void ) const { return _path; }
@ -239,8 +231,21 @@ namespace OSC
class Endpoint class Endpoint
{ {
static void error_handler(int num, const char *msg, const char *path); Thread _thread;
// lo_server_thread _st;
lo_server _server;
std::list<Peer*> _peers;
std::list<Signal*> _signals;
std::list<Method*> _methods;
void (*_peer_scan_complete_callback)(void*);
void *_peer_scan_complete_userdata;
char *_name;
static void error_handler(int num, const char *msg, const char *path);
static int osc_reply ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ); static int osc_reply ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
@ -256,14 +261,7 @@ namespace OSC
void scan_peer ( const char *name, const char *url ); void scan_peer ( const char *name, const char *url );
Thread _thread; private:
// lo_server_thread _st;
lo_server _server;
std::list<Peer*> _peers;
std::list<Signal*> _signals;
std::list<Method*> _methods;
static void *osc_thread ( void *arg ); static void *osc_thread ( void *arg );
void osc_thread ( void ); void osc_thread ( void );
@ -278,25 +276,21 @@ namespace OSC
static Signal *find_target_by_peer_address ( std::list<Signal*> *l, lo_address addr ); static Signal *find_target_by_peer_address ( std::list<Signal*> *l, lo_address addr );
char *_name;
void del_signal ( Signal *signal ); void del_signal ( Signal *signal );
void send_signal_rename_notifications( Signal *s ); void send_signal_rename_notifications( Signal *s );
void (*_peer_scan_complete_callback)(void*);
void *_peer_scan_complete_userdata;
public: public:
// can be used to point back to owning object.
void *owner;
void list_peer_signals ( void (*callback) (const char *, const OSC::Signal *, void * ), void *v ); void list_peer_signals ( void (*callback) (const char *, const OSC::Signal *, void * ), void *v );
int init ( int proto, const char *port = 0 ); int init ( int proto, const char *port = 0 );
Endpoint ( ); Endpoint ( );
~Endpoint ( ); ~Endpoint ( );
bool disconnect_signal ( OSC::Signal *s, OSC::Signal *d ); bool disconnect_signal ( OSC::Signal *s, OSC::Signal *d );
bool disconnect_signal ( OSC::Signal *s, const char *peer_name, const char *signal_path ); bool disconnect_signal ( OSC::Signal *s, const char *peer_name, const char *signal_path );
@ -360,9 +354,6 @@ namespace OSC
int send ( lo_address to, const char *path, const char *v1, const char *v2, const char *v3, int v4, float v5, float v6, float v7 ); int send ( lo_address to, const char *path, const char *v1, const char *v2, const char *v3, int v4, float v5, float v6, float v7 );
// can be used to point back to owning object.
void *owner;
void peer_scan_complete_callback ( void(*_cb)(void*), void *userdata) void peer_scan_complete_callback ( void(*_cb)(void*), void *userdata)
{ {
_peer_scan_complete_callback = _cb; _peer_scan_complete_callback = _cb;