>>>>> "Stefano" == Stefano Ghirlanda <[EMAIL PROTECTED]> writes:
Stefano> Hi Jean-Marc, this is about the "idea" project. I have been
Stefano> working on a perl module, Lyx::Comm, handling communication
Stefano> with Lyx. For example:
Stefano> my $lyx = Lyx::Comm->new(client => "Idea");
Stefano> $lyx->execute("buffer-begin");
Stefano> my ($status, $data) = $lyx->execute("server-get-xy");
That's a very good idea.
Stefano> It's basic but it seems to work. But I have one trouble and
Stefano> one thought about the lyxserver. Please direct me to the
Stefano> right person if the lyxserver is not of your concern...
Well, I am certainly not the one who knows best about this
stuff. Thus, I send my answer to lyx-devel too.
Stefano> * trouble: When I greet the server with LYXSRV:Idea:hello, the
Stefano> server replies with the same string, as expected, but it does
Stefano> *not* terminate the line with newline. This is causing me
Stefano> trouble since I read linewise from .lyxpipe.out (which is
Stefano> much simpler). It is also not conformant with the outcome of
Stefano> LYXCMDs, which are terminated by newlines. This seems to
Stefano> happen in LyXServer::callback, in file LyxServer.C, line 455
Stefano> (source for 1.0.2). Compare with line 493 below, where \n is
Stefano> added to the outcome of a LYXCMD.
It seems reasonable. I'll add the missing \n.
Concerning the thought part below, I just reproduced it so that others
can comment on it. Personnally, I agree that some message should be
returned on success, but there may be some applications which rely on
the fact that nothing is returned.
So, fellow developpers, any idea?
Stefano> * thought: In the same function, I see that an INFO or ERROR
Stefano> message is output to .lyxpipe.out *if* the action specified
Stefano> yielded a non-empty return value. This means that if a
Stefano> function returning nothing succeeds, nothing is output to the
Stefano> out pipe, but when it fails an ERROR message is written. But
Stefano> there must be a way to know whether an answer is expected or
Stefano> not, otherwise one might wait forever for an answer in the
Stefano> output pipe, or ignore error message. Moreover, such
Stefano> behaviour is not apparent from the documentation about the
Stefano> server, chapter 4 of the Customization help document.
Stefano> Right now I rely on the user knowing which functions return
Stefano> data and which not, as you can see from the buffer-begin and
Stefano> server-get-xy calls above. This is simple to do in perl, via
Stefano> the wantarray function, but less transparent to the user in
Stefano> other languages. E.g. in C++ one cannot overload based on
Stefano> return type, so an additional parameter like "bool
Stefano> WantAnswer" must be used to overload two execute()
Stefano> functions. In languages without function overloading one
Stefano> would need to use two functions, e.g. execute() and
Stefano> execute_nodata() for example.
Stefano> Of course, I still can't see whether a command which usually
Stefano> returns nothing fails, because I already decided not to read
Stefano> from the output pipe...
Stefano> The simplest solution would be to just complement the
Stefano> if(!rval.empty()) condition, line 488, with an else statement
Stefano> sending an "empty" message back, INFO:client:function, when a
Stefano> function returning nothing succeeds.
Stefano> Please note that I am new at system programming (ipc, pipes)
Stefano> and so I apologise if there is a better way of doing what I'm
Stefano> trying to do.