2002-07-22 02:40:07 +04:00
|
|
|
// Registrar.cpp
|
|
|
|
|
|
|
|
#include "Debug.h"
|
|
|
|
|
|
|
|
#include <Application.h>
|
|
|
|
#include <Message.h>
|
|
|
|
#include <OS.h>
|
|
|
|
#include <RegistrarDefs.h>
|
|
|
|
|
|
|
|
#include "ClipboardHandler.h"
|
2003-02-02 00:39:22 +03:00
|
|
|
#include "DiskDeviceManager.h"
|
2002-10-13 02:37:07 +04:00
|
|
|
#include "EventQueue.h"
|
2002-10-15 01:19:43 +04:00
|
|
|
#include "MessageEvent.h"
|
2002-10-13 02:37:07 +04:00
|
|
|
#include "MessageRunnerManager.h"
|
2002-07-22 02:40:07 +04:00
|
|
|
#include "MIMEManager.h"
|
|
|
|
#include "Registrar.h"
|
2002-07-24 03:40:12 +04:00
|
|
|
#include "TRoster.h"
|
2002-07-22 02:40:07 +04:00
|
|
|
|
2002-07-28 17:39:26 +04:00
|
|
|
/*!
|
|
|
|
\class Registrar
|
|
|
|
\brief The application class of the registrar.
|
|
|
|
|
|
|
|
Glues the registrar services together and dispatches the roster messages.
|
|
|
|
*/
|
|
|
|
|
2002-10-15 01:19:43 +04:00
|
|
|
//! Name of the event queue.
|
|
|
|
static const char *kEventQueueName = "timer_thread";
|
|
|
|
|
|
|
|
//! Time interval between two roster sanity checks (1 s).
|
|
|
|
static const bigtime_t kRosterSanityEventInterval = 1000000LL;
|
|
|
|
|
2002-07-22 02:40:07 +04:00
|
|
|
// constructor
|
2002-07-28 17:39:26 +04:00
|
|
|
/*! \brief Creates the registrar application class.
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
Registrar::Registrar()
|
|
|
|
: BApplication(kRegistrarSignature),
|
2002-07-24 03:40:12 +04:00
|
|
|
fRoster(NULL),
|
2002-07-22 02:40:07 +04:00
|
|
|
fClipboardHandler(NULL),
|
2002-10-13 02:37:07 +04:00
|
|
|
fMIMEManager(NULL),
|
2003-02-02 00:39:22 +03:00
|
|
|
fDiskDeviceManager(NULL),
|
2002-10-13 02:37:07 +04:00
|
|
|
fEventQueue(NULL),
|
2002-10-15 01:19:43 +04:00
|
|
|
fMessageRunnerManager(NULL),
|
|
|
|
fSanityEvent(NULL)
|
2002-07-22 02:40:07 +04:00
|
|
|
{
|
2002-07-27 00:02:10 +04:00
|
|
|
FUNCTION_START();
|
2002-07-22 02:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// destructor
|
2002-07-28 17:39:26 +04:00
|
|
|
/*! \brief Frees all resources associated with the registrar.
|
|
|
|
|
|
|
|
All registrar services, that haven't been shut down earlier, are
|
|
|
|
terminated.
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
Registrar::~Registrar()
|
|
|
|
{
|
2002-07-27 00:02:10 +04:00
|
|
|
FUNCTION_START();
|
2002-07-28 23:36:05 +04:00
|
|
|
Lock();
|
2002-10-13 02:37:07 +04:00
|
|
|
fEventQueue->Die();
|
|
|
|
delete fMessageRunnerManager;
|
|
|
|
delete fEventQueue;
|
2002-10-15 01:19:43 +04:00
|
|
|
delete fSanityEvent;
|
2003-02-02 00:39:22 +03:00
|
|
|
fDiskDeviceManager->Lock();
|
|
|
|
fDiskDeviceManager->Quit();
|
2002-07-22 02:40:07 +04:00
|
|
|
fMIMEManager->Lock();
|
|
|
|
fMIMEManager->Quit();
|
|
|
|
RemoveHandler(fClipboardHandler);
|
|
|
|
delete fClipboardHandler;
|
2002-07-24 03:40:12 +04:00
|
|
|
delete fRoster;
|
2002-10-15 01:19:43 +04:00
|
|
|
// Invalidate the global be_roster, so that the BApplication destructor
|
|
|
|
// won't dead-lock when sending a message to itself.
|
|
|
|
BPrivate::init_registrar_roster(BMessenger(), BMessenger());
|
2002-07-27 00:02:10 +04:00
|
|
|
FUNCTION_END();
|
2002-07-22 02:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// MessageReceived
|
2002-07-28 17:39:26 +04:00
|
|
|
/*! \brief Overrides the super class version to dispatch roster specific
|
|
|
|
messages.
|
|
|
|
\param message The message to be handled
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
void
|
|
|
|
Registrar::MessageReceived(BMessage *message)
|
|
|
|
{
|
2002-10-15 01:19:43 +04:00
|
|
|
// FUNCTION_START();
|
2002-07-22 02:40:07 +04:00
|
|
|
switch (message->what) {
|
2002-10-13 02:37:07 +04:00
|
|
|
// general requests
|
2002-07-22 02:40:07 +04:00
|
|
|
case B_REG_GET_MIME_MESSENGER:
|
|
|
|
{
|
|
|
|
PRINT(("B_REG_GET_MIME_MESSENGER\n"));
|
|
|
|
BMessenger messenger(NULL, fMIMEManager);
|
|
|
|
BMessage reply(B_REG_SUCCESS);
|
|
|
|
reply.AddMessenger("messenger", messenger);
|
|
|
|
message->SendReply(&reply);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B_REG_GET_CLIPBOARD_MESSENGER:
|
|
|
|
{
|
|
|
|
PRINT(("B_REG_GET_CLIPBOARD_MESSENGER\n"));
|
|
|
|
BMessenger messenger(fClipboardHandler);
|
|
|
|
BMessage reply(B_REG_SUCCESS);
|
|
|
|
reply.AddMessenger("messenger", messenger);
|
|
|
|
message->SendReply(&reply);
|
|
|
|
break;
|
|
|
|
}
|
2003-02-02 00:39:22 +03:00
|
|
|
case B_REG_GET_DISK_DEVICE_MESSENGER:
|
|
|
|
{
|
|
|
|
PRINT(("B_REG_GET_DISK_DEVICE_MESSENGER\n"));
|
|
|
|
BMessenger messenger(NULL, fDiskDeviceManager);
|
|
|
|
BMessage reply(B_REG_SUCCESS);
|
|
|
|
reply.AddMessenger("messenger", messenger);
|
|
|
|
message->SendReply(&reply);
|
|
|
|
break;
|
|
|
|
}
|
2002-10-13 02:37:07 +04:00
|
|
|
// roster requests
|
2002-07-24 03:40:12 +04:00
|
|
|
case B_REG_ADD_APP:
|
|
|
|
fRoster->HandleAddApplication(message);
|
|
|
|
break;
|
|
|
|
case B_REG_COMPLETE_REGISTRATION:
|
|
|
|
fRoster->HandleCompleteRegistration(message);
|
|
|
|
break;
|
2002-07-28 04:26:39 +04:00
|
|
|
case B_REG_IS_APP_PRE_REGISTERED:
|
2002-07-24 03:40:12 +04:00
|
|
|
fRoster->HandleIsAppPreRegistered(message);
|
|
|
|
break;
|
|
|
|
case B_REG_REMOVE_PRE_REGISTERED_APP:
|
|
|
|
fRoster->HandleRemovePreRegApp(message);
|
|
|
|
break;
|
|
|
|
case B_REG_REMOVE_APP:
|
|
|
|
fRoster->HandleRemoveApp(message);
|
|
|
|
break;
|
2002-07-27 00:02:10 +04:00
|
|
|
case B_REG_SET_THREAD_AND_TEAM:
|
|
|
|
fRoster->HandleSetThreadAndTeam(message);
|
|
|
|
break;
|
2002-10-08 02:03:11 +04:00
|
|
|
case B_REG_SET_SIGNATURE:
|
|
|
|
fRoster->HandleSetSignature(message);
|
|
|
|
break;
|
2002-07-28 04:26:39 +04:00
|
|
|
case B_REG_GET_APP_INFO:
|
|
|
|
fRoster->HandleGetAppInfo(message);
|
|
|
|
break;
|
|
|
|
case B_REG_GET_APP_LIST:
|
|
|
|
fRoster->HandleGetAppList(message);
|
|
|
|
break;
|
|
|
|
case B_REG_ACTIVATE_APP:
|
|
|
|
fRoster->HandleActivateApp(message);
|
2002-07-27 00:02:10 +04:00
|
|
|
break;
|
2002-10-16 02:31:55 +04:00
|
|
|
case B_REG_BROADCAST:
|
|
|
|
fRoster->HandleBroadcast(message);
|
|
|
|
break;
|
2002-10-18 18:05:25 +04:00
|
|
|
case B_REG_START_WATCHING:
|
|
|
|
fRoster->HandleStartWatching(message);
|
|
|
|
break;
|
|
|
|
case B_REG_STOP_WATCHING:
|
|
|
|
fRoster->HandleStopWatching(message);
|
2002-10-27 10:50:27 +03:00
|
|
|
break;
|
|
|
|
case B_REG_GET_RECENT_DOCUMENTS:
|
|
|
|
fRoster->HandleGetRecentDocuments(message);
|
|
|
|
break;
|
|
|
|
case B_REG_GET_RECENT_FOLDERS:
|
|
|
|
fRoster->HandleGetRecentFolders(message);
|
|
|
|
break;
|
|
|
|
case B_REG_GET_RECENT_APPS:
|
|
|
|
fRoster->HandleGetRecentApps(message);
|
|
|
|
break;
|
|
|
|
case B_REG_ADD_TO_RECENT_DOCUMENTS:
|
|
|
|
fRoster->HandleAddToRecentDocuments(message);
|
|
|
|
break;
|
|
|
|
case B_REG_ADD_TO_RECENT_FOLDERS:
|
|
|
|
fRoster->HandleAddToRecentFolders(message);
|
|
|
|
break;
|
|
|
|
case B_REG_ADD_TO_RECENT_APPS:
|
|
|
|
fRoster->HandleAddToRecentApps(message);
|
|
|
|
break;
|
|
|
|
case B_REG_CLEAR_RECENT_DOCUMENTS:
|
2002-11-08 11:36:08 +03:00
|
|
|
fRoster->ClearRecentDocuments();
|
2002-10-27 10:50:27 +03:00
|
|
|
break;
|
|
|
|
case B_REG_CLEAR_RECENT_FOLDERS:
|
2002-11-08 11:36:08 +03:00
|
|
|
fRoster->ClearRecentFolders();
|
2002-10-27 10:50:27 +03:00
|
|
|
break;
|
|
|
|
case B_REG_CLEAR_RECENT_APPS:
|
2002-11-08 11:36:08 +03:00
|
|
|
fRoster->ClearRecentApps();
|
|
|
|
break;
|
|
|
|
case B_REG_LOAD_RECENT_LISTS:
|
|
|
|
fRoster->HandleLoadRecentLists(message);
|
|
|
|
break;
|
|
|
|
case B_REG_SAVE_RECENT_LISTS:
|
|
|
|
fRoster->HandleSaveRecentLists(message);
|
2002-10-18 18:05:25 +04:00
|
|
|
break;
|
2002-10-13 02:37:07 +04:00
|
|
|
// message runner requests
|
|
|
|
case B_REG_REGISTER_MESSAGE_RUNNER:
|
|
|
|
fMessageRunnerManager->HandleRegisterRunner(message);
|
|
|
|
break;
|
|
|
|
case B_REG_UNREGISTER_MESSAGE_RUNNER:
|
|
|
|
fMessageRunnerManager->HandleUnregisterRunner(message);
|
|
|
|
break;
|
|
|
|
case B_REG_SET_MESSAGE_RUNNER_PARAMS:
|
|
|
|
fMessageRunnerManager->HandleSetRunnerParams(message);
|
|
|
|
break;
|
|
|
|
case B_REG_GET_MESSAGE_RUNNER_INFO:
|
|
|
|
fMessageRunnerManager->HandleGetRunnerInfo(message);
|
|
|
|
break;
|
2002-10-15 01:19:43 +04:00
|
|
|
// internal messages
|
|
|
|
case B_REG_ROSTER_SANITY_EVENT:
|
|
|
|
fRoster->CheckSanity();
|
|
|
|
fSanityEvent->SetTime(system_time() + kRosterSanityEventInterval);
|
|
|
|
fEventQueue->AddEvent(fSanityEvent);
|
|
|
|
break;
|
2002-07-22 02:40:07 +04:00
|
|
|
default:
|
|
|
|
BApplication::MessageReceived(message);
|
|
|
|
break;
|
|
|
|
}
|
2002-10-15 01:19:43 +04:00
|
|
|
// FUNCTION_END();
|
2002-07-22 02:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadyToRun
|
2002-07-28 17:39:26 +04:00
|
|
|
/*! \brief Overrides the super class version to initialize the registrar
|
|
|
|
services.
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
void
|
|
|
|
Registrar::ReadyToRun()
|
|
|
|
{
|
2002-07-27 00:02:10 +04:00
|
|
|
FUNCTION_START();
|
2002-07-28 23:36:05 +04:00
|
|
|
// create roster
|
2002-07-28 17:39:26 +04:00
|
|
|
fRoster = new TRoster;
|
2002-07-28 23:36:05 +04:00
|
|
|
fRoster->Init();
|
|
|
|
// create clipboard handler
|
2002-07-28 17:39:26 +04:00
|
|
|
fClipboardHandler = new ClipboardHandler;
|
|
|
|
AddHandler(fClipboardHandler);
|
2002-07-28 23:36:05 +04:00
|
|
|
// create MIME manager
|
2002-07-28 17:39:26 +04:00
|
|
|
fMIMEManager = new MIMEManager;
|
|
|
|
fMIMEManager->Run();
|
2003-02-02 00:39:22 +03:00
|
|
|
// create disk device manager
|
|
|
|
fDiskDeviceManager = new DiskDeviceManager;
|
|
|
|
fDiskDeviceManager->Run();
|
2002-10-13 02:37:07 +04:00
|
|
|
// create message runner manager
|
|
|
|
fEventQueue = new EventQueue(kEventQueueName);
|
|
|
|
fMessageRunnerManager = new MessageRunnerManager(fEventQueue);
|
2002-09-23 23:46:15 +04:00
|
|
|
// init the global be_roster
|
|
|
|
BPrivate::init_registrar_roster(be_app_messenger,
|
|
|
|
BMessenger(NULL, fMIMEManager));
|
2002-10-15 01:19:43 +04:00
|
|
|
// create and schedule the sanity message event
|
|
|
|
fSanityEvent = new MessageEvent(system_time() + kRosterSanityEventInterval,
|
|
|
|
this, B_REG_ROSTER_SANITY_EVENT);
|
|
|
|
fSanityEvent->SetAutoDelete(false);
|
|
|
|
fEventQueue->AddEvent(fSanityEvent);
|
2002-07-28 17:39:26 +04:00
|
|
|
FUNCTION_END();
|
2002-07-22 02:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// QuitRequested
|
2002-07-28 17:39:26 +04:00
|
|
|
/*! \brief Overrides the super class version to avoid termination of the
|
|
|
|
registrar until the system shutdown.
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
bool
|
|
|
|
Registrar::QuitRequested()
|
|
|
|
{
|
2002-07-27 00:02:10 +04:00
|
|
|
FUNCTION_START();
|
2002-07-22 02:40:07 +04:00
|
|
|
// The final registrar must not quit. At least not that easily. ;-)
|
|
|
|
return BApplication::QuitRequested();
|
|
|
|
}
|
|
|
|
|
2002-10-15 01:19:43 +04:00
|
|
|
// GetEventQueue
|
|
|
|
/*! \brief Returns the registrar's event queue.
|
|
|
|
\return The registrar's event queue.
|
|
|
|
*/
|
|
|
|
EventQueue*
|
|
|
|
Registrar::GetEventQueue() const
|
|
|
|
{
|
|
|
|
return fEventQueue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// App
|
|
|
|
/*! \brief Returns the Registrar application object.
|
|
|
|
\return The Registrar application object.
|
|
|
|
*/
|
|
|
|
Registrar*
|
|
|
|
Registrar::App()
|
|
|
|
{
|
|
|
|
return dynamic_cast<Registrar*>(be_app);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-23 23:46:15 +04:00
|
|
|
// init_registrar_roster
|
|
|
|
/*! \brief Initializes the global \a be_roster.
|
|
|
|
|
|
|
|
While this is done automagically for all other applications while libbe
|
|
|
|
initialization, the registrar needs to help out a bit.
|
|
|
|
|
|
|
|
\param mainMessenger A BMessenger targeting the registrar application.
|
|
|
|
\param mimeMessenger A BMessenger targeting the MIME manager.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
BPrivate::init_registrar_roster(BMessenger mainMessenger,
|
|
|
|
BMessenger mimeMessenger)
|
|
|
|
{
|
|
|
|
BRoster *roster = const_cast<BRoster*>(be_roster);
|
|
|
|
roster->fMess = mainMessenger;
|
|
|
|
roster->fMimeMess = mimeMessenger;
|
|
|
|
}
|
|
|
|
|
2002-07-22 02:40:07 +04:00
|
|
|
|
|
|
|
// main
|
2002-07-28 17:39:26 +04:00
|
|
|
/*! \brief Creates and runs the registrar application.
|
|
|
|
|
|
|
|
The main thread is renamed.
|
|
|
|
|
|
|
|
\return 0.
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
2002-07-27 00:02:10 +04:00
|
|
|
FUNCTION_START();
|
2002-07-22 02:40:07 +04:00
|
|
|
// rename the main thread
|
|
|
|
rename_thread(find_thread(NULL), kRosterThreadName);
|
|
|
|
// create and run the registrar application
|
|
|
|
Registrar *app = new Registrar();
|
|
|
|
PRINT(("app->Run()...\n"));
|
|
|
|
app->Run();
|
|
|
|
PRINT(("delete app...\n"));
|
|
|
|
delete app;
|
2002-07-27 00:02:10 +04:00
|
|
|
FUNCTION_END();
|
2002-07-22 02:40:07 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|