Menu

Asynchronous OBEX connection

Help
LHetzi
2010-03-14
2013-04-25
  • LHetzi

    LHetzi - 2010-03-14

    Hello,

    i want to create a non-blocking OBEX connection for my application Series60-Remote.
    I read on your Website "If you want the normal Cocoa asynchronous behaviour that doesn't freeze, use the LightAquaBlue framework and Apple's IOBluetooth framework through PyObjC instead"

    So I tried the following code.

    import lightblue
    class OBEXWrapper(object):
        def __init__(self):
            self.addr = lightblue._IOBluetooth.BluetoothDeviceAddress("00-1b-af-84-ff-e2")
            
            self.delegate = lightblue._obex._BBOBEXClientDelegate.alloc().initWithCallback_(self.finishedrequest)
            #lightblue._LightAquaBlue.BBBluetoothOBEXClient.setDebug_(True)
            self.connection = lightblue._LightAquaBlue.BBBluetoothOBEXClient.alloc().initWithRemoteDeviceAddress_channelID_delegate_(self.addr, 11, self.delegate)
        
        def finishedrequest(self,  error,  response):
            print "finished request",  error,  response
    obex = OBEXWrapper()
    

    But this didn't work, I get the following error:

    leowiz:~ lukas$ python test.py
    test.py:9: UninitializedDeallocWarning: leaking an uninitialized object of type BBBluetoothOBEXClient
      self.connection = lightblue._LightAquaBlue.BBBluetoothOBEXClient.alloc().initWithRemoteDeviceAddress_channelID_delegate_(self.addr, 11, self.delegate)
    Traceback (most recent call last):
      File "test.py", line 14, in <module>
        obex = OBEXWrapper()
      File "test.py", line 9, in __init__
        self.connection = lightblue._LightAquaBlue.BBBluetoothOBEXClient.alloc().initWithRemoteDeviceAddress_channelID_delegate_(self.addr, 11, self.delegate)
    ValueError: depythonifying array of 6 items, got one of 17

    Do you know what I've done wrong?
    Are there any exapmes for such an OBEX connection?

    Thanks for any help,
    Lukas Hetzenecker

     
  • blam

    blam - 2010-03-20

    Check the source code for OBEXClient in src/mac/_obex.py. It uses the BBBluetoothOBEXClient class from the LightAquaBlue framework to run an OBEX client. Whenever it starts an operation (connect, put, etc.) it calls _macutil.waituntil() which basically blocks until the client finishes the request. If you don't call _macutil.waituntil(), it won't block, and you've got yourself an asynchronous client. Of course, if you don't call _macutil.waituntil(), you'll have to start the event loop yourself through pyobjc.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.