1 /***************************************************************
2 **** PrefsPort.c: Communication port with JanoEditor ****
3 **** Free software under GNU license, started on 11/11/2000 ****
4 **** Written by T.Pierron ****
5 ***************************************************************/
7 #include <exec/types.h>
9 #include <libraries/dos.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
14 #include <clib/alib_protos.h>
18 #include "IPC_Prefs.h"
19 #include "JanoPrefs.h"
21 /** Port of Pref and Jano **/
22 static struct MsgPort
*port
, *reply
;
23 static struct JPacket
*cmd
;
25 UBYTE
*PortName
= JANOPREFS_PORT
;
27 /** Look if prefs isn't alredy running **/
28 char find_prefs( void )
31 if((reply
= (struct MsgPort
*) FindPort(PortName
)))
33 PortName
= NULL
; /* Private port */
34 if(( sigwait
= create_port() ))
36 /* Send to the running preference tool that someone tries to launch it again */
37 cmd
->class = CMD_SHOW
;
38 PutMsg(reply
, (struct Message
*)cmd
);
39 /* cmd packet is associated with "port", thus reply will be done here */
41 /* Unqueue message (don't reply!) */
44 /* Cleanup will be done later */
49 /** Setup public port of the preference editor **/
50 ULONG
create_port( void )
52 /* Create a port and */
53 if(( port
= (struct MsgPort
*) CreatePort(PortName
, 0L) ))
55 /* Create a message that can be sent to the editor */
56 if(( cmd
= (struct JPacket
*) CreateExtIO(port
, (long) sizeof (*cmd
)) ))
57 return (unsigned) (1L << port
->mp_SigBit
);
64 /** Search for a running session of editor **/
65 char find_jano(PREFS
*prefs
)
67 extern struct Screen
*Scr
;
68 if((reply
= (struct MsgPort
*) FindPort(JANO_PORT
)))
70 /* Get a copy of the preferences that uses the editor */
71 cmd
->class = CMD_PREF
;
72 PutMsg(reply
, (struct Message
*)cmd
);
73 Wait( 1 << port
->mp_SigBit
| SIGBREAKF_CTRL_C
);
75 /* Copy to our local buffer */
76 CopyMem(&cmd
->prefs
, prefs
, sizeof(*prefs
));
83 /** Send a preference struct to Jano's public port **/
84 char send_jano(PREFS
*prefs
, ULONG
class)
86 /* The port can be shutted down!! */
87 if(( reply
= (struct MsgPort
*) FindPort(JANO_PORT
)))
90 CopyMem(prefs
, &cmd
->prefs
, sizeof(*prefs
));
92 PutMsg(reply
, (struct Message
*)cmd
);
93 Wait( 1 << port
->mp_SigBit
| SIGBREAKF_CTRL_C
);
100 void close_port( void )
102 if( cmd
) DeleteExtIO((struct IORequest
*)cmd
);
104 /* Be sure there are no message left */
106 while((msg
= GetMsg( port
))) ReplyMsg(msg
);
111 /** Handle messages posted to the public port **/
112 void handle_port( void )
115 extern UBYTE ConfigFile
;
116 while(( msg
= (struct JPacket
*) GetMsg(port
) ))
120 case CMD_SHOW
: setup_guipref(); break;
122 /* Close preference tool only if it's associated to jano */
123 if( !ConfigFile
) close_prefwnd(0); break;
125 ReplyMsg((struct Message
*)msg
);