Feature: don't autosave blist.xml upon "last_seen" changes

immerrr again immerrr at gmail.com
Mon Apr 1 03:35:09 EDT 2013


On Sat, Mar 30, 2013 at 3:08 PM, Peter Lawler <bleeter at gmail.com> wrote:
> On 30/03/13 21:24, immerrr again wrote:
>>
>> The problem is that a buddy going offline alters
>> "last_seen" node attribute
>
>
> What you'd probably want to do is modify the blist so that plugins can have
> a preference to not write blist updates to disk immediately (you could have
> it set a timer for X minutes, or account logoff, or pidgin shutdown).
>

Alright, thanks. The first thing that comes to mind is to add a
"reason" parameter to save_node callback, smth like:

    typedef enum {
       PURPLE_BLIST_NODE_INVALID_REASON = -1,

       PURPLE_BLIST_NODE_CREATE,
       PURPLE_BLIST_NODE_CHANGE_SETTING,
       PURPLE_BLIST_NODE_RENAME,
       PURPLE_BLIST_NODE_REMOVE

    } PurpleBlistNodeSaveReason;

    void
    purple_blist_save_node_with_reason(PurpleBlistNode *node,
PurpleBlistNodeSaveReason reason, void* arg);

which would be called as

    purple_blist_save_node_with_reason(node,
PURPLE_BLIST_NODE_CHANGE_SETTING, "last_seen")

Well, I'm not really sure where to find the guidelines in writing
plugins/GUIs for libpurple, so but something tells me that this might
open a pandora box of backward incompatibility (especially, ABI
incompatibility) issues when a plugin (or a GUI) is oblivious of the
new API.


So, another option is to define those "PurpleBlistNodeSaveReason"
reason & "void* arg" as a variable accessible from outside with
something like:

    PurpleBlistNodeSaveReason purple_blist_node_get_save_reason();
    void* purple_blist_node_get_save_arg();

And then do the following in blist.c where save_node is used:

    void
    purple_blist_node_set_int(PurpleBlistNode* node, const char *key, int data)
    {
        ....
        if (ops && ops->save_node) {
            purple_blist_node_set_save_reason(PURPLE_BLIST_NODE_CHANGE_SETTING);
            purple_blist_node_set_save_arg("last_seen");

            ops->save_node((PurpleBlistNode *) buddy);

            purple_blist_node_set_save_reason(PURPLE_BLIST_NODE_INVALID_REASON);
            purple_blist_node_set_save_arg((void*)0);
        }
    }

> This is to say, to get 'last_seen' to not write as much to disk, blist
> probably needs changing then the last_seen plugin needs changing to meet the
> new blist foo.

The latter solution feels much more hackish to me, but AFAIU it avoids
all sorts of ABI incompatibility and will be fine for as long as
libpurple is single-threaded by design. And it would avoid the
necessity to modify lastseen or any other plugins.

--
Cheers,
immerrr




More information about the Devel mailing list