Le 08/11/2011 11:47, Romain Beauxis a écrit :
> 2011/11/7 Martin Hamant<[email protected]>:
>>
>> Le 07/11/2011 11:57, Romain Beauxis a écrit :
>>> I am wondering something tough: could you benefit from another design
>>> of your solution?
>> Why not !
>>> Sources IDs are unique and retrievable using source.id. Thus, why not
>>> using a separate list of source's metadata_url values, indexed by
>>> source ID? Something like:
>> Do you speak about the source ID I specify at output creation ?
>>
>> output = out(id="#{stream_id}".....)
>>
>> Because if yes - as this is the same stream_id I use in robinet - the only
>> thing I would need to pass on telnet to call update_url correctly is
>>
>> update_url<stream_id>|<metadata_url>
> Correct! The only detail is that the id you pass may be rewritten if
> there is already another source registered in the system with the same
> ID. In this case, source.id(output) should return the updated ID. Of
> course, if you did the right thing, this should not happen :-)
Yes... I see what you're talking about ;)

>
>>> # The list
>>> sources_metadata_urls = ref []
>>>
>>> # Update it
>>> def update_url(source, url) =
>>>    id = source.id(s)
>>>    elem = (id, url)
>> def update_url(uri) =
>>
>>     param = string.split(separator="\|",uri)
>>     id = list.nth(param,0)
>>     url = list.nth(param,1)
>>
>>   elem = (id, url)
>>   (...)
>>
>> Would be right ?
>>
> It is my call to list.fold which is incorrect. It should be:
>      sources_metadata_urls := list.fold(f, [], !sources_metadata_urls)
Yes, this is what I guessed at the first place, but trying this showed 
that this is not all :)

I've make it work with the following code:
def update_url(uri) =

   param = string.split(separator="\|",uri)
   id = list.nth(param,0)
   url = list.nth(param,1)

   elem = (id, url)

   # Directly append if not already present
   if not list.mem_assoc(id, !sources_metadata_urls) then
     sources_metadata_urls := list.append([elem], !sources_metadata_urls)
   else
     # This is more painful..
     def f(x, cur) =
       test_id = fst(cur) # instead of fst(x)
       # Update if given element matches
       if test_id == id then
         list.append([elem], x) # instead of list.append([elem], cur)
       else
         # Otherwise, put it back
         list.append([cur], x) # instead of list.append([x], cur)
       end
     end
     sources_metadata_urls := list.fold(f, [], !sources_metadata_urls) # 
added the missing [] original value for x
   end
   print(sources_metadata_urls) # debug
   "Done!" # this is required
end


It works like expected, I'm going forward to the next step !

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users

Reply via email to