Reordered the functions (private -> public). No functional change.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25637 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005, Ingo Weinhold, [email protected]. All rights reserved.
|
* Copyright 2005-2008, Ingo Weinhold, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -22,124 +22,23 @@
|
|||||||
# define PRINT(x) ;
|
# define PRINT(x) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static MessagingService *sMessagingService = NULL;
|
static MessagingService *sMessagingService = NULL;
|
||||||
|
|
||||||
static const int32 kMessagingAreaSize = B_PAGE_SIZE * 4;
|
static const int32 kMessagingAreaSize = B_PAGE_SIZE * 4;
|
||||||
|
|
||||||
// init_messaging_service
|
|
||||||
status_t
|
|
||||||
init_messaging_service()
|
|
||||||
{
|
|
||||||
static char buffer[sizeof(MessagingService)];
|
|
||||||
|
|
||||||
if (!sMessagingService)
|
// #pragma mark - MessagingArea
|
||||||
sMessagingService = new(buffer) MessagingService;
|
|
||||||
|
|
||||||
status_t error = sMessagingService->InitCheck();
|
|
||||||
|
|
||||||
// cleanup on error
|
|
||||||
if (error != B_OK) {
|
|
||||||
dprintf("ERROR: Failed to init messaging service: %s\n",
|
|
||||||
strerror(error));
|
|
||||||
sMessagingService->~MessagingService();
|
|
||||||
sMessagingService = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// _user_register_messaging_service
|
|
||||||
/** \brief Called by the userland server to register itself as a messaging
|
|
||||||
service for the kernel.
|
|
||||||
\param lockingSem A semaphore used for locking the shared data. Semaphore
|
|
||||||
counter must be initialized to 0.
|
|
||||||
\param counterSem A semaphore released every time the kernel pushes a
|
|
||||||
command into an empty area. Semaphore counter must be initialized
|
|
||||||
to 0.
|
|
||||||
\return
|
|
||||||
- The ID of the kernel area used for communication, if everything went fine,
|
|
||||||
- an error code otherwise.
|
|
||||||
*/
|
|
||||||
area_id
|
|
||||||
_user_register_messaging_service(sem_id lockSem, sem_id counterSem)
|
|
||||||
{
|
|
||||||
// check, if init_messaging_service() has been called yet
|
|
||||||
if (!sMessagingService)
|
|
||||||
return B_NO_INIT;
|
|
||||||
|
|
||||||
if (!sMessagingService->Lock())
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
area_id areaID;
|
|
||||||
status_t error = sMessagingService->RegisterService(lockSem, counterSem,
|
|
||||||
areaID);
|
|
||||||
|
|
||||||
sMessagingService->Unlock();
|
|
||||||
|
|
||||||
return (error != B_OK ? error : areaID);
|
|
||||||
}
|
|
||||||
|
|
||||||
// _user_unregister_messaging_service
|
|
||||||
status_t
|
|
||||||
_user_unregister_messaging_service()
|
|
||||||
{
|
|
||||||
// check, if init_messaging_service() has been called yet
|
|
||||||
if (!sMessagingService)
|
|
||||||
return B_NO_INIT;
|
|
||||||
|
|
||||||
if (!sMessagingService->Lock())
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
status_t error = sMessagingService->UnregisterService();
|
|
||||||
|
|
||||||
sMessagingService->Unlock();
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// send_message
|
|
||||||
status_t
|
|
||||||
send_message(const void *message, int32 messageSize,
|
|
||||||
const messaging_target *targets, int32 targetCount)
|
|
||||||
{
|
|
||||||
// check, if init_messaging_service() has been called yet
|
|
||||||
if (!sMessagingService)
|
|
||||||
return B_NO_INIT;
|
|
||||||
|
|
||||||
if (!sMessagingService->Lock())
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
status_t error = sMessagingService->SendMessage(message, messageSize,
|
|
||||||
targets, targetCount);
|
|
||||||
|
|
||||||
sMessagingService->Unlock();
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// send_message
|
|
||||||
status_t
|
|
||||||
send_message(const KMessage *message, const messaging_target *targets,
|
|
||||||
int32 targetCount)
|
|
||||||
{
|
|
||||||
if (!message)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
return send_message(message->Buffer(), message->ContentSize(), targets,
|
|
||||||
targetCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
MessagingArea::MessagingArea()
|
MessagingArea::MessagingArea()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
MessagingArea::~MessagingArea()
|
MessagingArea::~MessagingArea()
|
||||||
{
|
{
|
||||||
@@ -147,6 +46,7 @@ MessagingArea::~MessagingArea()
|
|||||||
delete_area(fID);
|
delete_area(fID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
MessagingArea *
|
MessagingArea *
|
||||||
MessagingArea::Create(sem_id lockSem, sem_id counterSem)
|
MessagingArea::Create(sem_id lockSem, sem_id counterSem)
|
||||||
@@ -175,6 +75,7 @@ MessagingArea::Create(sem_id lockSem, sem_id counterSem)
|
|||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// InitHeader
|
// InitHeader
|
||||||
void
|
void
|
||||||
MessagingArea::InitHeader()
|
MessagingArea::InitHeader()
|
||||||
@@ -188,6 +89,7 @@ MessagingArea::InitHeader()
|
|||||||
fHeader->last_command = 0;
|
fHeader->last_command = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// CheckCommandSize
|
// CheckCommandSize
|
||||||
bool
|
bool
|
||||||
MessagingArea::CheckCommandSize(int32 dataSize)
|
MessagingArea::CheckCommandSize(int32 dataSize)
|
||||||
@@ -198,6 +100,7 @@ MessagingArea::CheckCommandSize(int32 dataSize)
|
|||||||
&& size <= kMessagingAreaSize - (int32)sizeof(messaging_area_header));
|
&& size <= kMessagingAreaSize - (int32)sizeof(messaging_area_header));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Lock
|
// Lock
|
||||||
bool
|
bool
|
||||||
MessagingArea::Lock()
|
MessagingArea::Lock()
|
||||||
@@ -209,6 +112,7 @@ MessagingArea::Lock()
|
|||||||
return (acquire_sem(fLockSem) == B_OK);
|
return (acquire_sem(fLockSem) == B_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Unlock
|
// Unlock
|
||||||
void
|
void
|
||||||
MessagingArea::Unlock()
|
MessagingArea::Unlock()
|
||||||
@@ -217,6 +121,7 @@ MessagingArea::Unlock()
|
|||||||
release_sem(fLockSem);
|
release_sem(fLockSem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
area_id
|
area_id
|
||||||
MessagingArea::ID() const
|
MessagingArea::ID() const
|
||||||
@@ -224,6 +129,7 @@ MessagingArea::ID() const
|
|||||||
return fID;
|
return fID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
int32
|
int32
|
||||||
MessagingArea::Size() const
|
MessagingArea::Size() const
|
||||||
@@ -231,6 +137,7 @@ MessagingArea::Size() const
|
|||||||
return fSize;
|
return fSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// AllocateCommand
|
// AllocateCommand
|
||||||
void *
|
void *
|
||||||
MessagingArea::AllocateCommand(uint32 commandWhat, int32 dataSize,
|
MessagingArea::AllocateCommand(uint32 commandWhat, int32 dataSize,
|
||||||
@@ -302,6 +209,7 @@ MessagingArea::AllocateCommand(uint32 commandWhat, int32 dataSize,
|
|||||||
return command->data;
|
return command->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// CommitCommand
|
// CommitCommand
|
||||||
void
|
void
|
||||||
MessagingArea::CommitCommand()
|
MessagingArea::CommitCommand()
|
||||||
@@ -310,6 +218,7 @@ MessagingArea::CommitCommand()
|
|||||||
release_sem(fCounterSem);
|
release_sem(fCounterSem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetNextArea
|
// SetNextArea
|
||||||
void
|
void
|
||||||
MessagingArea::SetNextArea(MessagingArea *area)
|
MessagingArea::SetNextArea(MessagingArea *area)
|
||||||
@@ -318,6 +227,7 @@ MessagingArea::SetNextArea(MessagingArea *area)
|
|||||||
fHeader->next_kernel_area = (fNextArea ? fNextArea->ID() : -1);
|
fHeader->next_kernel_area = (fNextArea ? fNextArea->ID() : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NextArea
|
// NextArea
|
||||||
MessagingArea *
|
MessagingArea *
|
||||||
MessagingArea::NextArea() const
|
MessagingArea::NextArea() const
|
||||||
@@ -325,6 +235,7 @@ MessagingArea::NextArea() const
|
|||||||
return fNextArea;
|
return fNextArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _CheckCommand
|
// _CheckCommand
|
||||||
messaging_command *
|
messaging_command *
|
||||||
MessagingArea::_CheckCommand(int32 offset, int32 &size)
|
MessagingArea::_CheckCommand(int32 offset, int32 &size)
|
||||||
@@ -349,7 +260,8 @@ MessagingArea::_CheckCommand(int32 offset, int32 &size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark - MessagingService
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
MessagingService::MessagingService()
|
MessagingService::MessagingService()
|
||||||
@@ -359,6 +271,7 @@ MessagingService::MessagingService()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
MessagingService::~MessagingService()
|
MessagingService::~MessagingService()
|
||||||
{
|
{
|
||||||
@@ -366,6 +279,7 @@ MessagingService::~MessagingService()
|
|||||||
// bitter end.
|
// bitter end.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// InitCheck
|
// InitCheck
|
||||||
status_t
|
status_t
|
||||||
MessagingService::InitCheck() const
|
MessagingService::InitCheck() const
|
||||||
@@ -375,6 +289,7 @@ MessagingService::InitCheck() const
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Lock
|
// Lock
|
||||||
bool
|
bool
|
||||||
MessagingService::Lock()
|
MessagingService::Lock()
|
||||||
@@ -382,6 +297,7 @@ MessagingService::Lock()
|
|||||||
return fLock.Lock();
|
return fLock.Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Unlock
|
// Unlock
|
||||||
void
|
void
|
||||||
MessagingService::Unlock()
|
MessagingService::Unlock()
|
||||||
@@ -389,6 +305,7 @@ MessagingService::Unlock()
|
|||||||
fLock.Unlock();
|
fLock.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// RegisterService
|
// RegisterService
|
||||||
status_t
|
status_t
|
||||||
MessagingService::RegisterService(sem_id lockSem, sem_id counterSem,
|
MessagingService::RegisterService(sem_id lockSem, sem_id counterSem,
|
||||||
@@ -436,6 +353,7 @@ MessagingService::RegisterService(sem_id lockSem, sem_id counterSem,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// UnregisterService
|
// UnregisterService
|
||||||
status_t
|
status_t
|
||||||
MessagingService::UnregisterService()
|
MessagingService::UnregisterService()
|
||||||
@@ -465,6 +383,7 @@ MessagingService::UnregisterService()
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SendMessage
|
// SendMessage
|
||||||
status_t
|
status_t
|
||||||
MessagingService::SendMessage(const void *message, int32 messageSize,
|
MessagingService::SendMessage(const void *message, int32 messageSize,
|
||||||
@@ -508,6 +427,7 @@ PRINT((" Allocated space for send message command: area: %p, data: %p, "
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _AllocateCommand
|
// _AllocateCommand
|
||||||
status_t
|
status_t
|
||||||
MessagingService::_AllocateCommand(int32 commandWhat, int32 size,
|
MessagingService::_AllocateCommand(int32 commandWhat, int32 size,
|
||||||
@@ -580,3 +500,116 @@ MessagingService::_AllocateCommand(int32 commandWhat, int32 size,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - kernel private
|
||||||
|
|
||||||
|
|
||||||
|
// send_message
|
||||||
|
status_t
|
||||||
|
send_message(const void *message, int32 messageSize,
|
||||||
|
const messaging_target *targets, int32 targetCount)
|
||||||
|
{
|
||||||
|
// check, if init_messaging_service() has been called yet
|
||||||
|
if (!sMessagingService)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
if (!sMessagingService->Lock())
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
status_t error = sMessagingService->SendMessage(message, messageSize,
|
||||||
|
targets, targetCount);
|
||||||
|
|
||||||
|
sMessagingService->Unlock();
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// send_message
|
||||||
|
status_t
|
||||||
|
send_message(const KMessage *message, const messaging_target *targets,
|
||||||
|
int32 targetCount)
|
||||||
|
{
|
||||||
|
if (!message)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
return send_message(message->Buffer(), message->ContentSize(), targets,
|
||||||
|
targetCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// init_messaging_service
|
||||||
|
status_t
|
||||||
|
init_messaging_service()
|
||||||
|
{
|
||||||
|
static char buffer[sizeof(MessagingService)];
|
||||||
|
|
||||||
|
if (!sMessagingService)
|
||||||
|
sMessagingService = new(buffer) MessagingService;
|
||||||
|
|
||||||
|
status_t error = sMessagingService->InitCheck();
|
||||||
|
|
||||||
|
// cleanup on error
|
||||||
|
if (error != B_OK) {
|
||||||
|
dprintf("ERROR: Failed to init messaging service: %s\n",
|
||||||
|
strerror(error));
|
||||||
|
sMessagingService->~MessagingService();
|
||||||
|
sMessagingService = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - syscalls
|
||||||
|
|
||||||
|
|
||||||
|
// _user_register_messaging_service
|
||||||
|
/** \brief Called by the userland server to register itself as a messaging
|
||||||
|
service for the kernel.
|
||||||
|
\param lockingSem A semaphore used for locking the shared data. Semaphore
|
||||||
|
counter must be initialized to 0.
|
||||||
|
\param counterSem A semaphore released every time the kernel pushes a
|
||||||
|
command into an empty area. Semaphore counter must be initialized
|
||||||
|
to 0.
|
||||||
|
\return
|
||||||
|
- The ID of the kernel area used for communication, if everything went fine,
|
||||||
|
- an error code otherwise.
|
||||||
|
*/
|
||||||
|
area_id
|
||||||
|
_user_register_messaging_service(sem_id lockSem, sem_id counterSem)
|
||||||
|
{
|
||||||
|
// check, if init_messaging_service() has been called yet
|
||||||
|
if (!sMessagingService)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
if (!sMessagingService->Lock())
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
area_id areaID;
|
||||||
|
status_t error = sMessagingService->RegisterService(lockSem, counterSem,
|
||||||
|
areaID);
|
||||||
|
|
||||||
|
sMessagingService->Unlock();
|
||||||
|
|
||||||
|
return (error != B_OK ? error : areaID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// _user_unregister_messaging_service
|
||||||
|
status_t
|
||||||
|
_user_unregister_messaging_service()
|
||||||
|
{
|
||||||
|
// check, if init_messaging_service() has been called yet
|
||||||
|
if (!sMessagingService)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
if (!sMessagingService->Lock())
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
status_t error = sMessagingService->UnregisterService();
|
||||||
|
|
||||||
|
sMessagingService->Unlock();
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user