[AOLSERVER] OT: Embedding Tcl Interp into existing C application

2004-08-27 Thread Brett Schwarz
Hello,

Sorry for the OT, but I thought this would be the best
list to contact about this.

There is an existing app that is multi-threaded, that
I wanted to added the ability to execute Tcl code from
this app. This reminded me very much of how aolserver
works, so I was going to start digging into the
aolserver code to see how it is done.

However, before I start, I was wondering if any kind
souls out there have any helpful tips...maybe an
overview on how aolserver does this, where to start
looking in the code, and any general threading tips.

thanks,

--brett


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to [EMAIL PROTECTED] with the
body of SIGNOFF AOLSERVER in the email message. You can leave the Subject: field of 
your email blank.


Re: [AOLSERVER] OT: Embedding Tcl Interp into existing C application

2004-08-27 Thread Dossy Shiobara
On 2004.08.27, Brett Schwarz [EMAIL PROTECTED] wrote:

 However, before I start, I was wondering if any kind
 souls out there have any helpful tips...maybe an
 overview on how aolserver does this, where to start
 looking in the code, and any general threading tips.

How you go about embedding the Tcl interpreter will depend on what it'll
be used for and how.

Can you elaborate on some details about your requirements?

-- Dossy

--
Dossy Shiobara   mail: [EMAIL PROTECTED]
Panoptic Computer Network web: http://www.panoptic.com/
  He realized the fastest way to change is to laugh at your own
folly -- then you can let go and quickly move on. (p. 70)


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to [EMAIL PROTECTED] with the
body of SIGNOFF AOLSERVER in the email message. You can leave the Subject: field of 
your email blank.


Re: [AOLSERVER] OT: Embedding Tcl Interp into existing C application

2004-08-27 Thread Brett Schwarz
--- Dossy Shiobara [EMAIL PROTECTED] wrote:

 On 2004.08.27, Brett Schwarz
 [EMAIL PROTECTED] wrote:
 
  However, before I start, I was wondering if any
 kind
  souls out there have any helpful tips...maybe an
  overview on how aolserver does this, where to
 start
  looking in the code, and any general threading
 tips.

 How you go about embedding the Tcl interpreter will
 depend on what it'll
 be used for and how.

 Can you elaborate on some details about your
 requirements?


Sure, I didn't elaborate before, because I was trying
to keep the OT noise down.

Anyways, there is an open source PBX system (asterisk)
that has an programming interface that is very similar
to CGI (in fact it is called AGI). Right now, it forks
off a process everytime an AGI is called (just like
CGI). I would like to change that so that Tcl scripts
are loaded in ahead of time, and are executed in
process (no forking). Pretty much how aolserver runs
tcl procs and tcl pages.

More info for asterisk can be gotten here:
www.asterisk.org, and I actually wrote an article
about it that you can get an overview about here:
http://linuxjournal.com/article.php?sid=6769 which
gives an example of an AGI.

Hope that helps...

thanks for your time,

--brett


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to [EMAIL PROTECTED] with the
body of SIGNOFF AOLSERVER in the email message. You can leave the Subject: field of 
your email blank.


Re: [AOLSERVER] OT: Embedding Tcl Interp into existing C application

2004-08-27 Thread Andrew Piskorski
On Fri, Aug 27, 2004 at 11:11:59AM -0700, Brett Schwarz wrote:

 Sure, I didn't elaborate before, because I was trying to keep the OT
 noise down.

Actually, I think this sort of discussion, while not PRECISELY on
topic for the AOLserver list, is more than close enough for
discsussion.  In fact, I'd like to encourage it.

Your question is basically one example of, I know that AOLserver does
X really well, I'd like to understand how, so that I can do something
similar to X with a different program..  I think those sorts of
engineering design questions are likely to teach many of us something
useful.

 Anyways, there is an open source PBX system (asterisk) that has an
 programming interface that is very similar to CGI (in fact it is
 called AGI). Right now, it forks off a process everytime an AGI is
 called (just like CGI). I would like to change that so that Tcl
 scripts are loaded in ahead of time, and are executed in process (no
 forking). Pretty much how aolserver runs tcl procs and tcl pages.

