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.2  2008/02/15 03:32:07  james
14  * *** empty log message ***
15  *
16  * Revision 1.1  2008/02/14 02:46:44  james
17  * *** empty log message ***
18  *
19  * Revision 1.1  2008/02/14 01:55:57  james
20  * *** empty log message ***
21  *
22  */
23
24
25 #include "project.h"
26
27 #define CMD_BUFLEN      128
28
29 typedef struct
30 {
31   KEYDIS_SIGNATURE;
32 } KeyDis_VT102;
33
34 typedef struct
35 {
36   KEYDIS_SIGNATURE;
37   Socket *s;
38 } KeyDis_IPC;
39
40
41 static void
42 keydis_close (KeyDis * t)
43 {
44   free (t);
45 }
46
47
48 static int
49 keydis_ipc_key (KeyDis * _t, Context * c, int key)
50 {
51   KeyDis_IPC *t = (KeyDis_IPC *) _t;
52
53   return ipc_msg_send_key (t->s, key);
54 }
55
56 static int
57 keydis_ipc_set_baud (KeyDis * _t, Context * c, int baud)
58 {
59   KeyDis_IPC *t = (KeyDis_IPC *) _t;
60
61   ipc_msg_send_setbaud (t->s, baud);
62
63   return 0;
64 }
65
66 static int
67 keydis_ipc_send_break (KeyDis * _t, Context * c)
68 {
69   KeyDis_IPC *t = (KeyDis_IPC *) _t;
70
71   ipc_msg_send_sendbreak (t->s);
72
73   return 0;
74 }
75
76 static int
77 keydis_ipc_set_flow (KeyDis * _t, Context * c, int flow)
78 {
79   KeyDis_IPC *t = (KeyDis_IPC *) _t;
80
81   ipc_msg_send_setflow (t->s, flow);
82
83   return 0;
84 }
85
86 static int
87 keydis_vt102_key (KeyDis * _t, Context * c, int key)
88 {
89   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
90
91   vt102_send (c, key);
92   return 0;
93 }
94
95 static int
96 keydis_vt102_set_baud (KeyDis * _t, Context * c, int baud)
97 {
98   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
99
100   tty_set_baud (c->t, baud);
101
102   return 0;
103 }
104
105 static int
106 keydis_vt102_send_break (KeyDis * _t, Context * c)
107 {
108   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
109
110   tty_send_break (c->t);
111
112   return 0;
113 }
114
115 static int
116 keydis_vt102_set_flow (KeyDis * _t, Context * c, int flow)
117 {
118   KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
119
120   tty_set_flow (c->t, flow);
121
122   return 0;
123 }
124
125
126
127 KeyDis *
128 keydis_vt102_new (void)
129 {
130   KeyDis_VT102 *t = malloc (sizeof (KeyDis_VT102));
131   t->key = keydis_vt102_key;
132   t->close = keydis_close;
133   t->set_baud = keydis_vt102_set_baud;
134   t->send_break = keydis_vt102_send_break;
135   t->set_flow = keydis_vt102_set_flow;
136   return (KeyDis *) t;
137 }
138
139
140 KeyDis *
141 keydis_ipc_new (Socket * s)
142 {
143   KeyDis_IPC *t = malloc (sizeof (KeyDis_IPC));
144   t->key = keydis_ipc_key;
145   t->close = keydis_close;
146   t->set_baud = keydis_ipc_set_baud;
147   t->send_break = keydis_ipc_send_break;
148   t->set_flow = keydis_ipc_set_flow;
149   t->s = s;
150   return (KeyDis *) t;
151 }
152
153
154
155
156
157
158 int
159 keydis_key (KeyDis * t, Context * c, int key)
160 {
161
162   if (!c->d)
163     return t->key (t, c, key);
164
165   cmd_show_status (c->d, c);
166
167   if (c->d->active)
168     return cmd_key (c->d, c, key);
169
170   if (key == CMD_KEY)
171     return cmd_activate (c->d, c);
172
173
174   return t->key (t, c, key);
175 }