configure: when detecting linux include directory for kernel compiler use target...
[AROS.git] / rom / filesys / ram / notification.c
blobf0a828fa982e838def1254d540fb0dfa6e05a68b
1 /*
3 File: notification.c
4 Author: Neil Cafferkey
5 Copyright (C) 2001-2008 Neil Cafferkey
7 This file is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 This file is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this file; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA.
25 #include "handler_protos.h"
28 static VOID NotifyObject(struct Handler *handler, struct Object *object);
32 /****i* ram.handler/MatchNotifyRequests ************************************
34 * NAME
35 * MatchNotifyRequests --
37 * SYNOPSIS
38 * MatchNotifyRequests(handler)
40 * VOID MatchNotifyRequests(struct Handler *);
42 * FUNCTION
44 * INPUTS
46 * RESULT
48 * EXAMPLE
50 * NOTES
52 * BUGS
54 * SEE ALSO
56 ****************************************************************************
60 VOID MatchNotifyRequests(struct Handler *handler)
62 struct Notification *notification, *next_notification, *tail;
63 struct Object *object;
65 next_notification = (APTR)handler->notifications.mlh_Head;
66 tail = (APTR)&handler->notifications.mlh_Tail;
68 while(next_notification != tail)
70 notification = next_notification;
71 next_notification = (APTR)((struct MinNode *)notification)->mln_Succ;
73 object = GetHardObject(handler, NULL,
74 notification->request->nr_FullName, NULL);
75 if(object != NULL)
77 Remove((APTR)notification);
78 AddTail((APTR)&object->notifications, (APTR)notification);
82 return;
87 /****i* ram.handler/UnmatchNotifyRequests **********************************
89 * NAME
90 * UnmatchNotifyRequests --
92 * SYNOPSIS
93 * UnmatchNotifyRequests(handler, object)
95 * VOID UnmatchNotifyRequests(struct Handler *, struct Object *);
97 * FUNCTION
99 * INPUTS
101 * RESULT
103 * EXAMPLE
105 * NOTES
107 * BUGS
109 * SEE ALSO
111 ****************************************************************************
115 VOID UnmatchNotifyRequests(struct Handler *handler, struct Object *object)
117 struct Notification *notification, *next_notification, *tail;
119 next_notification = (APTR)object->notifications.mlh_Head;
120 tail = (APTR)&object->notifications.mlh_Tail;
122 while(next_notification != tail)
124 notification = next_notification;
125 next_notification = (APTR)((struct MinNode *)notification)->mln_Succ;
127 Remove((APTR)notification);
128 AddTail((APTR)&handler->notifications, (APTR)notification);
131 return;
136 /****i* ram.handler/NotifyAll **********************************************
138 * NAME
139 * NotifyAll --
141 * SYNOPSIS
142 * NotifyAll(handler, object, notify_links)
144 * VOID NotifyAll(struct Handler *, struct Object *, BOOL);
146 * FUNCTION
148 * INPUTS
150 * RESULT
152 * EXAMPLE
154 * NOTES
156 * BUGS
158 * SEE ALSO
160 ****************************************************************************
164 VOID NotifyAll(struct Handler *handler, struct Object *object,
165 BOOL notify_links)
167 struct MinNode *tail, *link_node;
169 if(notify_links)
171 object = GetRealObject(object);
172 link_node = object->hard_link.mln_Succ;
173 if(link_node != NULL)
175 tail = (APTR)&HARDLINK(link_node)->elements.mlh_Tail;
177 else
178 notify_links = FALSE;
181 if(notify_links)
183 link_node = &object->hard_link;
185 while(link_node != tail)
187 object = HARDLINK(link_node);
188 NotifyObject(handler, object);
189 NotifyObject(handler, object->parent);
190 link_node = link_node->mln_Succ;
193 else
195 NotifyObject(handler, object);
196 NotifyObject(handler, object->parent);
199 return;
204 /****i* ram.handler/NotifyObject *******************************************
206 * NAME
207 * NotifyObject --
209 * SYNOPSIS
210 * NotifyObject(handler, object)
212 * VOID NotifyObject(struct Handler *, struct Object *);
214 * FUNCTION
216 * INPUTS
218 * RESULT
220 * EXAMPLE
222 * NOTES
224 * BUGS
226 * SEE ALSO
228 ****************************************************************************
232 static VOID NotifyObject(struct Handler *handler, struct Object *object)
234 struct Notification *notification, *tail;
236 if(object != NULL)
238 notification = (APTR)object->notifications.mlh_Head;
239 tail = (APTR)&object->notifications.mlh_Tail;
241 while(notification != tail)
243 Notify(handler, notification);
244 notification = (APTR)((struct MinNode *)notification)->mln_Succ;
248 return;
253 /****i* ram.handler/FindNotification ***************************************
255 * NAME
256 * FindNotification --
258 * SYNOPSIS
259 * notification = FindNotification(handler,
260 * request)
262 * struct Notification *FindNotification(struct Handler *,
263 * struct NotifyRequest);
265 * FUNCTION
267 * INPUTS
269 * RESULT
271 * EXAMPLE
273 * NOTES
275 * BUGS
277 * SEE ALSO
279 ****************************************************************************
283 struct Notification *FindNotification(struct Handler *handler,
284 struct NotifyRequest *request)
286 struct Notification *notification, *tail;
287 struct MinList *list;
288 BOOL found;
289 struct Object *object;
291 /* Find which list the request should be in */
293 object = GetHardObject(handler, NULL, request->nr_FullName, NULL);
294 if(object != NULL)
295 list = &object->notifications;
296 else
297 list = &handler->notifications;
299 /* Search the list */
301 notification = (APTR)list->mlh_Head;
302 tail = (APTR)&list->mlh_Tail;
303 found = FALSE;
305 while(notification != tail && !found)
307 if(notification->request == request)
308 found = TRUE;
309 else
310 notification = (APTR)((struct MinNode *)notification)->mln_Succ;
313 if(!found)
314 notification = NULL;
316 return notification;
321 /****i* ram.handler/ReceiveNotifyReply *************************************
323 * NAME
324 * ReceiveNotifyReply --
326 * SYNOPSIS
327 * ReceiveNotifyReply(handler, message)
329 * VOID ReceiveNotifyReply(struct Handler *, struct NotifyMessage *);
331 * FUNCTION
333 * INPUTS
335 * RESULT
337 * EXAMPLE
339 * NOTES
341 * BUGS
343 * SEE ALSO
345 ****************************************************************************
349 VOID ReceiveNotifyReply(struct Handler *handler,
350 struct NotifyMessage *message)
352 struct NotifyRequest *request;
353 struct Notification *notification = NULL;
355 /* Get request and free message */
357 request = message->nm_NReq;
358 FreePooled(handler->public_pool, message, sizeof(struct NotifyMessage));
360 /* Get notification if EndNotify() hasn't been called */
362 if(request->nr_FullName != NULL)
363 notification = FindNotification(handler, request);
364 if(notification != NULL)
366 request->nr_MsgCount--;
368 /* Send a new notification if there's one pending */
370 if((request->nr_Flags & NRF_MAGIC) != 0)
372 request->nr_Flags &= ~NRF_MAGIC;
373 Notify(handler, notification);
377 return;
382 /****i* ram.handler/Notify *************************************************
384 * NAME
385 * Notify --
387 * SYNOPSIS
388 * Notify(handler, notification)
390 * VOID Notify(struct Handler *, struct Notification *);
392 * FUNCTION
394 * INPUTS
396 * RESULT
398 * EXAMPLE
400 * NOTES
402 * BUGS
404 * SEE ALSO
406 ****************************************************************************
410 VOID Notify(struct Handler *handler, struct Notification *notification)
412 struct NotifyMessage *message;
413 struct NotifyRequest *request;
414 ULONG flags;
416 request = notification->request;
417 flags = request->nr_Flags;
418 if((flags & NRF_SEND_MESSAGE) != 0)
420 /* Send message now or remember to send it later */
422 if((flags & NRF_WAIT_REPLY) == 0 || request->nr_MsgCount == 0)
424 message = AllocPooled(handler->public_pool,
425 sizeof(struct NotifyMessage));
426 if(message != NULL)
428 ((struct Message *)message)->mn_ReplyPort =
429 handler->notify_port;
430 ((struct Message *)message)->mn_Length =
431 sizeof(struct NotifyMessage);
432 message->nm_NReq = request;
433 message->nm_Class = NOTIFY_CLASS;
434 message->nm_Code = NOTIFY_CODE;
436 PutMsg(request->nr_stuff.nr_Msg.nr_Port, (APTR)message);
437 request->nr_MsgCount++;
440 else
441 request->nr_Flags |= NRF_MAGIC;
443 else
445 Signal(request->nr_stuff.nr_Signal.nr_Task,
446 1 << (request->nr_stuff.nr_Signal.nr_SignalNum));
449 return;