Back to index

texmacs  1.0.7.15
Classes | Functions
connection.cpp File Reference
#include "connect.hpp"
#include "socket_notifier.hpp"
#include "iterator.hpp"
#include "convert.hpp"
#include "scheme.hpp"
#include "resource.hpp"
#include "Generic/input.hpp"
#include "gui.hpp"

Go to the source code of this file.

Classes

struct  connection_rep

Functions

static tree connection_retrieve (string name, string session)
 RESOURCE (connection)
 RESOURCE_CODE (connection)
static void connection_callback (void *obj, void *info)
void connection_notify (connection con, string ch, tree t)
void connection_notify_status (connection con)
bool connection_declared (string name)
tree connection_info (string name, string session)
tree connection_handlers (string name)
string connection_start (string name, string session, bool again)
void connection_write (string name, string session, string s)
void connection_write (string name, string session, tree t)
tree connection_read (string name, string session, string channel)
void connection_interrupt (string name, string session)
void connection_stop (string name, string session)
int connection_status (string name, string session)
static connection connection_get (string name, string session)
tree connection_eval (string name, string session, tree t)
tree connection_eval (string name, string session, string s)
tree connection_cmd (string name, string session, string cmd)

Function Documentation

static void connection_callback ( void *  obj,
void *  info 
) [static]

