On 6/30/07, Chachereau Nicolas <[EMAIL PROTECTED]> wrote:
The more I think of it, the more I'm convinced breaking backward
compatibility and going for sockets would be worth it. But I'm not
the only one to decide here :)

Here's my first stab at a new revamped Director interface for GTK:

http://mysite.mweb.co.za/residents/sdonovan/DirectorExtension.zip

It's still backwards-compatible enough for scitePM to still work. But
(1) SciTE is now always listening (2) if ipc.scite.name doesn't exist,
then it makes up a pipe name of the form /tmp/SciTE.<pid>.in (3) there
is a new command 'register:' which causes SciTE to make a new
send/notify pipe of the form /tmp/SciTE.<pid>.<count>.out. (4) the
'correspondent' field of a command has been implemented (5) cleans up
any pipes it creates (this requires the gtk_main_quit patch so that
DirectorExtension::Finalise() is called)

It is now possible for multiple SciTE instances to each talk to
multiple extensions!

The GTK director interface is not well documented so a few examples
are useful. This demo requires two open terminal windows: first,
create a pipe which will be used to send commands to SciTE:
$ mkfifo /tmp/out

and run SciTE, setting the pipe properties on the command line:
$ SciTE -ipc.scite.name=/tmp/in -ipc.director.name=/tmp/out&

(Note: /tmp/in must not exist - let SciTE create it!)

In one terminal you can then receive SciTE's notifications:
$ cat /tmp/out
opened:/home/steve/scite-gdb/scite_lua/debugger.lua
opened:/home/steve/scite-gdb/scite_lua/lfs.lua
opened:/home/steve/scite174/scite/gtk/DirectorExtension.cxx
switched:/home/steve/scite-gdb/scite_lua/debugger.lua

In the other terminal send a command to SciTE's request pipe:

$ echo "open:/home/steve/scite174/scite/gtk/makefile" > /tmp/in

and you will get this notification appearing in the first terminal:

opened:/home/steve/scite174/scite/gtk/makefile

On closing SciTE, you will get:
closing:

and the pipe is closed.

It's actually easier to use this interface than under Win32, since
then you will have to create a window to receive WM_COPYDATA messages,
and find out the SciTE instance's window handle by iterating over all
top-level windows and using GetClassName(). This simple pipe-based
scheme can be used by any language that can read and write regular
files. But, it is limited to a single SciTE instance speaking to a
single director program. (Other programs can always write commands to
/tmp/in, but they cannot receive notifications).

With the new director interface, it is not necessary to specify
ipc.scite.name and ipc.director.name; SciTE will always create a
listener request pipe using its pid. After executing SciTE (_without_
setting the ipc properties) this pipe appears in /tmp and will be
called something like /tmp/SciTE.25340.in. This pipe will be
automatically removed when SciTE dies. To get a notify pipe back from
SciTE, there is a new command 'register:':

$ echo "register:" > /tmp/SciTE.25340.in
$ ls /tmp/SciTE*
/tmp/SciTE.25340.1.out
/tmp/SciTE.25340.in     /tmp/SciTE.register
$ cat /tmp/SciTE.register
/tmp/SciTE.25340.1.out

After the commmand, a new pipe appears in /tmp, made using the pid as
before and a count. This name is written to the temporary file
/tmp/SciTE.register.

Here is a bash script which gets a unique notification pipe and listens to it:

for i in /tmp/SciTE.*.in; do
       infile=$i
done
echo $infile
echo "register:" > $infile
sleep 0.1
outfile=$(cat /tmp/SciTE.register)
cat $outfile

It will pick up the last SciTE instance, ask it for a notify pipe,
wait a little bit (100ms) and extract the notify pipe name from the
temporary file. You can then run this script in a number of terminals,
and they will all receive notifications from the SciTE instance that
was discovered. After closing SciTE, all the request and notify pipes
will be removed.

The wait is necessary because we are doing an asynchronous request,
and need to give SciTE an opportunity to actually read and process
that request. (In C, the function nanosleep() can be used to wait for
times less than a second) When preparing commands, remember to
slashify them if necessary. Slashification allows you to pass
line-feeds in the message with C-style escapes, etc (See Slash() in
SciTEBase.cxx:1275)

The correspondent feature allows any requesting program to receive
some expected answer using a specific named pipe. For instance, the
askpropery command will cause SciTE to send the the value of property
back. For example:

Do this in one terminal
$ mkfifo /tmp/special
$ cat /tmp/special

The cat will block. Execute this SciTE command in another terminal:
$ echo ":/tmp/special:askproperty:current.pid" > /tmp/in

and the last cat will print out the return value and close:
macro:stringinfo:26018.

If a command begins with a colon, then the first part is a return
address, which in this case is a complete filepath. If you had just
entered:
$ echo "askproperty:current.pid" > /tmp/in

then the answer would appear in /tmp/out as before.

steve d.
_______________________________________________
Scite-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scite-interest

Reply via email to