vfs: check userland buffers before reading them.
[haiku.git] / src / apps / cortex / support / IObservable.h
bloba46d7e425c00c75e8004d80ff8c5b10a1073941c
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 // IObservable.h
33 // * PURPOSE
34 // Defines a general observable-object interface.
35 // * HISTORY
36 // e.moon 19aug99 Begun
38 #ifndef __IObservable_H__
39 #define __IObservable_H__
41 class BMessenger;
43 #include "cortex_defs.h"
44 __BEGIN_CORTEX_NAMESPACE
46 class IObservable {
48 public:
49 IObservable() { }
50 virtual ~IObservable() { }
51 public: // *** deletion
52 // clients must call release() rather than deleting,
53 // to ensure that all observers are notified of the
54 // object's demise. if the object has already been
55 // released, return an error.
56 virtual status_t release()=0;
58 public: // *** accessors
59 // return true if release() has been called, false otherwise.
60 virtual bool isReleased() const=0;
62 protected: // *** hooks
63 // must be called after an observer has been added (this is a good
64 // place to send an acknowledgement)
65 virtual void observerAdded(
66 const BMessenger& observer) {TOUCH(observer);}
68 // must be called after an observer has been removed
69 virtual void observerRemoved(
70 const BMessenger& observer) {TOUCH(observer);}
72 // must be called once all observers have been removed
73 virtual void releaseComplete() {}
75 protected: // *** operations
76 // call to send the given message to all observers.
77 // Responsibility for deletion of the message remains with
78 // the caller.
79 virtual status_t notify(
80 BMessage* message)=0;
82 // must be called by release() if targets remain to be
83 // released. should notify all targets with an appropriate
84 // release-notification message (such as M_RELEASE_OBSERVABLE).
85 virtual void notifyRelease()=0;
88 __END_CORTEX_NAMESPACE
89 #endif /*__IObservable_H__*/