From ac30a5a4e246894310d46d0d02baf65b4b721b44 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 3 May 2012 22:57:54 -0700 Subject: [PATCH] OSC: Fix some uninitialized values. --- mixer/src/Mixer.C | 2 -- nonlib/OSC/Endpoint.C | 42 ++++++++++++++++++++++++++--- nonlib/OSC/Endpoint.H | 63 +++++++++++++++++++------------------------ 3 files changed, 66 insertions(+), 41 deletions(-) diff --git a/mixer/src/Mixer.C b/mixer/src/Mixer.C index 7103220..1b2ec82 100644 --- a/mixer/src/Mixer.C +++ b/mixer/src/Mixer.C @@ -48,8 +48,6 @@ #include "OSC/Endpoint.H" #include -#include "OSC/Endpoint.H" - const double STATUS_UPDATE_FREQ = 0.2f; extern char *user_config_dir; diff --git a/nonlib/OSC/Endpoint.C b/nonlib/OSC/Endpoint.C index 2fc4bbd..d749184 100644 --- a/nonlib/OSC/Endpoint.C +++ b/nonlib/OSC/Endpoint.C @@ -56,6 +56,22 @@ namespace OSC 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 ( ) { if ( _endpoint ) @@ -140,7 +156,9 @@ namespace OSC return r; } + + void Endpoint::error_handler(int num, const char *msg, const char *path) { @@ -149,6 +167,11 @@ namespace OSC Endpoint::Endpoint ( ) { + _peer_scan_complete_callback = 0; + _peer_scan_complete_userdata = 0; + _server = 0; + _name = 0; + owner = 0; } int @@ -164,7 +187,6 @@ namespace OSC return -1; } - add_method( "/signal/hello", "ss", &Endpoint::osc_sig_hello, this, "" ); add_method( "/signal/connect", "ii", &Endpoint::osc_sig_connect, this, "" ); add_method( "/signal/disconnect", "ii", &Endpoint::osc_sig_disconnect, this, "" ); @@ -183,7 +205,11 @@ namespace OSC Endpoint::~Endpoint ( ) { // lo_server_thread_free( _st ); - lo_server_free( _server ); + if ( _server ) + { + lo_server_free( _server ); + _server = 0; + } } OSC::Signal * @@ -248,6 +274,8 @@ namespace OSC void Endpoint::hello ( const char *url ) { + assert( name() ); + lo_address addr = lo_address_new_from_url ( url ); char *our_url = this->url(); @@ -260,6 +288,7 @@ namespace OSC int 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; const char *peer_name = &argv[0]->s; @@ -271,7 +300,14 @@ namespace OSC { 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; diff --git a/nonlib/OSC/Endpoint.H b/nonlib/OSC/Endpoint.H index 7cb030a..3421861 100644 --- a/nonlib/OSC/Endpoint.H +++ b/nonlib/OSC/Endpoint.H @@ -166,22 +166,7 @@ namespace OSC public: - 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 ( const char *path, Direction dir ); ~Signal ( ); static Signal *get_peer_signal_by_id ( Peer *p, int signal_id ); @@ -203,6 +188,13 @@ namespace OSC _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 char *path ( void ) const { return _path; } @@ -239,8 +231,21 @@ namespace OSC 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 _peers; + std::list _signals; + std::list _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 ); @@ -256,14 +261,7 @@ namespace OSC void scan_peer ( const char *name, const char *url ); - Thread _thread; - -// lo_server_thread _st; - lo_server _server; - - std::list _peers; - std::list _signals; - std::list _methods; + private: static void *osc_thread ( void *arg ); void osc_thread ( void ); @@ -278,25 +276,21 @@ namespace OSC static Signal *find_target_by_peer_address ( std::list *l, lo_address addr ); - char *_name; - void del_signal ( Signal *signal ); void send_signal_rename_notifications( Signal *s ); - void (*_peer_scan_complete_callback)(void*); - void *_peer_scan_complete_userdata; - 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 ); int init ( int proto, const char *port = 0 ); + Endpoint ( ); ~Endpoint ( ); - - - bool disconnect_signal ( OSC::Signal *s, OSC::Signal *d ); 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 ); - // can be used to point back to owning object. - void *owner; - void peer_scan_complete_callback ( void(*_cb)(void*), void *userdata) { _peer_scan_complete_callback = _cb;