You might also consider something like FastCGI.  Maybe that approach
would be easier to integrate into the Asterisk codebase than
AOLserver's in-process interpreter approach, I dunno.

Now, I've never done it, but my understanding is that anytime you want
to combine Tcl and C, your first thing to decide is which language is
in charge?  In AOLserver the C code is in charge, and that's the way
Ousterhout originally envisioned embedding Tcl.  The other way, more
popular lately, is to make Tcl in charge, and embed all your C
functionality into tclsh as new Tcl commands.

I imagine that depending on how the Asterisk code is organized, one or
both of those approaches should be feasible.  But of course, unless
the whole codebase is already organized as a library for easy
embedding into other code, the AOLserver style C is in charge way
sounds more likely.

 http://linuxjournal.com/article.php?sid=6769 which

http://www.asterisk.org/

--
Andrew Piskorski [EMAIL PROTECTED]
http://www.piskorski.com/


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to [EMAIL PROTECTED] with the
body of SIGNOFF AOLSERVER in the email message. You can leave the Subject: field of 
your email blank.


Re: [AOLSERVER] OT: Embedding Tcl Interp into existing C application

2004-08-27 Thread Dossy Shiobara
On 2004.08.27, Brett Schwarz [EMAIL PROTECTED] wrote:
 Anyways, there is an open source PBX system (asterisk) that has an
 programming interface that is very similar to CGI (in fact it is
 called AGI). Right now, it forks off a process everytime an AGI is
 called (just like CGI). I would like to change that so that Tcl
 scripts are loaded in ahead of time, and are executed in process (no
 forking). Pretty much how aolserver runs tcl procs and tcl pages.

You specifically asked about embedding Tcl in a multithreaded
application.  Is Asterix multi-threaded?  If it is, and they fork and
exec a new process for each AGI invocation, that's interesting ...

The simplest thing to do is to start by not pre-loading all the scripts
ahead of time (since there's still no multi-threaded Tcl_CloneInterp()
function, loading them ahead of time may not benefit you much).  I'd
start by simply creating a new Tcl interp. and evaluate a script,
instead of fork/exec of an external program.  This also keeps a lof of
the headaches of multi-threaded programming out of your hair.  Expose
the Asterix API to Tcl by creating Tcl commands from C.

Once you've got that working, then just tune for performance as real
measurements dictate.

A good page to learn how to start embedding Tcl in your C app. can be
found on the Tcl'ers Wiki:

How to embed Tcl in C applications
http://wiki.tcl.tk/2074

-- Dossy

--
Dossy Shiobara   mail: [EMAIL PROTECTED]
Panoptic Computer Network web: http://www.panoptic.com/
  He realized the fastest way to change is to laugh at your own
folly -- then you can let go and quickly move on. (p. 70)


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to [EMAIL PROTECTED] with the
body of SIGNOFF AOLSERVER in the email message. You can leave the Subject: field of 
your email blank.


Re: [AOLSERVER] OT: Embedding Tcl Interp into existing C application

2004-08-27 Thread Brett Schwarz
--- Andrew Piskorski [EMAIL PROTECTED] wrote:

 On Fri, Aug 27, 2004 at 11:11:59AM -0700, Brett
 Schwarz wrote:

  Sure, I didn't elaborate before, because I was
 trying to keep the OT
  noise down.

 Actually, I think this sort of discussion, while not
 PRECISELY on
 topic for the AOLserver list, is more than close
 enough for
 discsussion.  In fact, I'd like to encourage it.

 Your question is basically one example of, I know
 that AOLserver does
 X really well, I'd like to understand how, so that I
 can do something
 similar to X with a different program..  I think
 those sorts of
 engineering design questions are likely to teach
 many of us something
 useful.

  Anyways, there is an open source PBX system
 (asterisk) that has an
  programming interface that is very similar to CGI
 (in fact it is
  called AGI). Right now, it forks off a process
 everytime an AGI is
  called (just like CGI). I would like to change
 that so that Tcl
  scripts are loaded in ahead of time, and are
 executed in process (no
  forking). Pretty much how aolserver runs tcl procs
 and tcl pages.

 You might also consider something like FastCGI.
 Maybe that approach
 would be easier to integrate into the Asterisk
 codebase than
 AOLserver's in-process interpreter approach, I
 dunno.


