Back to index

texmacs  1.0.7.15
texmacs_client.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : texmacs_client.cpp
00004 * DESCRIPTION: clients of TeXmacs servers
00005 * COPYRIGHT  : (C) 2007  Joris van der Hoeven 
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "client_server.hpp"
00013 #include "socket_server.hpp"
00014 #include "socket_link.hpp"
00015 #include "scheme.hpp"
00016 
00017 static socket_link_rep* the_client= NULL;
00018 
00019 /******************************************************************************
00020 * Client side
00021 ******************************************************************************/
00022 
00023 void
00024 client_start (string host) {
00025   if (the_client == NULL) {
00026     (void) eval ("(use-modules (remote texmacs-client))");
00027     the_client= tm_new<socket_link_rep> (host, 6561, SOCKET_CLIENT, -1);
00028   }
00029   if (!the_client->alive)
00030     cout << "TeXmacs] Starting client... " << the_client->start () << "\n";
00031 }
00032 
00033 void
00034 client_stop () {
00035   if (the_client != NULL) {
00036     the_client->stop ();
00037     tm_delete (the_client);
00038     the_client= NULL;
00039   }
00040 }
00041 
00042 string
00043 client_read () {
00044   if (the_client == NULL || !the_client->alive) return "";
00045   if (!the_client->complete_packet (LINK_OUT)) return "";
00046   bool success;
00047   string back= the_client->read_packet (LINK_OUT, 0, success);
00048   //cout << "Server read " << back << "\n";
00049   return back;
00050 }
00051 
00052 void
00053 client_write (string s) {
00054   if (the_client == NULL || !the_client->alive) return;
00055   //cout << "Client write " << s << "\n";
00056   the_client->write_packet (s, LINK_IN);
00057 }
00058 
00059 void
00060 enter_secure_mode () {
00061   the_client->secure_client ();
00062 }