chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / keydis.c
1 /*
2  * keydis.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] = "$Id$";
10
11 /*
12  * $Log$
13  * Revision 1.3  2008/02/15 23:52:12  james
14  * *** empty log message ***
15  *
16  * Revision 1.2  2008/02/15 03:32:07  james
17  * *** empty log message ***
18  *
19  * Revision 1.1  2008/02/14 02:46:44  james
20  * *** empty log message ***
21  *
22  * Revision 1.1  2008/02/14 01:55:57  james
23  * *** empty log message ***
24  *
25  */
26
27
28 #include "project.h"
29
30 #define CMD_BUFLEN      128
31
32 typedef struct
33 {
34   KEYDIS_SIGNATURE;
35 } KeyDis_VT102;
36
37 typedef struct
38 {
39   KEYDIS_SIGNATURE;
40   Socket *s;
41 } KeyDis_IPC;
42
43
44 static void
45 keydis_close (KeyDis * t)
46 {
47   free (t);
48 }
49
50
51 static int
52 keydis_ipc_key (KeyDis * _t, Context * c, int key)
53 {
54   KeyDis_IPC *t = (KeyDis_IPC *) _t;
55
56   return ipc_msg_send_key (t->s, key);
57 }
58
59 static int
60 keydis_ipc_set_baud (KeyDis * _t, Context * c, int baud)
61 {
62   KeyDis_IPC *t = (KeyDis_IPC *) _t;
63
64   ipc_msg_send_setbaud (t->s, baud);
65
66   return 0;
67 }
68
69 static int
70 keydis_ipc_send_break (KeyDis * _t, Context * c)
71 {
72   KeyDis_IPC *t = (KeyDis_IPC *) _t;
73
74   ipc_msg_send_sendbreak (t->s);
75
76   return 0;
77 }
78
79 static int
80 keydis_ipc_set_flow (KeyDis * _t, Context * c, int flow)
81 {
82   KeyDis_IPC *t = (KeyDis_IPC *) _t;
83
84   ipc_msg_send_setflow (t->s, flow);
85
86   return 0;
87 }
88
89
90 static int
91 keydis_ipc_hangup (KeyDis * _t, Context * c)
92 {
93   KeyDis_IPC *t = (KeyDis_IPC *) _t;
94
95   ipc_msg_send_hangup (t->s);
96
97   return 0;
98 }
99
100 static int
101 keydis_vt102_key (KeyDis * _t, Context * c, int key)
102 {
103   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
104
105   vt102_send (c, key);
106   return 0;
107 }
108
109 static int
110 keydis_vt102_set_baud (KeyDis * _t, Context * c, int baud)
111 {
112   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
113
114   tty_set_baud (c->t, baud);
115
116   return 0;
117 }
118
119 static int
120 keydis_vt102_send_break (KeyDis * _t, Context * c)
121 {
122   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
123
124   tty_send_break (c->t);
125
126   return 0;
127 }
128
129 static int
130 keydis_vt102_set_flow (KeyDis * _t, Context * c, int flow)
131 {
132   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
133
134   tty_set_flow (c->t, flow);
135
136   return 0;
137 }
138
139
140 static int
141 keydis_vt102_hangup (KeyDis * _t, Context * c)
142 {
143   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
144
145   tty_hangup (c->t);
146
147   return 0;
148 }
149
150
151
152 KeyDis *
153 keydis_vt102_new (void)
154 {
155   KeyDis_VT102 *t = malloc (sizeof (KeyDis_VT102));
156   t->key = keydis_vt102_key;
157   t->close = keydis_close;
158   t->set_baud = keydis_vt102_set_baud;
159   t->send_break = keydis_vt102_send_break;
160   t->set_flow = keydis_vt102_set_flow;
161   t->hangup = keydis_vt102_hangup;
162   return (KeyDis *) t;
163 }
164
165
166 KeyDis *
167 keydis_ipc_new (Socket * s)
168 {
169   KeyDis_IPC *t = malloc (sizeof (KeyDis_IPC));
170   t->key = keydis_ipc_key;
171   t->close = keydis_close;
172   t->set_baud = keydis_ipc_set_baud;
173   t->send_break = keydis_ipc_send_break;
174   t->set_flow = keydis_ipc_set_flow;
175   t->hangup = keydis_ipc_hangup;
176   t->s = s;
177   return (KeyDis *) t;
178 }
179
180
181
182
183
184
185 int
186 keydis_key (KeyDis * t, Context * c, int key)
187 {
188
189   if (!c->d)
190     return t->key (t, c, key);
191
192   cmd_show_status (c->d, c);
193
194   if (c->d->active)
195     return cmd_key (c->d, c, key);
196
197   if (key == CMD_KEY)
198     return cmd_activate (c->d, c);
199
200
201   return t->key (t, c, key);
202 }