I thought, in essense, aolserver is FastCGI. What are
the differences?

 Now, I've never done it, but my understanding is
 that anytime you want
 to combine Tcl and C, your first thing to decide is
 which language is
 in charge?  In AOLserver the C code is in charge,
 and that's the way
 Ousterhout originally envisioned embedding Tcl.  The
 other way, more
 popular lately, is to make Tcl in charge, and embed
 all your C
 functionality into tclsh as new Tcl commands.

 I imagine that depending on how the Asterisk code is
 organized, one or
 both of those approaches should be feasible.  But of
 course, unless
 the whole codebase is already organized as a library
 for easy
 embedding into other code, the AOLserver style C is
 in charge way
 sounds more likely.


By default, C is in charge, since this is an existing
C app.


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to [EMAIL PROTECTED] with the
body of SIGNOFF AOLSERVER in the email message. You can leave the Subject: field of 
your email blank.


Re: [AOLSERVER] OT: Embedding Tcl Interp into existing C application

2004-08-27 Thread Brett Schwarz
--- Dossy Shiobara [EMAIL PROTECTED] wrote:

 On 2004.08.27, Brett Schwarz
 [EMAIL PROTECTED] wrote:
  Anyways, there is an open source PBX system
 (asterisk) that has an
  programming interface that is very similar to CGI
 (in fact it is
  called AGI). Right now, it forks off a process
 everytime an AGI is
  called (just like CGI). I would like to change
 that so that Tcl
  scripts are loaded in ahead of time, and are
 executed in process (no
  forking). Pretty much how aolserver runs tcl procs
 and tcl pages.

 You specifically asked about embedding Tcl in a
 multithreaded
 application.  Is Asterix multi-threaded?  If it is,
 and they fork and
 exec a new process for each AGI invocation, that's
 interesting ...


yes, it is multi-threaded. They fork, because it is an
external program. Just think of CGI.

 The simplest thing to do is to start by not
 pre-loading all the scripts
 ahead of time (since there's still no multi-threaded
 Tcl_CloneInterp()
 function, loading them ahead of time may not benefit
 you much).  I'd

But, what is the impact of loaded them ahead of time?
I thought that's was aolserver does (i.e. the tcl
procs).

I realize that there is some performance problems with
cloning an interp, but isn't this done at startup
time, where I don't necessarily care about timing? Or
am I way off base here?

 start by simply creating a new Tcl interp. and
 evaluate a script,
 instead of fork/exec of an external program.  This
 also keeps a lof of
 the headaches of multi-threaded programming out of
 your hair.  Expose
 the Asterix API to Tcl by creating Tcl commands from
 C.


Here's one of the deals that I am clueless about
mult-threaded programming. This is how I would think
it would happen. The main thread would read that it is
a Tcl app, and so it needs to send that to the
Tcl_Interp. I would imagine that the Tcl_Interp would
be in anther thread. So, I am assuming that there is
communication between the threads. Is this similar to
how aolserver does it? If so, where would I begin to
look to see how data is passed back and forth?

 Once you've got that working, then just tune for
 performance as real
 measurements dictate.

 A good page to learn how to start embedding Tcl in
 your C app. can be
 found on the Tcl'ers Wiki:

 How to embed Tcl in C applications
 http://wiki.tcl.tk/2074


I am familiar with embedding Tcl in C, I am just
unsure how its works in a mult-threaded
environment...especially how data is passed back and
forth between the main C thread, and the thread that
has Tcl embedded.

thanks for the info...I am learning ;)

--brett


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to [EMAIL PROTECTED] with the
body of SIGNOFF AOLSERVER in the email message. You can leave the Subject: field of 
your email blank.