From zond at troja.ath.cx Fri Sep 7 04:22:14 2007 From: zond at troja.ath.cx (Martin Kihlgren) Date: Fri, 7 Sep 2007 10:22:14 +0200 Subject: [Ruburple-development] Ruburple - getting Buddy Icon In-Reply-To: <13d1fccd0709060835s43037642ma0ad96a1515f6de7@mail.gmail.com> References: <13d1fccd0709060835s43037642ma0ad96a1515f6de7@mail.gmail.com> Message-ID: <20070907082214.GA26798@troja.ath.cx> Ooh, it was a long time since I spent any kind of time on this project :) But I am very happy that it is useful for you! First of all, you should be aware (perhaps you already are) of all the weird shit going on in ruburple: Since libpurple isn't threadsafe at all, calling libpurple from ruby is no good, and since ruby goes completely wack if other threads than its own thread does stuff inside the ruby engine, calling ruby from libpurple is no good either. To solve that problem I send single shot events from ruby to the event engine that libpurple uses, and let libpurple modify arguments in those event handlers. Then ruby waits for the execution of that event to be complete (using a normal semaphore) and then looks at the argument for any kind of return value. For the other way around, I use a pipe that a ruby 'thread' listens to using C, and that all the event handlers in libpurple that want to communicate with ruby write to. To the pipe structs are written, and the structs contain semaphores that the ruby event listener raises after having executed the ruby call that is connected to the event. And the libpurple event handler waits until that semaphore is raised until continuing. All this is kind of clunky, but it was the easiest way I could think of handling it. As to the PurpleContact vs PurpleBuddy, if I remember correctly a PurpleContact is a struct that can contain a buddy, a group or any of the other things that can live in the pidgin contact list. And a hint: That kind of problem can occur when you dont use my clunky way of communicating between ruby and libpurple - if the pointer that contains the image object is emptied before you read it in ruby, then you may get any kind of undefined behaviour, for example a null pointer. If you copy the content immediately and dont return the ruby event handler until that is done (on return the semaphore in the struct written to the libpurple->ruby pipe is raised, and the libpurple event handler that wrote to the pipe can continue on its way, possibly freeing pointers and stuff). I hope this helped! regards, //Martin Kihlgren On Thu, Sep 06, 2007 at 11:35:11PM +0800, Kamal Fariz Mahyuddin wrote: > Hi Martin, > > I've been playing around with ruburple this past week and it's really > pleasant to use and a great project. > > Reason I'm emailing you is to request for some pointers from you in my > quest to add grabbing buddy icons from within ruburple. I'm not very > familiar with C, but I've done some small addition to ruburple_ext.c > to support Account#icon to return the StoredImage object. However, for > some reason, I am always getting null pointers for my account's own > StoredImage. > > I'd like to pick your brain to better understand how libpurple does > things - for example, buddyicon.h has > purple_buddy_icons_find_custom_icon(PurpleContact). How does a > PurpleContact relate to a PurpleBuddy? > > Thanks for your time. > > > Regards, > kamal -- ################################################################### A girl camper once had an affair With a fellow all covered with hair. When she gave him his hat She realized that She'd been had by Smokey the Bear. ###################################################################