~ubuntu-branches/ubuntu/saucy/texmacs/saucy-proposed

« back to all changes in this revision

Viewing changes to src/System/Link/texmacs_client.cpp

  • Committer: Package Import Robot
  • Author(s): Atsuhito KOHDA
  • Date: 2013-02-21 11:51:59 UTC
  • mfrom: (4.3.2 sid)
  • Revision ID: package-import@ubuntu.com-20130221115159-e0ejzow5o83ogzsy
Tags: 1:1.0.7.18-1
* New Upstream Release.
* Removed 05_fixRd.patch and updated 01_american.patch, 09_ipa.patch
  10_tex-files.cpp.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#include "socket_link.hpp"
15
15
#include "scheme.hpp"
16
16
 
17
 
static socket_link_rep* the_client= NULL;
 
17
typedef socket_link_rep* weak_socket_link;
 
18
static array<weak_socket_link> the_clients;
 
19
static bool clients_started= false;
18
20
 
19
21
/******************************************************************************
20
22
* Client side
21
23
******************************************************************************/
22
24
 
23
 
void
 
25
int
24
26
client_start (string host) {
25
 
  if (the_client == NULL) {
 
27
  if (!clients_started) {
26
28
    (void) eval ("(use-modules (remote texmacs-client))");
27
 
    the_client= tm_new<socket_link_rep> (host, 6561, SOCKET_CLIENT, -1);
28
 
  }
29
 
  if (!the_client->alive)
30
 
    cout << "TeXmacs] Starting client... " << the_client->start () << "\n";
 
29
    clients_started= true;
 
30
  }
 
31
  weak_socket_link client=
 
32
    tm_new<socket_link_rep> (host, 6561, SOCKET_CLIENT, -1);
 
33
  if (!client->alive)
 
34
    cout << "TeXmacs] Starting client... " << client->start () << "\n";
 
35
  if (client->alive) {
 
36
    call ("client-add", object (client->io));
 
37
    the_clients << client;
 
38
    return client->io;
 
39
  }
 
40
  else return -1;
31
41
}
32
42
 
33
43
void
34
 
client_stop () {
35
 
  if (the_client != NULL) {
36
 
    the_client->stop ();
37
 
    tm_delete (the_client);
38
 
    the_client= NULL;
39
 
  }
 
44
client_stop (int fd) {
 
45
  for (int i=0; i<N(the_clients); i++)
 
46
    if (the_clients[i]->io == fd) {
 
47
      weak_socket_link client= the_clients[i];
 
48
      client->stop ();
 
49
      tm_delete (client);
 
50
      client= NULL;
 
51
      the_clients= append (range (the_clients, 0, i),
 
52
                           range (the_clients, i+1, N(the_clients)));
 
53
    }
 
54
}
 
55
 
 
56
static weak_socket_link
 
57
find_client (int fd) {
 
58
  for (int i=0; i<N(the_clients); i++)
 
59
    if (the_clients[i]->io == fd)
 
60
      return the_clients[i];
 
61
  return NULL;
40
62
}
41
63
 
42
64
string
43
 
client_read () {
44
 
  if (the_client == NULL || !the_client->alive) return "";
45
 
  if (!the_client->complete_packet (LINK_OUT)) return "";
 
65
client_read (int fd) {
 
66
  weak_socket_link client= find_client (fd);
 
67
  if (client == NULL || !client->alive) return "";
 
68
  if (!client->complete_packet (LINK_OUT)) return "";
46
69
  bool success;
47
 
  string back= the_client->read_packet (LINK_OUT, 0, success);
 
70
  string back= client->read_packet (LINK_OUT, 0, success);
48
71
  //cout << "Server read " << back << "\n";
49
72
  return back;
50
73
}
51
74
 
52
75
void
53
 
client_write (string s) {
54
 
  if (the_client == NULL || !the_client->alive) return;
 
76
client_write (int fd, string s) {
 
77
  weak_socket_link client= find_client (fd);
 
78
  if (client == NULL || !client->alive) return;
55
79
  //cout << "Client write " << s << "\n";
56
 
  the_client->write_packet (s, LINK_IN);
 
80
  client->write_packet (s, LINK_IN);
57
81
}
58
82
 
59
83
void
60
 
enter_secure_mode () {
61
 
  the_client->secure_client ();
 
84
enter_secure_mode (int fd) {
 
85
  weak_socket_link client= find_client (fd);
 
86
  if (client == NULL || !client->alive) return;
 
87
  client->secure_client ();
62
88
}