vfs: check userland buffers before reading them.
[haiku.git] / src / servers / registrar / Clipboard.cpp
blob386a1b27cb8a481a512655bf508b95d91569d87b
1 // Clipboard.cpp
3 #include <app/Clipboard.h>
5 #include "Clipboard.h"
7 /*!
8 \class Clipboard
9 \brief Server-side representation of a clipboard.
12 // constructor
13 /*! \brief Creates and initializes a Clipboard.
14 \param name The name of the clipboard.
16 Clipboard::Clipboard(const char *name)
17 : fName(name),
18 fData(B_SIMPLE_DATA),
19 fDataSource(),
20 fCount(0),
21 fWatchingService()
25 // destructor
26 /*! \brief Frees all resources associate with this object.
28 Clipboard::~Clipboard()
32 // SetData
33 /*! \brief Sets the clipboard's data.
35 Also notifies all watchers that the clipboard data have changed.
37 \param data The new clipboard data.
38 \param dataSource The clipboards new data source.
40 void
41 Clipboard::SetData(const BMessage *data, BMessenger dataSource)
43 fData = *data;
44 fDataSource = dataSource;
45 fCount++;
46 NotifyWatchers();
49 // Data
50 /*! \brief Returns the clipboard's data.
51 \return The clipboard's data.
53 const BMessage *
54 Clipboard::Data() const
56 return &fData;
59 // DataSource
60 /*! \brief Returns the clipboard's data source.
61 \return The clipboard's data source.
63 BMessenger
64 Clipboard::DataSource() const
66 return fDataSource;
69 // Count
70 int32
71 Clipboard::Count() const
73 return fCount;
77 // AddWatcher
78 /*! \brief Adds a new watcher for this clipboard.
79 \param watcher The messenger referring to the new watcher.
80 \return \c true, if the watcher could be added successfully,
81 \c false otherwise.
83 bool
84 Clipboard::AddWatcher(BMessenger watcher)
86 return fWatchingService.AddWatcher(watcher);
89 // RemoveWatcher
90 /*! \brief Removes a watcher from this clipboard.
91 \param watcher The watcher to be removed.
92 \return \c true, if the supplied watcher was watching the clipboard,
93 \c false otherwise.
95 bool
96 Clipboard::RemoveWatcher(BMessenger watcher)
98 return fWatchingService.RemoveWatcher(watcher);
101 // NotifyWatchers
102 /*! \brief Sends a notification message that the clipboard data have changed
103 to all associated watchers.
105 void
106 Clipboard::NotifyWatchers()
108 BMessage message(B_CLIPBOARD_CHANGED);
109 fWatchingService.NotifyWatchers(&message, NULL);