Moved the unmaintainable list of initializers for the different constructors

to InitData(). Also fixed the initial value of fPulseRate (was 500000 but
according to the BeBook, it should have been 0).
Implemented SetPulseRate() (untested, but should be okay).
Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10499 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-12-20 11:09:56 +00:00
parent 1d34350c71
commit af34fbf1c5
+54 -48
View File
@@ -36,6 +36,7 @@
#include <AppFileInfo.h> #include <AppFileInfo.h>
#include <Application.h> #include <Application.h>
#include <AppMisc.h> #include <AppMisc.h>
#include <MessageRunner.h>
#include <Cursor.h> #include <Cursor.h>
#include <Debug.h> #include <Debug.h>
#include <Entry.h> #include <Entry.h>
@@ -191,36 +192,16 @@ static void fill_argv_message(BMessage *message);
BApplication::BApplication(const char *signature) BApplication::BApplication(const char *signature)
: BLooper(looper_name_for(signature)), : BLooper(looper_name_for(signature))
fAppName(NULL),
fServerFrom(-1),
fServerTo(-1),
fServerHeap(NULL),
fPulseRate(500000),
fInitialWorkspace(0),
fDraggedMessage(NULL),
fPulseRunner(NULL),
fInitError(B_NO_INIT),
fReadyToRunCalled(false)
{ {
InitData(signature, NULL); InitData(signature, NULL);
} }
BApplication::BApplication(const char* signature, status_t* error) BApplication::BApplication(const char *signature, status_t *_error)
: BLooper(looper_name_for(signature)), : BLooper(looper_name_for(signature))
fAppName(NULL),
fServerFrom(-1),
fServerTo(-1),
fServerHeap(NULL),
fPulseRate(500000),
fInitialWorkspace(0),
fDraggedMessage(NULL),
fPulseRunner(NULL),
fInitError(B_NO_INIT),
fReadyToRunCalled(false)
{ {
InitData(signature, error); InitData(signature, _error);
} }
@@ -241,11 +222,9 @@ BApplication::~BApplication()
gLooperList.GetLooperList(&looperList); gLooperList.GetLooperList(&looperList);
} }
for (int32 i = 0; i < looperList.CountItems(); i++) for (int32 i = 0; i < looperList.CountItems(); i++) {
{
window = dynamic_cast<BWindow*>((BLooper*)looperList.ItemAt(i)); window = dynamic_cast<BWindow*>((BLooper*)looperList.ItemAt(i));
if (window) if (window) {
{
window->Lock(); window->Lock();
window->Quit(); window->Quit();
} }
@@ -272,17 +251,7 @@ BApplication::~BApplication()
BApplication::BApplication(BMessage *data) BApplication::BApplication(BMessage *data)
// Note: BeOS calls the private BLooper(int32, port_id, const char *) // Note: BeOS calls the private BLooper(int32, port_id, const char *)
// constructor here, test if it's needed // constructor here, test if it's needed
: BLooper(looper_name_for(NULL)), : BLooper(looper_name_for(NULL))
fAppName(NULL),
fServerFrom(-1),
fServerTo(-1),
fServerHeap(NULL),
fPulseRate(500000),
fInitialWorkspace(0),
fDraggedMessage(NULL),
fPulseRunner(NULL),
fInitError(B_NO_INIT),
fReadyToRunCalled(false)
{ {
const char *signature = NULL; const char *signature = NULL;
data->FindString("mime_sig", &signature); data->FindString("mime_sig", &signature);
@@ -754,8 +723,30 @@ BApplication::DispatchMessage(BMessage *message, BHandler *handler)
void void
BApplication::SetPulseRate(bigtime_t rate) BApplication::SetPulseRate(bigtime_t rate)
{ {
// ToDo: implement pulse runner! if (rate < 0)
rate = 0;
// BeBook states that we have only 100,000 microseconds granularity
rate -= rate % 100000;
if (!Lock())
return;
if (rate != 0) {
// reset existing pulse runner, or create new one
if (fPulseRunner == NULL) {
BMessage pulse(B_PULSE);
fPulseRunner = new BMessageRunner(be_app_messenger, &pulse, rate);
} else
fPulseRunner->SetInterval(rate);
} else {
// turn off pulse messages
delete fPulseRunner;
fPulseRunner = NULL;
}
fPulseRate = rate; fPulseRate = rate;
Unlock();
} }
@@ -794,7 +785,8 @@ BApplication::BApplication(const BApplication& rhs)
} }
BApplication& BApplication::operator=(const BApplication& rhs) BApplication &
BApplication::operator=(const BApplication &rhs)
{ {
return *this; return *this;
} }
@@ -840,21 +832,34 @@ BApplication::InitData(const char *signature, status_t *error)
// check whether there exists already an application // check whether there exists already an application
if (be_app) if (be_app)
debugger("2 BApplication objects were created. Only one is allowed."); debugger("2 BApplication objects were created. Only one is allowed.");
fServerFrom = fServerTo = -1;
fServerHeap = NULL;
fInitialWorkspace = 0;
fDraggedMessage = NULL;
fReadyToRunCalled = false;
// initially, there is no pulse
fPulseRunner = NULL;
fPulseRate = 0;
// check signature // check signature
fInitError = check_app_signature(signature); fInitError = check_app_signature(signature);
fAppName = signature; fAppName = signature;
#ifndef RUN_WITHOUT_REGISTRAR #ifndef RUN_WITHOUT_REGISTRAR
bool isRegistrar bool isRegistrar = signature
= (signature && !strcasecmp(signature, kRegistrarSignature)); && !strcasecmp(signature, kRegistrarSignature);
// get team and thread // get team and thread
team_id team = Team(); team_id team = Team();
thread_id thread = BPrivate::main_thread_for(team); thread_id thread = BPrivate::main_thread_for(team);
#endif #endif
// get app executable ref // get app executable ref
entry_ref ref; entry_ref ref;
if (fInitError == B_OK) if (fInitError == B_OK)
fInitError = BPrivate::get_app_ref(&ref); fInitError = BPrivate::get_app_ref(&ref);
// get the BAppFileInfo and extract the information we need // get the BAppFileInfo and extract the information we need
uint32 appFlags = B_REG_DEFAULT_APP_FLAGS; uint32 appFlags = B_REG_DEFAULT_APP_FLAGS;
if (fInitError == B_OK) { if (fInitError == B_OK) {
@@ -865,14 +870,14 @@ BApplication::InitData(const char *signature, status_t *error)
fileInfo.GetAppFlags(&appFlags); fileInfo.GetAppFlags(&appFlags);
char appFileSignature[B_MIME_TYPE_LENGTH + 1]; char appFileSignature[B_MIME_TYPE_LENGTH + 1];
// compare the file signature and the supplied signature // compare the file signature and the supplied signature
if (fileInfo.GetSignature(appFileSignature) == B_OK) { if (fileInfo.GetSignature(appFileSignature) == B_OK
if (strcasecmp(appFileSignature, signature) != 0) { && strcasecmp(appFileSignature, signature) != 0) {
printf("Signature in rsrc doesn't match constructor arg. " printf("Signature in rsrc doesn't match constructor arg. (%s, %s)\n",
"(%s,%s)\n", signature, appFileSignature); signature, appFileSignature);
}
} }
} }
} }
#ifndef RUN_WITHOUT_REGISTRAR #ifndef RUN_WITHOUT_REGISTRAR
// check whether be_roster is valid // check whether be_roster is valid
if (fInitError == B_OK && !isRegistrar if (fInitError == B_OK && !isRegistrar
@@ -980,6 +985,7 @@ BApplication::InitData(const char *signature, status_t *error)
if (fInitError == B_OK) if (fInitError == B_OK)
fInitError = _init_interface_kit_(); fInitError = _init_interface_kit_();
#endif // RUN_WITHOUT_APP_SERVER #endif // RUN_WITHOUT_APP_SERVER
// set the BHandler's name // set the BHandler's name
if (fInitError == B_OK) if (fInitError == B_OK)
SetName(ref.name); SetName(ref.name);