Back to index

texmacs  1.0.7.15
texmacs_server.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : texmacs_server.cpp
00004 * DESCRIPTION: 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 "tm_link.hpp"
00013 #include "client_server.hpp"
00014 #include "socket_server.hpp"
00015 #include "scheme.hpp"
00016 
00017 static socket_server_rep* the_server= NULL;
00018 
00019 /******************************************************************************
00020 * Server side
00021 ******************************************************************************/
00022 
00023 void
00024 server_start () {
00025   if (the_server == NULL) {
00026     (void) eval ("(use-modules (remote texmacs-server))");
00027     the_server= tm_new<socket_server_rep> (6561);
00028   }
00029   if (!the_server->alive)
00030     cout << "TeXmacs] Starting server... " << the_server->start () << "\n";
00031 }
00032 
00033 void
00034 server_stop () {
00035   if (the_server != NULL) {
00036     tm_delete (the_server);
00037     the_server= NULL;
00038   }
00039 }
00040 
00041 string
00042 server_read (int fd) {
00043   tm_link ln= find_socket_link (fd);
00044   if (is_nil (ln)) return "";
00045   if (!ln->complete_packet (LINK_OUT)) return "";
00046   bool success;
00047   string back= ln->read_packet (LINK_OUT, 0, success);
00048   //cout << "Server read " << back << "\n";
00049   return back;
00050 }
00051 
00052 void
00053 server_write (int fd, string s) {
00054   tm_link ln= find_socket_link (fd);
00055   if (is_nil (ln)) return;
00056   //cout << "Server write " << s << "\n";
00057   ln->write_packet (s, LINK_IN);
00058 }