User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

obex-data-server:coding_tips [2008/07/13 16:10] (current)
Line 1: Line 1:
 +====== Coding Guide Lines ======
 +This page intends to be a place where you will find tips on how to make your code work better with obex-data-server
 +===== Python =====
 +=== Don't open so many files ===
 +Python and dbus makes greats teams, but when it regards to working with ods it sometimes can do nasty things.
 +One of this things is that as long as you have 1 object listening for signals coming from dbus this object will never be freed so then the object will still be linked in ods, leading to **huge** memory consumptions and crashes in ods because it runs out of file descriptors.
 +One of the solutions to this is quite simple (but quite hard to figure out) is to register for that matches a certain object path, and not for signals right to that object. So for example if you want to listen too all //TransferStarted// signals from //org.openobex.ServerSession// you do something like this:
 +<code python>
 +    def __transfer_started_cb(self, filename, local_path, size, path, *args):
 +        self.__sessions[path].__local_path = local_path
 +'Session: %s file: %s' % (path , local_path))
 +    def StartServer(self):
 +        ....
 +        self.bus.add_signal_receiver( 
 +                self.__transfer_started_cb,
 +                signal_name = 'TransferStarted',
 +                dbus_interface = 'org.openobex.ServerSession',
 +                path_keyword = 'path'
 +        )
 +Where //self.bus// is the dbus bus connection, and __sessions is a table that holds a reference to each one of the files path you're expecting.
 +If you want to take a look at a complete running solution you can take a look at: [[ | AIRmessage ]]
obex-data-server/coding_tips.txt ยท Last modified: 2008/07/13 16:10 (external edit)