* Radically culled the list of BApplication friends and introduced a

BApplication::Private class for accessing relevant parts.
* Pulled the app server connection and IK initialization out of
  InitData() into a new method _InitGUIContext() and introduced a private
  constructor that allows to avoid this initialization. This will be used
  for servers that don't have GUI respectively want to init the app server
  connection later.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13312 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2005-06-28 12:55:16 +00:00
parent ecf3bc3eb4
commit c8e7f53e08
5 changed files with 93 additions and 46 deletions
+9 -10
View File
@@ -95,14 +95,11 @@ public:
private: private:
typedef BLooper _inherited; typedef BLooper _inherited;
friend class BWindow; class Private;
friend class BView; friend class Private;
friend class BBitmap;
friend class BScrollBar;
friend class BPrivateScreen;
friend class BPrivate::AppServerLink;
friend void _toggle_handles_(bool);
BApplication(const char* signature, bool initGUI,
status_t* error);
BApplication(uint32 signature); BApplication(uint32 signature);
BApplication(const BApplication&); BApplication(const BApplication&);
BApplication& operator=(const BApplication&); BApplication& operator=(const BApplication&);
@@ -120,14 +117,16 @@ private:
BMessage* specifier, int32 form, BMessage* specifier, int32 form,
const char* property); const char* property);
void run_task(); void run_task();
void InitData(const char* signature, status_t* error); void InitData(const char* signature, bool initGUI,
status_t* error);
void BeginRectTracking(BRect r, bool trackWhole); void BeginRectTracking(BRect r, bool trackWhole);
void EndRectTracking(); void EndRectTracking();
void setup_server_heaps(); status_t setup_server_heaps();
void* rw_offs_to_ptr(uint32 offset); void* rw_offs_to_ptr(uint32 offset);
void* ro_offs_to_ptr(uint32 offset); void* ro_offs_to_ptr(uint32 offset);
void* global_ro_offs_to_ptr(uint32 offset); void* global_ro_offs_to_ptr(uint32 offset);
void connect_to_app_server(); status_t _InitGUIContext();
status_t connect_to_app_server();
void send_drag( BMessage* msg, void send_drag( BMessage* msg,
int32 vs_token, int32 vs_token,
BPoint offset, BPoint offset,
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
*/
#ifndef _APPLICATION_PRIVATE_H
#define _APPLICATION_PRIVATE_H
#include <Application.h>
class BApplication::Private {
public:
static inline status_t InitGUIContext()
{ return be_app->_InitGUIContext(); }
static inline BPrivate::PortLink *ServerLink()
{ return be_app->fServerLink; }
};
#endif // _APPLICATION_PRIVATE_H
+3 -2
View File
@@ -11,6 +11,7 @@
#include <Application.h> #include <Application.h>
#include <Locker.h> #include <Locker.h>
#include <ApplicationPrivate.h>
#include <AppServerLink.h> #include <AppServerLink.h>
@@ -33,8 +34,8 @@ AppServerLink::AppServerLink(void)
// if there is no be_app, we can't do a whole lot, anyway // if there is no be_app, we can't do a whole lot, anyway
if (be_app) { if (be_app) {
fReceiver = &be_app->fServerLink->Receiver(); fReceiver = &BApplication::Private::ServerLink()->Receiver();
fSender = &be_app->fServerLink->Sender(); fSender = &BApplication::Private::ServerLink()->Sender();
} else { } else {
debugger("You need to have a valid app_server connection first!"); debugger("You need to have a valid app_server connection first!");
} }
+56 -33
View File
@@ -161,14 +161,22 @@ 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))
{ {
InitData(signature, NULL); InitData(signature, true, 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))
{ {
InitData(signature, _error); InitData(signature, true, _error);
}
BApplication::BApplication(const char *signature, bool initGUI,
status_t *_error)
: BLooper(looper_name_for(signature))
{
InitData(signature, initGUI, _error);
} }
@@ -180,7 +188,7 @@ BApplication::BApplication(BMessage *data)
const char *signature = NULL; const char *signature = NULL;
data->FindString("mime_sig", &signature); data->FindString("mime_sig", &signature);
InitData(signature, NULL); InitData(signature, true, NULL);
bigtime_t pulseRate; bigtime_t pulseRate;
if (data->FindInt64("_pulse", &pulseRate) == B_OK) if (data->FindInt64("_pulse", &pulseRate) == B_OK)
@@ -233,7 +241,7 @@ BApplication::operator=(const BApplication &rhs)
void void
BApplication::InitData(const char *signature, status_t *_error) BApplication::InitData(const char *signature, bool initGUI, status_t *_error)
{ {
DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error)); DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error));
// check whether there exists already an application // check whether there exists already an application
@@ -385,14 +393,6 @@ BApplication::InitData(const char *signature, status_t *_error)
// TODO: Not completely sure about the order, but this should be close. // TODO: Not completely sure about the order, but this should be close.
#ifndef RUN_WITHOUT_APP_SERVER
// An app_server connection is necessary for a lot of stuff, so get that first.
if (fInitError == B_OK)
connect_to_app_server();
if (fInitError == B_OK)
setup_server_heaps();
#endif // RUN_WITHOUT_APP_SERVER
// init be_app and be_app_messenger // init be_app and be_app_messenger
if (fInitError == B_OK) { if (fInitError == B_OK) {
be_app = this; be_app = this;
@@ -402,6 +402,7 @@ BApplication::InitData(const char *signature, status_t *_error)
// set the BHandler's name // set the BHandler's name
if (fInitError == B_OK) if (fInitError == B_OK)
SetName(ref.name); SetName(ref.name);
// create meta MIME // create meta MIME
if (fInitError == B_OK) { if (fInitError == B_OK) {
BPath path; BPath path;
@@ -410,16 +411,9 @@ BApplication::InitData(const char *signature, status_t *_error)
} }
#ifndef RUN_WITHOUT_APP_SERVER #ifndef RUN_WITHOUT_APP_SERVER
// Initialize the IK after we have set be_app because of a construction of a // app server connection and IK initialization
// AppServerLink (which depends on be_app) nested inside the call to get_menu_info. if (fInitError == B_OK && initGUI)
if (fInitError == B_OK) fInitError = _InitGUIContext();
fInitError = _init_interface_kit_();
// create global system cursors
// ToDo: these could have a predefined server token to safe the communication!
B_CURSOR_SYSTEM_DEFAULT = new BCursor(B_HAND_CURSOR);
B_CURSOR_I_BEAM = new BCursor(B_I_BEAM_CURSOR);
fInitialWorkspace = current_workspace();
#endif // RUN_WITHOUT_APP_SERVER #endif // RUN_WITHOUT_APP_SERVER
// Return the error or exit, if there was an error and no error variable // Return the error or exit, if there was an error and no error variable
@@ -1013,7 +1007,7 @@ BApplication::EndRectTracking()
} }
void status_t
BApplication::setup_server_heaps() BApplication::setup_server_heaps()
{ {
// TODO: implement? // TODO: implement?
@@ -1022,6 +1016,8 @@ BApplication::setup_server_heaps()
// R5 sets up a couple of areas for various tasks having to do with the // R5 sets up a couple of areas for various tasks having to do with the
// app_server. Currently (7/29/04), the R1 app_server does not do this and // app_server. Currently (7/29/04), the R1 app_server does not do this and
// may never do this unless a significant need is found for it. --DW // may never do this unless a significant need is found for it. --DW
return B_OK;
} }
@@ -1046,21 +1042,46 @@ BApplication::global_ro_offs_to_ptr(uint32 offset)
} }
void status_t
BApplication::_InitGUIContext()
{
// An app_server connection is necessary for a lot of stuff, so get that first.
status_t error = connect_to_app_server();
if (error != B_OK)
return error;
error = setup_server_heaps();
if (error != B_OK)
return error;
// Initialize the IK after we have set be_app because of a construction of a
// AppServerLink (which depends on be_app) nested inside the call to get_menu_info.
error = _init_interface_kit_();
if (error != B_OK)
return error;
// create global system cursors
// ToDo: these could have a predefined server token to safe the communication!
B_CURSOR_SYSTEM_DEFAULT = new BCursor(B_HAND_CURSOR);
B_CURSOR_I_BEAM = new BCursor(B_I_BEAM_CURSOR);
fInitialWorkspace = current_workspace();
return B_OK;
}
status_t
BApplication::connect_to_app_server() BApplication::connect_to_app_server()
{ {
port_id serverPort = find_port(SERVER_PORT_NAME); port_id serverPort = find_port(SERVER_PORT_NAME);
if (serverPort < B_OK) { if (serverPort < B_OK)
fInitError = serverPort; return serverPort;
return;
}
// Create the port so that the app_server knows where to send messages // Create the port so that the app_server knows where to send messages
port_id clientPort = create_port(100, "a<app_server"); port_id clientPort = create_port(100, "a<app_server");
if (clientPort < B_OK) { if (clientPort < B_OK)
fInitError = clientPort; return clientPort;
return;
}
// We can't use AppServerLink because be_app == NULL // We can't use AppServerLink because be_app == NULL
@@ -1090,9 +1111,11 @@ BApplication::connect_to_app_server()
fServerLink->SetSenderPort(serverPort); fServerLink->SetSenderPort(serverPort);
} else { } else {
fServerLink->SetSenderPort(-1); fServerLink->SetSenderPort(-1);
fInitError = B_ERROR;
debugger("BApplication: couldn't obtain new app_server comm port"); debugger("BApplication: couldn't obtain new app_server comm port");
return B_ERROR;
} }
return B_OK;
} }
+3 -1
View File
@@ -25,6 +25,7 @@
#include <MessageRunner.h> #include <MessageRunner.h>
#include <Roster.h> #include <Roster.h>
#include <ApplicationPrivate.h>
#include <AppMisc.h> #include <AppMisc.h>
#include <PortLink.h> #include <PortLink.h>
#include <ServerProtocol.h> #include <ServerProtocol.h>
@@ -2058,7 +2059,8 @@ BWindow::InitData(BRect frame, const char* title, window_look look,
STRACE(("BWindow::InitData(): contacting app_server...\n")); STRACE(("BWindow::InitData(): contacting app_server...\n"));
// let app_server to know that a window has been created. // let app_server to know that a window has been created.
fLink = new BPrivate::PortLink(be_app->fServerLink->SenderPort(), receivePort); fLink = new BPrivate::PortLink(
BApplication::Private::ServerLink()->SenderPort(), receivePort);
// HERE we are in BApplication's thread, so for locking we use be_app variable // HERE we are in BApplication's thread, so for locking we use be_app variable
// we'll lock the be_app to be sure we're the only one writing at BApplication's server port // we'll lock the be_app to be sure we're the only one writing at BApplication's server port