1 /*************************************************************************\
5 * Copyright 2000-2001 Emmanuel Lesueur *
7 \*************************************************************************/
10 #include <exec/nodes.h>
11 #include <exec/memory.h>
13 #include <proto/exec.h>
14 #include "apdf/io_client.h"
15 #include "apdf/io_server.h"
33 static struct MsgPort
*port
;
34 static struct MsgPort
*replyPort
;
35 static struct MyMessage1
*msg1
;
36 static struct MyMessage2
*msg2
;
38 IoHandle
ioOpen(const char *name
, size_t *size
) {
39 struct IoOpenMsg
*msg
= (struct IoOpenMsg
*)msg1
->buf
;
40 DB(printf("ioOpen(%s)\n", name
);)
41 msg
->ioMsg
.id
= ioIdOpen
;
42 strncpy(msg
->fileName
, name
, sizeof(msg
->fileName
) - 1);
43 msg
->fileName
[sizeof(msg
->fileName
) - 1] = '\0';
44 PutMsg(port
, &msg1
->msg
);
48 DB(printf("ioOpen = %lx, size = %ld\n", msg
->ioMsg
.handle
, msg
->size
);)
49 return msg
->ioMsg
.handle
;
52 void ioClose(IoHandle handle
) {
53 struct IoMsg
*msg
= (struct IoMsg
*)msg1
->buf
;
54 DB(printf("ioClose(%lx)\n", handle
);)
57 PutMsg(port
, &msg1
->msg
);
63 struct IoMsg
*msg
= (struct IoMsg
*)msg1
->buf
;
64 DB(printf("ioQuit()\n");)
66 PutMsg(port
, &msg1
->msg
);
71 void ioPreRead(IoHandle handle
, size_t offset
, size_t size
) {
72 struct IoPreReadMsg
*msg
= (struct IoPreReadMsg
*)msg1
->buf
;
73 DB(printf("ioPreRead(%lx, 0x%lx, 0x%lx)\n", handle
, offset
, size
);)
74 msg
->ioMsg
.id
= ioIdPreRead
;
75 msg
->ioMsg
.handle
= handle
;
78 PutMsg(port
, &msg1
->msg
);
83 size_t ioRead(IoHandle handle
, void *buf
, size_t offset
, size_t size
) {
84 struct IoReadMsg
*msg
= (struct IoReadMsg
*)msg1
->buf
;
86 DB(printf("ioRead(%lx, 0x%lx, 0x%lx)\n", handle
, offset
, size
);)
87 msg
->ioMsg
.id
= ioIdRead
;
88 msg
->ioMsg
.handle
= handle
;
92 PutMsg(port
, &msg1
->msg
);
93 PutMsg(port
, &msg2
->msg
);
101 IoDir
ioCurrentDir(IoDir dir
) {
102 struct IoCurrentDirMsg
*msg
= (struct IoCurrentDirMsg
*)msg1
->buf
;
103 DB(printf("ioCurrentDir(%lx)\n", dir
);)
104 msg
->ioMsg
.id
= ioIdCurrentDir
;
106 PutMsg(port
, &msg1
->msg
);
109 DB(printf("ioCurrentDir = %lx\n", msg
->dir
);)
113 int initClientIo(IoServer server
) {
114 port
= (struct MsgPort
*)server
;
115 replyPort
= CreateMsgPort();
116 msg1
= (struct MyMessage1
*)AllocMem(sizeof(*msg1
), MEMF_PUBLIC
|MEMF_CLEAR
);
118 msg1
->msg
.mn_ReplyPort
= replyPort
;
119 msg2
= (struct MyMessage2
*)AllocMem(sizeof(*msg2
), MEMF_PUBLIC
|MEMF_CLEAR
);
121 msg2
->msg
.mn_ReplyPort
= replyPort
;
122 return replyPort
&& msg1
&& msg2
;
125 void cleanupClientIo(IoServer
) {
127 FreeMem(msg1
, sizeof(*msg1
));
129 FreeMem(msg2
, sizeof(*msg2
));
131 DeleteMsgPort(replyPort
);