tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / kern / amiga_cx.c
blob813963c589f5161ec1358cafd62f61f34af29758
1 #include "conf.h"
2 #include "version.h"
4 #include <exec/libraries.h>
5 #include <libraries/commodities.h>
6 #include <proto/commodities.h>
7 #include <proto/exec.h>
8 #include <kern/amiga_cx.h>
9 #include <kern/amiga_gui.h>
11 extern UBYTE *REXX_PORT_NAME;
12 extern struct Task *AROSTCP_Task;
13 extern struct Library *SocketBase;
15 struct Library *CxBase = NULL;
16 static CxObj *Broker = NULL;
18 struct NewBroker nb = {
19 NB_VERSION,
20 NULL,
21 STACK_RELEASE,
22 "The opensource TCP/IP stack",
24 COF_SHOW_HIDE,
30 ULONG
31 cx_init(void)
33 if (CxBase = OpenLibrary("commodities.library", 0L)) {
34 nb.nb_Port = CreateMsgPort();
35 if (nb.nb_Port) {
36 nb.nb_Name = REXX_PORT_NAME;
37 return (ULONG)1 << nb.nb_Port->mp_SigBit;
40 cx_deinit();
41 return (0);
44 BOOL
45 cx_show(void)
47 if (!Broker && nb.nb_Port) {
48 Broker = CxBroker(&nb, NULL);
49 if (Broker) {
50 ActivateCxObj(Broker, 1);
51 return TRUE;
54 return FALSE;
57 BOOL
58 cx_hide(void)
60 struct Message *msg;
61 if (Broker) {
63 * Remove the broker from the system
65 DeleteCxObj(Broker);
66 /* Empty the message port */
67 while (msg = GetMsg(nb.nb_Port))
68 ReplyMsg(msg);
69 Broker = NULL;
71 return TRUE;
74 void cx_deinit(void)
76 if (CxBase) {
77 if (nb.nb_Port) {
78 cx_hide();
79 DeleteMsgPort(nb.nb_Port);
80 nb.nb_Port = NULL;
82 CloseLibrary(CxBase);
83 CxBase = NULL;
87 BOOL cx_poll(void)
89 CxMsg *msg;
90 ULONG msgid, msgtype;
92 if (msg = (CxMsg *)GetMsg(nb.nb_Port)) {
93 msgid = CxMsgID(msg);
94 msgtype = CxMsgType(msg);
95 ReplyMsg((struct Message *)msg);
96 if (SocketBase) {
97 if (msgtype == CXM_COMMAND) {
98 /* Commodities has sent a command */
99 switch(msgid) {
100 case CXCMD_ENABLE:
101 case CXCMD_DISABLE:
102 gui_snapshot();
103 break;
104 case CXCMD_APPEAR:
105 gui_open();
106 break;
107 case CXCMD_DISAPPEAR:
108 gui_close();
109 break;
110 case CXCMD_KILL:
111 /* user clicked Remove button, let's quit */
112 Signal(AROSTCP_Task, SIGBREAKF_CTRL_C);
113 break;
117 return TRUE;
119 return FALSE;