Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes | Friends
dyn_link_rep Struct Reference

#include <dyn_link.hpp>

Inheritance diagram for dyn_link_rep:
Inheritance graph
[legend]
Collaboration diagram for dyn_link_rep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 dyn_link_rep (string lib, string symbol, string init, string session)
 ~dyn_link_rep ()
string start ()
void write (string s, int channel)
stringwatch (int channel)
string read (int channel)
void listen (int msecs)
void interrupt ()
void stop ()
void write_packet (string s, int channel)
bool complete_packet (int channel)
string read_packet (int channel, int timeout, bool &success)
void secure_server (string cmd)
void secure_client ()
void set_command (command _cmd)
void apply_command ()

Public Attributes

string lib
string symbol
string init
pointer routs
string session
string ret
bool alive
string secret
command feed_cmd
int ref_count

Friends

class tm_link

Detailed Description

Definition at line 23 of file dyn_link.hpp.


Constructor & Destructor Documentation

dyn_link_rep::dyn_link_rep ( string  lib,
string  symbol,
string  init,
string  session 
)

Definition at line 90 of file dyn_link.cpp.

                                                                   :
  lib (l), symbol (s), init (i), routs (NULL), session (ses)
{
  alive= false;
}

Definition at line 96 of file dyn_link.cpp.

                             {
  // FIXME: should we 'unlink' the package?
}

Member Function Documentation

void tm_link_rep::apply_command ( ) [inline, inherited]

Definition at line 64 of file tm_link.hpp.

{ if (!is_nil (feed_cmd)) feed_cmd->apply (); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tm_link_rep::complete_packet ( int  channel) [inherited]

Definition at line 52 of file tm_link.cpp.

                                         {
  return message_complete (watch (channel));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dyn_link_rep::interrupt ( ) [virtual]

Implements tm_link_rep.

Definition at line 184 of file dyn_link.cpp.

{}
void dyn_link_rep::listen ( int  msecs) [virtual]

Implements tm_link_rep.

Definition at line 183 of file dyn_link.cpp.

{ (void) msecs; }
string dyn_link_rep::read ( int  channel) [virtual]

Implements tm_link_rep.

Definition at line 174 of file dyn_link.cpp.

                               {
  if (channel == LINK_OUT) {
    string r= ret;
    ret= "";
    return r;
  }
  else return "";
}
string tm_link_rep::read_packet ( int  channel,
int  timeout,
bool &  success 
) [inherited]

Definition at line 57 of file tm_link.cpp.

                                                                 {
  success= false;
  string& r= watch (channel);
  time_t start= texmacs_time ();
  while (!message_complete (r)) {
    int n= N(r);
    if (timeout > 0) listen (timeout);
    if (N(r) == n && (texmacs_time () - start >= timeout)) return "";
  }
  if (channel == LINK_OUT && N(r) > 0 && r[0] == '!') {
    secure_server (message_receive (r));
    return "";
  }
  else {
    string back= message_receive (r);
    if (secret != "") back= secret_decode (back, secret);
    success= true;
    return back;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tm_link_rep::secure_client ( ) [inherited]

Definition at line 92 of file tm_link.cpp.

                            {
  if (secret != "") return;
  write ("!", LINK_IN);
  write_packet (rsa_my_public_key (), LINK_IN);
  bool success;
  string r= read_packet (LINK_OUT, 10000, success);
  if (!success) { stop (); return; }
  secret= rsa_decode (r, rsa_my_private_key ());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tm_link_rep::secure_server ( string  cmd) [inherited]

Definition at line 83 of file tm_link.cpp.

                                                {
  if (secret != "") return;
  string k= secret_generate ();
  string s= rsa_encode (k, client_public);
  write_packet (s, LINK_IN);
  secret= k;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tm_link_rep::set_command ( command  _cmd) [inline, inherited]

Definition at line 63 of file tm_link.hpp.

{ feed_cmd = _cmd; }
string dyn_link_rep::start ( ) [virtual]

Implements tm_link_rep.

Definition at line 111 of file dyn_link.cpp.

                     {
#ifndef __MINGW32__
  string name= lib * ":" * symbol * "-package";
  if (dyn_linked->contains (name))
    routs= dyn_linked [name];
  if (routs != NULL)
    return "continuation of#'" * lib * "'";
  if (DEBUG_AUTO)
    cout << "TeXmacs] Installing dynamic link '" << lib << "'\n";

  string message= symbol_install (lib, symbol, routs);
  if (routs != NULL) {
    dyn_linked (name)= routs;
    package_exports_1* pack= (package_exports_1*) routs;
    char* _init  = as_charp (init);
    char* _errors= NULL;
    char* _message= pack->install (&TeXmacs, _init, &_errors);
    if (_errors != NULL) {
      routs= NULL;
      ret= "Error: " * string (_errors);
    }
    else {
      ret= string (_message == NULL? ((char*) ""): _message);
      alive= true;
    }
    tm_delete_array (_init);
    return ret;
  }
  else return message;
#else
  return "Error: dynamic linking not implemented";
#endif
}

Here is the call graph for this function:

void dyn_link_rep::stop ( ) [virtual]

Implements tm_link_rep.

Definition at line 185 of file dyn_link.cpp.

{}
string & dyn_link_rep::watch ( int  channel) [virtual]

Implements tm_link_rep.

Definition at line 167 of file dyn_link.cpp.

                                {
  static string empty_string= "";
  if (channel == LINK_OUT) return ret;
  else return empty_string;
}
void dyn_link_rep::write ( string  s,
int  channel 
) [virtual]

Implements tm_link_rep.

Definition at line 146 of file dyn_link.cpp.

                                          {
#ifndef __MINGW32__
  if ((!alive) || (channel != LINK_IN)) return;
  if (routs==NULL) {
    cerr << "Library= " << lib << "\n";
    FAILED ("library not installed");
  }
  package_exports_1* pack= (package_exports_1*) routs;

  char* _session= as_charp (session);
  char* _s= as_charp (s);
  char* _errors= NULL;
  char* _r= pack->evaluate (_s, _session, &_errors);
  ret= string (_r==NULL? (_errors==NULL? ((char*) "Error"): _errors): _r);
  tm_delete_array (_s);
  tm_delete_array (_session);
  if (!is_nil (this->feed_cmd)) this->feed_cmd->apply ();
#endif
}

Here is the call graph for this function:

void tm_link_rep::write_packet ( string  s,
int  channel 
) [inherited]

Definition at line 46 of file tm_link.cpp.

                                                {
  if (secret != "") s= secret_encode (s, secret);
  write ((as_string (N (s)) * "\n") * s, channel);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class tm_link [friend, inherited]

Definition at line 66 of file tm_link.hpp.


Member Data Documentation

bool tm_link_rep::alive [inherited]

Definition at line 40 of file tm_link.hpp.

Definition at line 43 of file tm_link.hpp.

Definition at line 26 of file dyn_link.hpp.

Definition at line 24 of file dyn_link.hpp.

int abstract_struct::ref_count [inherited]

Definition at line 142 of file basic.hpp.

Definition at line 29 of file dyn_link.hpp.

Definition at line 27 of file dyn_link.hpp.

Definition at line 41 of file tm_link.hpp.

Definition at line 28 of file dyn_link.hpp.

Definition at line 25 of file dyn_link.hpp.


The documentation for this struct was generated from the following files: