11
11
* CONNECTION_DEAD (usually) or CONNECTION_DYING (if we are still
12
12
* waiting for some residual output from the plugin).
13
13
*******************************************************************************
14
* This software falls under the GNU general public license and comes WITHOUT
15
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
16
* If you don't have this file, write to the Free Software Foundation, Inc.,
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
* This software falls under the GNU general public license version 3 or later.
15
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
16
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
18
17
******************************************************************************/
20
19
#include "connect.hpp"
38
37
string session; // name of the session
39
38
tm_link ln; // the underlying link
40
39
int status; // status of the connection
40
int prev_status; // last notified status
41
41
texmacs_input tm_in; // texmacs input handler for data from child
42
42
texmacs_input tm_err; // texmacs input handler for errors from child
58
58
connection_rep::connection_rep (string name2, string session2, tm_link ln2):
59
59
rep<connection> (name2 * "-" * session2),
60
name (name2), session (session2), ln (ln2), status (CONNECTION_DEAD),
60
name (name2), session (session2), ln (ln2),
61
status (CONNECTION_DEAD), prev_status (CONNECTION_DEAD),
61
62
tm_in ("output"), tm_err ("error") {}
139
140
******************************************************************************/
143
connection_notify (connection con, string ch, tree t) {
145
call ("connection-notify",
147
object (con->session),
153
connection_notify_status (connection con) {
155
(con->status == CONNECTION_DYING? WAITING_FOR_OUTPUT: con->status);
156
if (status == con->prev_status) return;
157
call ("connection-notify-status",
159
object (con->session),
161
con->prev_status= status;
142
165
listen_to_connections () {
143
166
iterator<string> it= iterate (connection::instances);
144
167
while (it->busy()) {
145
168
string name= it->next ();
146
169
connection con (name);
147
if ((con->status == WAITING_FOR_INPUT) ||
148
(con->status == WAITING_FOR_OUTPUT))
150
tree t= connection_handlers (con->name);
152
if (n>0) con->read (LINK_ERR);
153
for (i=0; i<n; i++) {
154
tree doc= con->tm_err->get (t[i][0]->label);
155
if (doc != "") call (t[i][1]->label, doc);
170
connection_notify_status (con);
171
if (con->status != CONNECTION_DEAD) {
172
con->read (LINK_ERR);
173
connection_notify (con, "error", con->tm_err->get ("error"));
174
con->read (LINK_OUT);
175
connection_notify (con, "output", con->tm_in->get ("output"));
176
connection_notify (con, "prompt", con->tm_in->get ("prompt"));
177
connection_notify (con, "input", con->tm_in->get ("input"));
178
tree t= connection_handlers (con->name);
180
for (i=0; i<n; i++) {
181
tree doc= con->tm_in->get (t[i][0]->label);
182
if (doc != "") call (t[i][1]->label, doc);
183
doc= con->tm_err->get (t[i][0]->label);
184
if (doc != "") call (t[i][1]->label, doc);
187
connection_notify_status (con);
188
218
connection_start (string name, string session, bool again) {
189
// cout << "Start " << name << ", " << session << ", " << again << "\n";
219
// cout << "Start " << name << ", " << session << "\n";
190
220
if (!connection_declared (name))
191
221
return "Error: connection " * name * " has not been declared";
197
227
tree t= connection_info (name, session);
198
228
if (is_tuple (t, "pipe", 1)) {
199
229
tm_link ln= make_pipe_link (t[1]->label);
200
con= new connection_rep (name, session, ln);
230
con= tm_new<connection_rep> (name, session, ln);
202
232
else if (is_tuple (t, "socket", 2)) {
203
233
tm_link ln= make_socket_link (t[1]->label, as_int (t[2]->label));
204
con= new connection_rep (name, session, ln);
234
con= tm_new<connection_rep> (name, session, ln);
206
236
else if (is_tuple (t, "dynlink", 3)) {
208
238
make_dynamic_link (t[1]->label, t[2]->label, t[3]->label, session);
209
con= new connection_rep (name, session, ln);
239
con= tm_new<connection_rep> (name, session, ln);