Re: [eclipse-clp-users] ECLiPSe - C/C++ interaction

From: Yngwie <yngwie_at_...164...>
Date: Fri, 13 Feb 2009 10:38:46 +0100
Joachim Schimpf wrote:
> Yngwie wrote:
>   
>> Giuseppe Di Guglielmo wrote:
>>     
>>> Dear all,
>>> I am developing a C/C++ module which has to interact with ECLiPSe. 
>>>
>>> A first solution is to look at "Embedding and Interfacing Manual", but I'd
>>> like to open something like a pipe or a socket versus ECLiPSe to directly
>>> write my predicates in Prolog and submit them to ECLiPSe. Moreover I have to
>>> retrieve the results from ECLiPSe to C/C++. How can do it? Does exist any
>>> example?
>>>
>>> C/C++ module ---> communication channel ---> ECLiPSe
>>>        ^               Prolog                    |
>>>        |-------- communication channel <---------|                    
>>>
>>> Best regards,
>>> Giuseppe
>>>
>>>   
>>>       
>> Hi Giuseppe,
>> I realized something like that in a web application context in PHP.
>> Even if the platform is different, I hope my experience could help you somehow.
>> I used sockets as communication channel and EXDR (described in ECLiPSe
>> Embedding and Interfacing Manual) as a language for representing terms;
>> a formal grammar for EXDR is reported in ECLiPSe manual and is an LL(1) grammar,
>> so it's quite easy to parse.
>>
>> For the communication part, initially I implemented the remote interface protocol
>> described in manual, but it was not too suited for my application needs
>> (i had to issue a Prolog goal nearly for each http request from client side,
>> and so my communication was not session oriented, but for you it could not be the same).
>> After asking on this mailing list, I dropped this way and implemented a simpler
>> model where the Prolog side is put in the classic iterative server accept loop, and
>> handles one request a time (for now it's ok for me).
>>
>> What I've done is write an EXDR parser/generator
>> for my application platform (PHP in my case), and write a socket server
>> in ECLiPSe to handle requests in a loop like this:
>>
>> listen :-
>> 	new_socket_server(Socket, localhost/<port>, <backlog queue size>), accept_loop(Socket).
>>
>> accept_loop(Socket) :-
>> 	accept(Socket, localhost/_, ConSocket),
>> 	read_exdr(ConSocket, Goal), Goal, write_exdr(ConSocket, Goal),
>> 	close(ConSocket),
>> 	accept_loop(Socket).
>>
>>
>> When a client completes the TCP handshaking, the Prolog server accepts the connection and
>> waits for a term in EXDR format; executes goal G, writes the instantiated goal out to
>> the connection socket and close the connection.
>>
>> This is only an example and I hope it could be useful to you.
>>
>> Best regards,
>> Andrea Montemaggio
>>     
>
>
> I would agree that for many applications Andrea's suggestion is a very good one.
>
> In particular, when talking to ECLiPSe from a foreign language over I/O channels
> like sockets, EXDR is the format you should use.  It is much easier to read/write
> than ECLiPSe source syntax, and much easier (and more compact, efficient, etc)
> than going through something like XML.  It is described here:
> http://eclipse-clp.org/doc/embedding/embroot051.html
>
> Andrea, would you be willing to share your PHP code, in particular for the
> EXDR conversions?
>
>
> -- Joachim
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>   
Hi Joachim,
sure, I'm very happy to share my PHP code to deal with EXDR.
I need just to do a little refactoring and commenting, then it will be ready.
Which way you suggest to share the code? A Sourceforge project may be?

Regards,
Andrea
Received on Fri Feb 13 2009 - 09:38:43 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 22 2024 - 18:13:20 CET