;
t>c           @   s@   d  Z  d k Z d k l Z d k l Z d f  d     YZ d S(   s   wtMessenger.py

 author michael branton

 This script is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this script; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
N(   s
   OSCMessage(   s   wtConnections   wtMessengerc           B   s   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s\   encapsulates basic methods needed to talk to a
	wireTAP server (http://wiretap.stetson.edu/)c         C   s   t    |  _ g  |  _ |  i d  t d  |  _ |  i d  |  i d  |  i	 d  |  i
 d  |  i d  |  i d  d S(   s  This is the class constructor.  It can be used to create a
		new wtMessenger object. All default values will be set by 
		this function so it is best to call it when extending 
		from this class. Defaults to UDP, blocking, with 
		server port 4950 and a randomly selected client port.s   Falsei    iV  s   UDPs    s   TrueN(   s
   OSCMessages   selfs   messages   mySubscriptionss   setConnecteds   wtConnections   conns   setClientPorts   setServerPorts   setProtocols
   setChannels   setClearOnSends   setBlocking(   s   self(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   __init__   s     	c         G   s@   |  i |  |  i | d  |  i i   |  i d  d Sd S(   s   This function will open a connection to the specified server 
		and set the default channel. It returns 'True' on success and 'False' 
		otherwise. The server can be an IP Address or host name.i    s   TrueN(   s   selfs	   setServers   servers
   setChannels   channels   conns   creates   setConnected(   s   selfs   servers   channel(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   serverConnect2   s     c         C   sS   x |  i D] } |  i |  q
 W|  i d j o |  i i   n |  i d  d S(   s   This function will close the connection if it is open. It also 
		unsubscribes from all subscribed channels so that multiple port 
		subscriptions do not linger.s    s   FalseN(   s   selfs   mySubscriptionss   subs   unsubscribes   conns   closes   setConnected(   s   selfs   sub(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   serverDisconnect>   s     
 c         G   s   t  |  d j o |  i } n | d } | d d j o d | } n |  i i |  |  i i |  i  |  i i	 |  i i
    |  i d j o |  i   n d S(   s   This function will send a message to the connected server. 
		If channel is not explicitly set, then the default channel will be 
		used. This function will prepend "/in/" to the channel unless the 
		explicit "/" is detected" i    s   /s   /in/s   TrueN(   s   lens   channels   selfs   chans   messages
   setAddresss   conns   setHostPorts
   serverports   sends	   getBinarys   coss   clear(   s   selfs   channels   chan(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   sendJ   s     
c         G   s   |  i   t |  d j o7 |  i } t |  i  d j o |  i i |  q n< | d } |  i i |  |  i d j o |  i |  n | d d j o d | } n d | GH|  i |  d S(   s  This function is a special form of the send function. Set channel 
		to the name of a subscribe channel you wish to receive data from. The 
		specified channel will automatically be prepended with "/subscribe/" 
		so keep this in mind when setting the value. You may use an explicit channel 
		by starting the channel name with "/". If you omit channel (e.g. subscribe() )
		the current default channel will be used. i    s    s   /s   /subscribe/s   subscribing N(	   s   selfs   clears   lens   channels   chans   mySubscriptionss   appends
   setChannels   send(   s   selfs   channels   chan(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys	   subscribea   s     
	
	c         G   sm   |  i   t |  d j o |  i } n | d } | d d j o d | } n d | GH|  i |  d S(   s  This function is a special form of the send function. Set channel to the 
		name of an unsubscribe channel you wish to stop receiving data from. The 
		channel specified will automatically be prepended with "/unsubscribe/" 
		so keep this in mind when setting the value or use the explicit channel 
		notation (channel starts with a "/"). If you omit channel (e.g. unsubscribe() ),
		the default channel will be used.i    s   /s   /unsubscribe/s   unsubscribing N(   s   selfs   clears   lens   channels   chans   send(   s   selfs   channels   chan(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   unsubscribe|   s     

	c         G   s%   x | D] } |  i i |  q Wd S(   sV   This function will add a single value or an array of values to 
		the current message.N(   s   datas   datums   selfs   messages   append(   s   selfs   datas   datum(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   add   s      c         G   s8   |  i d  |  i |  |  i |  |  i d  d S(   s6   This function will create a new channel on the server.s   adds	   /channelsN(   s   selfs   adds   channels   descriptions   send(   s   selfs   channels   description(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys
   addChannel   s
     c         C   s+   |  i d  |  i |  |  i d  d S(   s4   This function will remove a channel from the server.s   removes	   /channelsN(   s   selfs   adds   channels   send(   s   selfs   channel(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   removeChannel   s     c         C   s   |  i i   d S(   s   This function will clear the current message. This function is 
		automatically called after a send when the clear on send flag is set 
		to true.N(   s   selfs   messages	   clearData(   s   self(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   clear   s     c         C   sg   d } |  i   d j oF |  i i   \ } } x$ t i |  D] } | i |  q> Wd } n | Sd S(   s   This function is used to receive data from a wireTAP server. The 
		function will save a wtData object by reference into the received argument 
		whether data was received or not.s   Falses   TrueN(   s   rcs   selfs   isConnecteds   conns   receives   datas   addresss   OSCs	   decodeOSCs   datums   receiveds   append(   s   selfs   receiveds   rcs   datums   addresss   data(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   receive   s      
c         C   s    | |  _  |  i i |  i   d S(   s   privateN(   s   servers   selfs   conns   setHost(   s   selfs   server(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys	   setServer   s     	c         C   s   | |  _  d S(   s+   This function will set the default channel.N(   s   channels   self(   s   selfs   channel(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys
   setChannel   s     c         C   s    | |  _  |  i i |  i   d S(   s:   This function will set the protocol used by serverConnect.N(   s   protocols   selfs   conns   setProtocol(   s   selfs   protocol(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   setProtocol   s     	c         C   s4   | |  _ |  i d j o |  i i |  i  n d S(   s6   This function will set the port used by serverConnect.s    N(   s   ports   selfs
   serverports   conns   setHostPort(   s   selfs   port(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   setServerPort   s     	c         C   s    | |  _ |  i i |  i  d S(   sS   This function will set the port used by the messenger object 
		to receive data on.N(   s   ports   selfs
   clientports   conns   setClientPort(   s   selfs   port(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   setClientPort   s     	c         C   s/   | d j o |  i i    n |  i i   d S(   s\   This function will set the blocking mode used when receiving data 
		from a wireTAP server. s   TrueN(   s   blocks   selfs   conns   nonblock(   s   selfs   block(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   setBlocking   s     c         C   s   | |  _ d S(   s   This function will set the clear on send flag. When set to true, 
		the send function will automatically clear the current message after 
		each call. N(   s   clears   selfs   cos(   s   selfs   clear(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   setClearOnSend   s     c         C   s   | |  _ d S(   s   privateN(   s   states   selfs	   connected(   s   selfs   state(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   setConnected   s     c         C   s   |  i Sd S(   s@   This function returns 'True' if connected and 'False' otherwise.N(   s   selfs	   connected(   s   self(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   isConnected   s     (   s   __name__s
   __module__s   __doc__s   __init__s   serverConnects   serverDisconnects   sends	   subscribes   unsubscribes   adds
   addChannels   removeChannels   clears   receives	   setServers
   setChannels   setProtocols   setServerPorts   setClientPorts   setBlockings   setClearOnSends   setConnecteds   isConnected(    (    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   wtMessenger   s*    															
		
		(   s   __doc__s   OSCs
   OSCMessages   wtConnections   wtMessenger(   s   OSCs
   OSCMessages   wtConnections   wtMessenger(    (    s2   /home/delire/devel/python/pyKit-OSC/wtMessenger.pys   ?   s   	