btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / cortex / support / ObservableHandler.h
blob9f7c9e92278bccd5d540deec20b741e887d1627a
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // ObservableHandler.h
33 // * PURPOSE
34 // Implementation of an observable BHandler.
36 // * HISTORY
37 // e.moon 19aug99 Begun.
39 #ifndef __ObservableHandler_H__
40 #define __ObservableHandler_H__
42 #include <Handler.h>
44 #include "observe.h"
45 #include "IObservable.h"
46 #include "MultiInvoker.h"
48 #include "cortex_defs.h"
49 __BEGIN_CORTEX_NAMESPACE
51 class ObservableHandler :
52 public BHandler,
53 public IObservable,
54 private MultiInvoker {
56 typedef BHandler _inherited;
58 public: // *** deletion
59 // clients must call release() rather than deleting,
60 // to ensure that all observers are notified of the
61 // object's demise. if the object has already been
62 // released, return an error.
64 virtual status_t release();
66 public: // *** ctor/dtor
67 virtual ~ObservableHandler();
68 ObservableHandler(
69 const char* name=0);
70 ObservableHandler(
71 BMessage* archive);
73 public: // *** accessors
74 // return true if release() has been called, false otherwise.
75 bool isReleased() const;
77 protected: // *** hooks
78 // sends M_OBSERVER_ADDED to the newly-added observer
79 virtual void observerAdded(
80 const BMessenger& observer);
82 // sends M_OBSERVER_REMOVED to the newly-removed observer
83 virtual void observerRemoved(
84 const BMessenger& observer);
86 protected: // *** internal operations
87 // call to send the given message to all observers.
88 // Responsibility for deletion of the message remains with
89 // the caller.
90 // * LOCKING: the BLooper must be locked.
91 virtual status_t notify(
92 BMessage* message);
94 // sends M_RELEASE_OBSERVABLE
95 virtual void notifyRelease();
97 public: // *** BHandler
98 virtual void MessageReceived(
99 BMessage* message);
101 public: // *** BArchivable
102 // * LOCKING: the BLooper must be locked.
103 virtual status_t Archive(
104 BMessage* archive,
105 bool deep=true) const;
107 private: // implementation
108 void _handleAddObserver(
109 BMessage* message); //nyi
111 void _handleRemoveObserver(
112 BMessage* message); //nyi
114 private: // members
115 bool m_released;
118 __END_CORTEX_NAMESPACE
119 #endif /*__ObservableHandler_H__*/