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"
|
|
|
|
#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-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),
|
|
|
|
fMIMEManager(NULL)
|
|
|
|
{
|
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-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-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-07-27 00:02:10 +04:00
|
|
|
FUNCTION_START();
|
2002-07-22 02:40:07 +04:00
|
|
|
switch (message->what) {
|
|
|
|
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;
|
|
|
|
}
|
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-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-07-22 02:40:07 +04:00
|
|
|
default:
|
|
|
|
BApplication::MessageReceived(message);
|
|
|
|
break;
|
|
|
|
}
|
2002-07-27 00:02:10 +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();
|
2002-09-23 23:46:15 +04:00
|
|
|
// init the global be_roster
|
|
|
|
BPrivate::init_registrar_roster(be_app_messenger,
|
|
|
|
BMessenger(NULL, fMIMEManager));
|
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-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;
|
|
|
|
}
|
|
|
|
|