Bringing apdf from vendor into main branch.
[AROS-Contrib.git] / apdf / server / io_client_68k.cc
blob3ace7555078993cf2433ad7a28cc35bc2b037a88
1 /*************************************************************************\
2 * *
3 * io_client_68k.cc *
4 * *
5 * Copyright 2000-2001 Emmanuel Lesueur *
6 * *
7 \*************************************************************************/
9 #include <string.h>
10 #include <exec/nodes.h>
11 #include <exec/memory.h>
12 #include <dos/dos.h>
13 #include <proto/exec.h>
14 #include "apdf/io_client.h"
15 #include "apdf/io_server.h"
17 #if 0
18 # define DB(x) x
19 # include <stdio.h>
20 #else
21 # define DB(x)
22 #endif
24 struct MyMessage1 {
25 struct Message msg;
26 char buf[1024];
28 struct MyMessage2 {
29 struct Message msg;
30 void *buf;
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);
45 WaitPort(replyPort);
46 GetMsg(replyPort);
47 *size = msg->size;
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);)
55 msg->id = ioIdClose;
56 msg->handle = handle;
57 PutMsg(port, &msg1->msg);
58 WaitPort(replyPort);
59 GetMsg(replyPort);
62 void ioQuit(void) {
63 struct IoMsg *msg = (struct IoMsg *)msg1->buf;
64 DB(printf("ioQuit()\n");)
65 msg->id = ioIdQuit;
66 PutMsg(port, &msg1->msg);
67 WaitPort(replyPort);
68 GetMsg(replyPort);
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;
76 msg->offset = offset;
77 msg->size = size;
78 PutMsg(port, &msg1->msg);
79 WaitPort(replyPort);
80 GetMsg(replyPort);
83 size_t ioRead(IoHandle handle, void *buf, size_t offset, size_t size) {
84 struct IoReadMsg *msg = (struct IoReadMsg *)msg1->buf;
85 void *buf1;
86 DB(printf("ioRead(%lx, 0x%lx, 0x%lx)\n", handle, offset, size);)
87 msg->ioMsg.id = ioIdRead;
88 msg->ioMsg.handle = handle;
89 msg->offset = offset;
90 msg->size = size;
91 msg2->buf = buf;
92 PutMsg(port, &msg1->msg);
93 PutMsg(port, &msg2->msg);
94 WaitPort(replyPort);
95 GetMsg(replyPort);
96 WaitPort(replyPort);
97 GetMsg(replyPort);
98 return msg->size;
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;
105 msg->dir = dir;
106 PutMsg(port, &msg1->msg);
107 WaitPort(replyPort);
108 GetMsg(replyPort);
109 DB(printf("ioCurrentDir = %lx\n", msg->dir);)
110 return 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);
117 if (msg1)
118 msg1->msg.mn_ReplyPort = replyPort;
119 msg2 = (struct MyMessage2 *)AllocMem(sizeof(*msg2), MEMF_PUBLIC|MEMF_CLEAR);
120 if (msg2)
121 msg2->msg.mn_ReplyPort = replyPort;
122 return replyPort && msg1 && msg2;
125 void cleanupClientIo(IoServer) {
126 if (msg1)
127 FreeMem(msg1, sizeof(*msg1));
128 if (msg2)
129 FreeMem(msg2, sizeof(*msg2));
130 if (replyPort)
131 DeleteMsgPort(replyPort);