btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / servers / net / SimpleMessageFilter.cpp
blob83f7bbf59b4fb771df100c2e3b938930422dbc35
1 /*
2 * Copyright 2004, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
4 */
6 /*! \class SimpleMessageFilter
7 \brief This is a BMessageFilter that can filter multiple \a what values.
9 This class extends the BMessageFilter's ability of handling one \a what value
10 to handling multiple \a what values.
13 #include "SimpleMessageFilter.h"
14 #include <Message.h>
17 /*! \brief Creates a copy of the \a what array.
19 \param what A pointer to an array of \a what values that should be filtered.
20 The end-of-list indicator is an element valued 0 (zero).
21 \param target The target for messages matching one of the \a what values.
22 If \a target == NULL the messages will be discarded.
24 SimpleMessageFilter::SimpleMessageFilter(const uint32 *what, BHandler *target)
25 : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
26 fTarget(target)
28 if(!what) {
29 fWhatArray = NULL;
30 return;
33 // include the trailing zero in the copy
34 int32 count = 0;
35 while(what[count++] != 0)
37 fWhatArray = new uint32[count];
38 memcpy(fWhatArray, what, count * sizeof(uint32));
42 //! Frees the copied \a what array.
43 SimpleMessageFilter::~SimpleMessageFilter()
45 delete fWhatArray;
49 //! Filters all messages that match the \a what array given in the constructor.
50 filter_result
51 SimpleMessageFilter::Filter(BMessage *message, BHandler **target)
53 for(int32 index = 0; fWhatArray[index] != 0; index++)
54 if(fWhatArray[index] == message->what) {
55 if(!fTarget)
56 return B_SKIP_MESSAGE;
58 *target = fTarget;
59 break;
62 return B_DISPATCH_MESSAGE;