On Mon, Mar 9, 2015 at 10:35 AM, Ken Giusti <kgiu...@redhat.com> wrote:

> Hi,
>
> I just noticed that the 0.9rc1 marks the
> pn_XXX_get_context()/pn_XXX_set_context() set of APIs as being deprecated.
>
> I use these apis fairly frequently as a means to map back to my
> application's context.
>
> What are they being replaced with?   I couldn't find an associated JIRA
> explaining how to upgrade my code.
>
> thanks,
>

The context API has been replaced with the attachments API. The attachments
API provides two key improvements over contexts. Firstly, you can have
multiple attachments for a given object without them interfering with each
other. Secondly, it permits you to define the type of each attachment,
thereby allowing simpler options for memory management since you can use
reference counted pointers if you wish.

The general pattern is:

    PN_HANDLE(FOO) // this is a macro that defines FOO to refer to a static
memory location guaranteed to be unique within the program

    pn_record_t *record = pn_xxx_attachments(xxx);
    pn_record_def(record, FOO, PN_VOID | PN_OBJECT);
    pn_record_set(record, FOO, value);
    void *value = pn_record_get(record, FOO);

For real use you'll probably want to wrap the get/set with accessors that
cast foo to/from a more specific type, e.g.:

    pn_foo_t *pn_xxx_get_foo(xxx);
    void pn_xxx_set_foo(xxx, pn_foo_t *foo);

I just noticed the pn_record_t API is missing doxygen. I'll add it to the
list for a doc blitz. I have a plane ride coming up soon, so hopefully will
have some time to churn out the missing doc pieces here.

--Rafael

Reply via email to