Definition at line 61 of file connection.cpp.

                                            {
  (void) info;
  //cout << "connection callback " << obj << LF;
  connection_rep *con = (connection_rep*) obj;
  con->listen ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree connection_cmd ( string  name,
string  session,
string  cmd 
)

Definition at line 368 of file connection.cpp.

                                                         {
  // cout << "Command " << name << ", " << session << ", " << cmd << LF;
  string s= as_string (call ("format-command", name, cmd));
  tree r= connection_eval (name, session, s);
  if (is_func (r, DOCUMENT, 1)) r= r[0];
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool connection_declared ( string  name)

Definition at line 205 of file connection.cpp.

                                  {
  return as_bool (call ("connection-defined?", name));
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree connection_eval ( string  name,
string  session,
tree  t 
)

Definition at line 350 of file connection.cpp.

                                                      {
  // cout << "Evaluating " << name << ", " << session << ", " << t << LF;
  connection con= connection_get (name, session);
  if (is_nil (con)) return "";
  connection_write (name, session, t);
  return connection_retrieve (name, session);
}

Here is the call graph for this function:

tree connection_eval ( string  name,
string  session,
string  s 
)

Definition at line 359 of file connection.cpp.

                                                        {
  // cout << "Evaluating " << name << ", " << session << ", " << s << LF;
  connection con= connection_get (name, session);
  if (is_nil (con)) return "";
  connection_write (name, session, s);
  return connection_retrieve (name, session);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static connection connection_get ( string  name,
string  session 
) [static]

Definition at line 319 of file connection.cpp.

                                             {
  connection con= connection (name * "-" * session);
  if (is_nil (con)) {
    if (connection_start (name, session, true) != "ok") return con;
    con= connection (name * "-" * session);
  }
  return con;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 215 of file connection.cpp.

                                  {
  static hashmap<string,tree> handlers (tuple ());
  if (!handlers->contains (name))
    handlers (name)= stree_to_tree (call ("connection-get-handlers", name));
  return handlers[name];
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree connection_info ( string  name,
string  session 
)

Definition at line 210 of file connection.cpp.

                                              {
  return stree_to_tree (call ("connection-info", name, session));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void connection_interrupt ( string  name,
string  session 
)

Definition at line 286 of file connection.cpp.

                                                   {
  // cout << "Interrupt " << name << ", " << session << "\n";
  connection con= connection (name * "-" * session);
  if (is_nil (con)) return;
  con->interrupt ();
  con->listen ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void connection_notify ( connection  con,
string  ch,
tree  t 
)

Definition at line 156 of file connection.cpp.

                                                      {
  if (t == "") return;
  call ("connection-notify",
       object (con->name),
       object (con->session),
       object (ch),
       object (t));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void connection_notify_status ( connection  con)

Definition at line 166 of file connection.cpp.

                                          {
  int status=
    (con->status == CONNECTION_DYING? WAITING_FOR_OUTPUT: con->status);
  if (status == con->prev_status) return;
  call ("connection-notify-status",
       object (con->name),
       object (con->session),
       object (status));
  con->prev_status= status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree connection_read ( string  name,
string  session,
string  channel 
)

Definition at line 271 of file connection.cpp.

                                                              {
  // cout << "Read " << name << ", " << session << ", " << channel << "\n";
  connection con= connection (name * "-" * session);
  if (is_nil (con)) return "";
  con->read (LINK_ERR);
  tree t= con->tm_err->get (channel);
  if (t == "") {
    con->read (LINK_OUT);
    t= con->tm_in->get (channel);
  }
  // cout << "Result " << t << "\n";
  return t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static tree connection_retrieve ( string  name,
string  session 
) [static]

Definition at line 329 of file connection.cpp.

                                                  {
  // cout << "Retrieve " << name << ", " << session << "\n";
  connection con= connection (name * "-" * session);
  if (is_nil (con)) return "";
  tree doc (DOCUMENT);
  while (true) {
    con->forced_eval= true;
    perform_select ();
    con->forced_eval= false;
    tree next= connection_read (name, session);
    if (next == "");
    else if (is_document (next)) doc << A (next);
    else doc << next;
    if (con->status == WAITING_FOR_INPUT) break;
  }
  if (N(doc) == 0) return "";
  // cout << "Retrieved " << doc << "\n";
  return doc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string connection_start ( string  name,
string  session,
bool  again 
)

Definition at line 227 of file connection.cpp.

                                                           {
  // cout << "Start " << name << ", " << session << "\n";
  if (!connection_declared (name))
    return "Error: connection " * name * " has not been declared";

  connection con= connection (name * "-" * session);
  if (is_nil (con)) {
    if (DEBUG_VERBOSE)
      cout << "TeXmacs] Starting session '" << session << "'\n";
    tree t= connection_info (name, session);
    if (is_tuple (t, "pipe", 1)) {
      tm_link ln= make_pipe_link (t[1]->label);
      con= tm_new<connection_rep> (name, session, ln);
    }
    else if (is_tuple (t, "socket", 2)) {
      tm_link ln= make_socket_link (t[1]->label, as_int (t[2]->label));
      con= tm_new<connection_rep> (name, session, ln);
    }
    else if (is_tuple (t, "dynlink", 3)) {
      tm_link ln=
       make_dynamic_link (t[1]->label, t[2]->label, t[3]->label, session);
      con= tm_new<connection_rep> (name, session, ln);
    }
  }

  return con->start (again);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int connection_status ( string  name,
string  session 
)

Definition at line 304 of file connection.cpp.

                                                {
  // cout << "Status " << name << ", " << session << " -> ";
  connection con= connection (name * "-" * session);
  if ((!is_nil (con)) && (con->status == CONNECTION_DYING))
    return WAITING_FOR_OUTPUT;
  if (is_nil (con) || (!con->ln->alive)) return CONNECTION_DEAD;
  // cout << con->ln->status << "\n";
  return con->status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void connection_stop ( string  name,
string  session 
)

Definition at line 295 of file connection.cpp.

                                              {
  // cout << "Stop " << name << ", " << session << "\n";
  connection con= connection (name * "-" * session);
  if (is_nil (con)) return;
  con->stop ();
  con->listen ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void connection_write ( string  name,
string  session,
string  s 
)

Definition at line 256 of file connection.cpp.

                                                         {
  // cout << "Write " << name << ", " << session << ", " << s << "\n";
  connection con= connection (name * "-" * session);
  if (is_nil (con)) return;
  con->write (s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void connection_write ( string  name,
string  session,
tree  t 
)

Definition at line 264 of file connection.cpp.

                                                       {
  // cout << "Write " << name << ", " << session << ", " << t << "\n";
  string s= as_string (call ("plugin-serialize", name, tree_to_stree (t)));
  connection_write (name, session, s);
}

Here is the call graph for this function:

RESOURCE ( connection  )
RESOURCE_CODE ( connection  )