Applied our coding style. Theoretically improved return values.
Data() now enters the debugger as well if called in unlocked state. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8191 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+194
-166
@@ -43,212 +43,240 @@ BClipboard *be_clipboard;
|
|||||||
|
|
||||||
BClipboard::BClipboard(const char *name, bool transient)
|
BClipboard::BClipboard(const char *name, bool transient)
|
||||||
{
|
{
|
||||||
if ( name )
|
if (name != NULL)
|
||||||
fName = strdup(name);
|
fName = strdup(name);
|
||||||
else
|
else
|
||||||
fName = strdup("system");
|
fName = strdup("system");
|
||||||
fData = new BMessage();
|
|
||||||
fCount = 0;
|
|
||||||
fSystemCount = 0;
|
|
||||||
|
|
||||||
BMessage message(B_REG_GET_CLIPBOARD_MESSENGER), reply;
|
fData = new BMessage();
|
||||||
if ( (BRoster::Private().SendTo(&message, &reply, false) == B_OK) &&
|
fCount = 0;
|
||||||
(reply.what == B_REG_SUCCESS) &&
|
fSystemCount = 0;
|
||||||
(reply.FindMessenger("messenger",&fClipHandler) == B_OK) )
|
|
||||||
{
|
BMessage message(B_REG_GET_CLIPBOARD_MESSENGER), reply;
|
||||||
BMessage handlerMessage(B_REG_ADD_CLIPBOARD), handlerReply;
|
if (BRoster::Private().SendTo(&message, &reply, false) == B_OK
|
||||||
int32 result;
|
&& reply.what == B_REG_SUCCESS
|
||||||
if ( (handlerMessage.AddString("name",fName) == B_OK) &&
|
&& reply.FindMessenger("messenger", &fClipHandler) == B_OK) {
|
||||||
(fClipHandler.SendMessage(&handlerMessage, &handlerReply) == B_OK) )
|
BMessage handlerMessage(B_REG_ADD_CLIPBOARD), handlerReply;
|
||||||
handlerReply.FindInt32("result",&result);
|
int32 result;
|
||||||
}
|
if (handlerMessage.AddString("name", fName) == B_OK
|
||||||
|
&& fClipHandler.SendMessage(&handlerMessage, &handlerReply) == B_OK)
|
||||||
|
handlerReply.FindInt32("result", &result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BClipboard::~BClipboard()
|
BClipboard::~BClipboard()
|
||||||
{
|
{
|
||||||
free(fName);
|
free(fName);
|
||||||
delete fData;
|
delete fData;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
const char* BClipboard::Name() const
|
|
||||||
{
|
|
||||||
return (const char*)fName;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint32 BClipboard::LocalCount() const
|
|
||||||
{
|
|
||||||
/* fSystemCount contains the total number of writes to the clipboard.
|
|
||||||
fCount contains the number of writes to the clipboard done by this
|
|
||||||
BClipboard.
|
|
||||||
*/
|
|
||||||
return fSystemCount;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint32 BClipboard::SystemCount() const
|
|
||||||
{
|
|
||||||
int32 val;
|
|
||||||
BMessage message(B_REG_GET_CLIPBOARD_COUNT), reply;
|
|
||||||
if ( (message.AddString("name",fName) == B_OK) &&
|
|
||||||
(fClipHandler.SendMessage(&message, &reply) == B_OK) &&
|
|
||||||
(reply.FindInt32("count",&val) == B_OK) )
|
|
||||||
return (uint32)val;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BClipboard::StartWatching(BMessenger target)
|
|
||||||
{
|
|
||||||
BMessage message(B_REG_CLIPBOARD_START_WATCHING), reply;
|
|
||||||
if ( (message.AddString("name",fName) == B_OK) &&
|
|
||||||
(message.AddMessenger("target", target ) == B_OK) &&
|
|
||||||
(fClipHandler.SendMessage(&message, &reply) == B_OK) )
|
|
||||||
{
|
|
||||||
int32 result;
|
|
||||||
reply.FindInt32("result",&result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BClipboard::StopWatching(BMessenger target)
|
|
||||||
{
|
|
||||||
BMessage message(B_REG_CLIPBOARD_STOP_WATCHING), reply;
|
|
||||||
if ( (message.AddString("name",fName) == B_OK) &&
|
|
||||||
(message.AddMessenger("target", target ) == B_OK) &&
|
|
||||||
(fClipHandler.SendMessage(&message, &reply) == B_OK) )
|
|
||||||
{
|
|
||||||
int32 result;
|
|
||||||
reply.FindInt32("result",&result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BClipboard::Lock()
|
|
||||||
{
|
|
||||||
/* Will this work correctly if clipboard is deleted while still waiting on
|
|
||||||
fLock.Lock() ? */
|
|
||||||
bool retVal;
|
|
||||||
retVal = fLock.Lock();
|
|
||||||
if ( retVal &&
|
|
||||||
(DownloadFromSystem() != B_OK) )
|
|
||||||
{
|
|
||||||
retVal = false;
|
|
||||||
fLock.Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
return retVal;
|
const char *
|
||||||
}
|
BClipboard::Name() const
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BClipboard::Unlock()
|
|
||||||
{
|
{
|
||||||
fLock.Unlock();
|
return (const char *)fName;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BClipboard::IsLocked() const
|
|
||||||
|
uint32
|
||||||
|
BClipboard::LocalCount() const
|
||||||
{
|
{
|
||||||
return fLock.IsLocked();
|
/* fSystemCount contains the total number of writes to the clipboard.
|
||||||
|
* fCount contains the number of writes to the clipboard done by this
|
||||||
|
* BClipboard.
|
||||||
|
*/
|
||||||
|
return fSystemCount;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BClipboard::Clear()
|
|
||||||
|
uint32
|
||||||
|
BClipboard::SystemCount() const
|
||||||
{
|
{
|
||||||
if ( AssertLocked() &&
|
int32 value;
|
||||||
(fData->MakeEmpty() == B_OK) )
|
BMessage message(B_REG_GET_CLIPBOARD_COUNT), reply;
|
||||||
return B_OK;
|
if (message.AddString("name", fName) == B_OK
|
||||||
return B_ERROR;
|
&& fClipHandler.SendMessage(&message, &reply) == B_OK
|
||||||
|
&& reply.FindInt32("count", &value) == B_OK)
|
||||||
|
return (uint32)value;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BClipboard::Commit()
|
|
||||||
|
status_t
|
||||||
|
BClipboard::StartWatching(BMessenger target)
|
||||||
{
|
{
|
||||||
if ( AssertLocked() &&
|
BMessage message(B_REG_CLIPBOARD_START_WATCHING), reply;
|
||||||
(UploadToSystem() == B_OK) )
|
if (message.AddString("name", fName) == B_OK
|
||||||
return B_OK;
|
&& message.AddMessenger("target", target) == B_OK
|
||||||
return B_ERROR;
|
&& fClipHandler.SendMessage(&message, &reply) == B_OK) {
|
||||||
|
int32 result;
|
||||||
|
reply.FindInt32("result", &result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BClipboard::Revert()
|
|
||||||
|
status_t
|
||||||
|
BClipboard::StopWatching(BMessenger target)
|
||||||
{
|
{
|
||||||
if ( AssertLocked() &&
|
BMessage message(B_REG_CLIPBOARD_STOP_WATCHING), reply;
|
||||||
(fData->MakeEmpty() == B_OK) &&
|
if (message.AddString("name", fName) == B_OK
|
||||||
(DownloadFromSystem() == B_OK) )
|
&& message.AddMessenger("target", target) == B_OK
|
||||||
return B_OK;
|
&& fClipHandler.SendMessage(&message, &reply) == B_OK) {
|
||||||
return B_ERROR;
|
int32 result;
|
||||||
|
reply.FindInt32("result", &result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BMessenger BClipboard::DataSource() const
|
|
||||||
|
bool
|
||||||
|
BClipboard::Lock()
|
||||||
{
|
{
|
||||||
return fDataSource;
|
// Will this work correctly if clipboard is deleted while still waiting on
|
||||||
|
// fLock.Lock() ?
|
||||||
|
bool locked = fLock.Lock();
|
||||||
|
if (locked && DownloadFromSystem() != B_OK) {
|
||||||
|
locked = false;
|
||||||
|
fLock.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
return locked;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BMessage* BClipboard::Data() const
|
|
||||||
|
void
|
||||||
|
BClipboard::Unlock()
|
||||||
{
|
{
|
||||||
if ( IsLocked() )
|
fLock.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BClipboard::IsLocked() const
|
||||||
|
{
|
||||||
|
return fLock.IsLocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BClipboard::Clear()
|
||||||
|
{
|
||||||
|
if (!AssertLocked())
|
||||||
|
return B_NOT_ALLOWED;
|
||||||
|
|
||||||
|
return fData->MakeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BClipboard::Commit()
|
||||||
|
{
|
||||||
|
if (!AssertLocked())
|
||||||
|
return B_NOT_ALLOWED;
|
||||||
|
|
||||||
|
return UploadToSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BClipboard::Revert()
|
||||||
|
{
|
||||||
|
if (!AssertLocked())
|
||||||
|
return B_NOT_ALLOWED;
|
||||||
|
|
||||||
|
status_t status = fData->MakeEmpty();
|
||||||
|
if (status == B_OK)
|
||||||
|
status = DownloadFromSystem();
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMessenger
|
||||||
|
BClipboard::DataSource() const
|
||||||
|
{
|
||||||
|
return fDataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMessage *
|
||||||
|
BClipboard::Data() const
|
||||||
|
{
|
||||||
|
if (!AssertLocked())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return fData;
|
return fData;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
// Private methods
|
||||||
|
|
||||||
|
|
||||||
BClipboard::BClipboard(const BClipboard &)
|
BClipboard::BClipboard(const BClipboard &)
|
||||||
{
|
{
|
||||||
/* This is private, and I don't use it, so I'm not going to implement it */
|
// This is private, and I don't use it, so I'm not going to implement it
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BClipboard & BClipboard::operator=(const BClipboard &)
|
BClipboard & BClipboard::operator=(const BClipboard &)
|
||||||
{
|
{
|
||||||
/* This is private, and I don't use it, so I'm not going to implement it */
|
// This is private, and I don't use it, so I'm not going to implement it
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BClipboard::_ReservedClipboard1()
|
|
||||||
{
|
void BClipboard::_ReservedClipboard1() {}
|
||||||
}
|
void BClipboard::_ReservedClipboard2() {}
|
||||||
//------------------------------------------------------------------------------
|
void BClipboard::_ReservedClipboard3() {}
|
||||||
void BClipboard::_ReservedClipboard2()
|
|
||||||
{
|
|
||||||
}
|
bool
|
||||||
//------------------------------------------------------------------------------
|
BClipboard::AssertLocked() const
|
||||||
void BClipboard::_ReservedClipboard3()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BClipboard::AssertLocked() const
|
|
||||||
{
|
{
|
||||||
// This function is for jumping to the debugger if not locked
|
// This function is for jumping to the debugger if not locked
|
||||||
if(!fLock.IsLocked())
|
if (!fLock.IsLocked()) {
|
||||||
{
|
|
||||||
debugger("The clipboard must be locked before proceeding.");
|
debugger("The clipboard must be locked before proceeding.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BClipboard::DownloadFromSystem(bool force)
|
|
||||||
|
status_t
|
||||||
|
BClipboard::DownloadFromSystem(bool force)
|
||||||
{
|
{
|
||||||
// Apparently, the force paramater was used in some sort of
|
// Apparently, the force paramater was used in some sort of
|
||||||
// optimization in R5. Currently, we ignore it.
|
// optimization in R5. Currently, we ignore it.
|
||||||
BMessage message(B_REG_DOWNLOAD_CLIPBOARD), reply;
|
BMessage message(B_REG_DOWNLOAD_CLIPBOARD), reply;
|
||||||
if ( (message.AddString("name",fName) == B_OK) &&
|
if (message.AddString("name", fName) == B_OK
|
||||||
(fClipHandler.SendMessage(&message, &reply) == B_OK) &&
|
&& fClipHandler.SendMessage(&message, &reply) == B_OK
|
||||||
(reply.FindMessage("data",fData) == B_OK) &&
|
&& reply.FindMessage("data", fData) == B_OK
|
||||||
(reply.FindMessenger("data source",&fDataSource) == B_OK) &&
|
&& reply.FindMessenger("data source", &fDataSource) == B_OK
|
||||||
(reply.FindInt32("count",(int32 *)(&fSystemCount)) == B_OK) )
|
&& reply.FindInt32("count", (int32 *)&fSystemCount) == B_OK)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
return B_ERROR;
|
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BClipboard::UploadToSystem()
|
|
||||||
|
status_t
|
||||||
|
BClipboard::UploadToSystem()
|
||||||
{
|
{
|
||||||
BMessage message(B_REG_UPLOAD_CLIPBOARD), reply;
|
BMessage message(B_REG_UPLOAD_CLIPBOARD), reply;
|
||||||
if ( (message.AddString("name",fName) == B_OK) &&
|
if (message.AddString("name", fName) == B_OK
|
||||||
(message.AddMessage("data",fData) == B_OK) &&
|
&& message.AddMessage("data", fData) == B_OK
|
||||||
(message.AddMessenger("data source", be_app_messenger ) == B_OK) &&
|
&& message.AddMessenger("data source", be_app_messenger) == B_OK
|
||||||
(fClipHandler.SendMessage(&message, &reply) == B_OK) &&
|
&& fClipHandler.SendMessage(&message, &reply) == B_OK
|
||||||
(reply.FindInt32("count",(int32 *)(&fSystemCount)) == B_OK) )
|
&& reply.FindInt32("count", (int32 *)&fSystemCount) == B_OK) {
|
||||||
{
|
fCount++;
|
||||||
fCount++;
|
return B_OK;
|
||||||
return B_OK;
|
}
|
||||||
}
|
return B_ERROR;
|
||||||
return B_ERROR;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user