lightmelody

changeset 743:77f1dcc38add

Deprecated Connection.open now wraps new Connection.open_async
author Arc Riley <arcriley@gmail.com>
date Wed, 17 Dec 2014 00:22:00 +0000
parents d448df1b7665
children 139cf216a934
files src/Connection.gs
diffstat 1 files changed, 32 insertions(+), 27 deletions(-) [+]
line diff
     1.1 --- a/src/Connection.gs	Mon Dec 15 05:04:57 2014 +0000
     1.2 +++ b/src/Connection.gs	Wed Dec 17 00:22:00 2014 +0000
     1.3 @@ -85,7 +85,10 @@
     1.4      // Keep Alive
     1.5      _keep_alive_rate : uint
     1.6  
     1.7 -    // Deprecated Async Callbacks
     1.8 +    // Async Callbacks
     1.9 +    _open_cb : SourceFunc
    1.10 +
    1.11 +    // Deprecated non-GIO Async Callbacks
    1.12      _auth_func : ResultFunction
    1.13      _open_func : ResultFunction
    1.14  
    1.15 @@ -258,6 +261,7 @@
    1.16          return self.state >= State.AUTHENTICATED
    1.17  
    1.18  
    1.19 +    // DEPRECATED
    1.20      def open (function : ResultFunction#) : bool raises Error
    1.21          // Bail if the connection is already open
    1.22          if is_open()
    1.23 @@ -274,28 +278,41 @@
    1.24          // Store callback
    1.25          _open_func = (owned) function
    1.26  
    1.27 +        self.open_async.begin((AsyncReadyCallback) _open_callfunc)
    1.28 +
    1.29 +        return true
    1.30 +
    1.31 +
    1.32 +    def _open_callfunc(res : AsyncResult)
    1.33 +        _open_func(self, open_async.end(res))
    1.34 +
    1.35 +
    1.36 +    def async open_async () : bool raises Error
    1.37 +        // Bail if the connection is already open
    1.38 +        if is_open()
    1.39 +            /*
    1.40 +            set_error (error,
    1.41 +                       Lm.Error,
    1.42 +                       Lm.Error.CONNECTION_NOT_OPEN,
    1.43 +                       "Connection already open.")
    1.44 +            */
    1.45 +            return false
    1.46 +
    1.47 +        state = State.OPENING
    1.48 +
    1.49 +        // Store callback
    1.50 +        _open_cb = open_async.callback
    1.51 +
    1.52          // Attach message queue
    1.53          self.queue.attach(self.context)
    1.54  
    1.55          // Connect using GIO
    1.56          client : SocketClient = new SocketClient()
    1.57 -        client.connect_to_service_async.begin(server, "xmpp-client", null,
    1.58 -                                              _open_cb)
    1.59 +        yield client.connect_to_service_async(server, "xmpp-client", null)
    1.60 +
    1.61          return true
    1.62  
    1.63  
    1.64 -    def _open_cb(obj : Object?, res : GLib.AsyncResult)
    1.65 -        var client = (SocketClient) obj
    1.66 -        try
    1.67 -            _stream = client.connect_async.end(res)
    1.68 -
    1.69 -            // Successfully connected
    1.70 -            _open_func(self, true)
    1.71 -        except e : GLib.Error
    1.72 -            // Unsuccessful
    1.73 -            _open_func(self, false)
    1.74 -
    1.75 -
    1.76      def open_and_block () : bool raises Error
    1.77          client : SocketClient = new SocketClient()
    1.78          try
    1.79 @@ -311,18 +328,6 @@
    1.80          return true
    1.81  
    1.82  
    1.83 -
    1.84 -    /* TODO WIP
    1.85 -    def async open_async () : bool raises Error
    1.86 -        // Bail if the connetion is already open
    1.87 -        //if is_open()
    1.88 -        //    return false
    1.89 -
    1.90 -        client : SocketClient = new SocketClient()
    1.91 -        client.connect_to_service_async.begin(server, "xmpp-client", null)
    1.92 -    */
    1.93 -
    1.94 -
    1.95      def send (message : Message) : bool raises Error
    1.96          xml_str : string = message.node.to_string()
    1.97