On 12/19/2016 4:24 PM, Shetty, Mandeep wrote:
>
> I think it is expected that the application remember information that 
> it wants to upon discovery callback.
>
> As to why the CSDK frees references that it hands up to a higher 
> layer, I do not know. There must have been some logical reason behind 
> that decision.
>

I'm interested to hear those reasons.


> I can suggest a hack though if you want to keep the discovery payload. 
> Just ?Steal the pointer?.
>
> Keep a copy of the pointer in your application and then assign the 
> pointer in the response struct to NULL or an empty discovery payload 
> if the code that frees discovery payload expects things to be NOT NULL.
>
> Again, this is? hacky. It?d be idiomatic to maintain state in a more 
> elegant way.
>
> *From:* iotivity-dev-bounces at lists.iotivity.org 
> [mailto:iotivity-dev-bounces at lists.iotivity.org] *On Behalf Of *Morten 
> Nielsen
> *Sent:* Sunday, December 18, 2016 7:49 AM
> *To:* iotivity-dev at lists.iotivity.org
> *Subject:* [dev] Destroying payloads
>
> I?ve noticed that the C SDK generally destroys payloads as soon as it 
> can. For instance when you pass in a payload to OCDoResource, it?s 
> destroyed at the end of the call. Or when I get a discovery payload 
> back, it?s destroyed immediately after the callback of the discovery. 
> In the latter case I might want to perform an asynchronous get of the 
> resource?s properties, but after that point the discovery payload has 
> been destroyed and I now have a dangling useless pointer (and there?s 
> no method for cloning the discovery payload as a workaround).
>
> I?m really confused why there?s a bunch of destroy methods in the 
> C-SDK, but it seems it is taking over destroying resources for me 
> before I had a chance to be done with them.
>
> Is there a way to take back control of references that I pass in, or 
> get as an output? If I create them, or get them as a result, I should 
> be in charge of their lifecycle. Without it, it makes it completely 
> unpredictable when a handle is still valid or not. Generally I would 
> want my higher-level container classes to destroy the CSDK references 
> when they go out of scope, but I have no clue if they have already 
> been destroyed by the C SDK ? it really depends on whether they have 
> been used as input to a method at some point, or was a return value 
> from a callback.
>
> Thanks
>
> /Morten
>
>
>
> _______________________________________________
> iotivity-dev mailing list
> iotivity-dev at lists.iotivity.org
> https://lists.iotivity.org/mailman/listinfo/iotivity-dev


-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.iotivity.org/pipermail/iotivity-dev/attachments/20161219/0ba27dd9/attachment.html>

Reply via email to