00001 /*---------------------------------------------------------------------------- 00002 MoMu: A Mobile Music Toolkit 00003 Copyright (c) 2010 Nicholas J. Bryan, Jorge Herrera, Jieun Oh, and Ge Wang 00004 All rights reserved. 00005 http://momu.stanford.edu/toolkit/ 00006 00007 Mobile Music Research @ CCRMA 00008 Music, Computing, Design Group 00009 Stanford University 00010 http://momu.stanford.edu/ 00011 http://ccrma.stanford.edu/groups/mcd/ 00012 00013 MoMu is distributed under the following BSD style open source license: 00014 00015 Permission is hereby granted, free of charge, to any person obtaining a 00016 copy of this software and associated documentation files (the 00017 "Software"), to deal in the Software without restriction, including 00018 without limitation the rights to use, copy, modify, merge, publish, 00019 distribute, sublicense, and/or sell copies of the Software, and to 00020 permit persons to whom the Software is furnished to do so, subject to 00021 the following conditions: 00022 00023 The authors encourage users of MoMu to include this copyright notice, 00024 and to let us know that you are using MoMu. Any person wishing to 00025 distribute modifications to the Software is encouraged to send the 00026 modifications to the original authors so that they can be incorporated 00027 into the canonical version. 00028 00029 The Software is provided "as is", WITHOUT ANY WARRANTY, express or implied, 00030 including but not limited to the warranties of MERCHANTABILITY, FITNESS 00031 FOR A PARTICULAR PURPOSE and NONINFRINGEMENT. In no event shall the authors 00032 or copyright holders by liable for any claim, damages, or other liability, 00033 whether in an actino of a contract, tort or otherwise, arising from, out of 00034 or in connection with the Software or the use or other dealings in the 00035 software. 00036 -----------------------------------------------------------------------------*/ 00037 00038 /*----------------------------------------------------------------------------*/ 00049 /*----------------------------------------------------------------------------*/ 00050 00051 #ifndef __MO_NET_H__ 00052 #define __MO_NET_H__ 00053 00054 #include "mo_def.h" 00055 #include "mo_thread.h" 00056 00057 #include "UdpSocket.h" 00058 #include "OscReceivedElements.h" 00059 #include "OscPacketListener.h" 00060 #include "OscOutboundPacketStream.h" 00061 00062 #include <iostream> 00063 #include <map> 00064 00065 00066 00067 /*----------------------------------------------------------------------------*/ 00072 /*----------------------------------------------------------------------------*/ 00073 class MoNetOSCPacketListener : public osc::OscPacketListener 00074 { 00075 protected: 00077 virtual void ProcessMessage( const osc::ReceivedMessage & m, 00078 const IpEndpointName & remoteEndpoint ); 00079 }; 00080 00081 00082 /*----------------------------------------------------------------------------*/ 00087 /*----------------------------------------------------------------------------*/ 00088 class MoNetSender 00089 { 00090 // TODO: implement me 00091 }; 00092 00093 00094 /*----------------------------------------------------------------------------*/ 00102 /*----------------------------------------------------------------------------*/ 00103 typedef void ( * MoNetReceiveCallback )( osc::ReceivedMessageArgumentStream 00104 & argument_stream, 00105 void * data ); 00106 00107 00108 /*----------------------------------------------------------------------------*/ 00113 /*----------------------------------------------------------------------------*/ 00114 struct MoNetCallback 00115 { 00116 MoNetReceiveCallback callback; 00117 void * data; 00118 }; 00119 00120 00121 /*----------------------------------------------------------------------------*/ 00133 /*----------------------------------------------------------------------------*/ 00134 class MoNet 00135 { 00136 public: 00137 00139 static void addAddressCallback( 00140 const std::string pattern, 00141 const MoNetReceiveCallback & callback, 00142 void * data = NULL ); 00143 00145 static void removeAddressCallback( const std::string pattern ); 00146 00148 static void setListeningPort( long port ); 00149 00151 static long getListeningPort(); 00152 00154 static void startListening(); 00155 00157 static void stopListening(); 00158 00162 static std::map<std::string, MoNetCallback> m_pattern_callbacks; 00163 00177 static void sendMessage( 00178 const std::string &ip, 00179 uint port, 00180 const std::string &pattern_address, 00181 char types[], 00182 uint size, 00183 ... ); 00184 00185 public: 00186 00188 static std::string getMyIPaddress(); 00189 00190 public: 00192 static std::map<std::string, UdpTransmitSocket *> m_cache; 00193 00195 static void clearCache(); 00196 00197 private: 00198 // OSC listening thread 00199 static MoThread m_thread; 00200 static bool m_thread_started; 00201 // listening port 00202 static long m_listening_port; 00203 // Output buffer size 00204 static unsigned int m_output_buffer_size; 00205 00206 // converter 00207 static unsigned int stringIPtoHEX( const std::string & ip ); 00208 00209 private: 00210 // Launches the listening thread 00211 static void * cb_osc_listener( void * ); 00212 }; 00213 00214 00215 #endif