From c8e7f53e08c32deb27f14d18a2dbf8b58f309b64 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 28 Jun 2005 12:55:16 +0000 Subject: [PATCH] * 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 --- headers/os/app/Application.h | 19 +++-- headers/private/app/ApplicationPrivate.h | 22 ++++++ src/kits/app/AppServerLink.cpp | 5 +- src/kits/app/Application.cpp | 89 +++++++++++++++--------- src/kits/interface/Window.cpp | 4 +- 5 files changed, 93 insertions(+), 46 deletions(-) create mode 100644 headers/private/app/ApplicationPrivate.h diff --git a/headers/os/app/Application.h b/headers/os/app/Application.h index db587795f7..87db695632 100644 --- a/headers/os/app/Application.h +++ b/headers/os/app/Application.h @@ -95,14 +95,11 @@ public: private: typedef BLooper _inherited; - friend class BWindow; - friend class BView; - friend class BBitmap; - friend class BScrollBar; - friend class BPrivateScreen; - friend class BPrivate::AppServerLink; - friend void _toggle_handles_(bool); + class Private; + friend class Private; + BApplication(const char* signature, bool initGUI, + status_t* error); BApplication(uint32 signature); BApplication(const BApplication&); BApplication& operator=(const BApplication&); @@ -120,14 +117,16 @@ private: BMessage* specifier, int32 form, const char* property); 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 EndRectTracking(); - void setup_server_heaps(); + status_t setup_server_heaps(); void* rw_offs_to_ptr(uint32 offset); void* 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, int32 vs_token, BPoint offset, diff --git a/headers/private/app/ApplicationPrivate.h b/headers/private/app/ApplicationPrivate.h new file mode 100644 index 0000000000..5005ae043d --- /dev/null +++ b/headers/private/app/ApplicationPrivate.h @@ -0,0 +1,22 @@ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ingo Weinhold + */ +#ifndef _APPLICATION_PRIVATE_H +#define _APPLICATION_PRIVATE_H + +#include + +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 diff --git a/src/kits/app/AppServerLink.cpp b/src/kits/app/AppServerLink.cpp index e3bd35fa04..64316bdf03 100644 --- a/src/kits/app/AppServerLink.cpp +++ b/src/kits/app/AppServerLink.cpp @@ -11,6 +11,7 @@ #include #include +#include #include @@ -33,8 +34,8 @@ AppServerLink::AppServerLink(void) // if there is no be_app, we can't do a whole lot, anyway if (be_app) { - fReceiver = &be_app->fServerLink->Receiver(); - fSender = &be_app->fServerLink->Sender(); + fReceiver = &BApplication::Private::ServerLink()->Receiver(); + fSender = &BApplication::Private::ServerLink()->Sender(); } else { debugger("You need to have a valid app_server connection first!"); } diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index df662f9323..4c51df8f46 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -161,14 +161,22 @@ static void fill_argv_message(BMessage &message); BApplication::BApplication(const char *signature) : BLooper(looper_name_for(signature)) { - InitData(signature, NULL); + InitData(signature, true, NULL); } BApplication::BApplication(const char *signature, status_t *_error) : 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; data->FindString("mime_sig", &signature); - InitData(signature, NULL); + InitData(signature, true, NULL); bigtime_t pulseRate; if (data->FindInt64("_pulse", &pulseRate) == B_OK) @@ -233,7 +241,7 @@ BApplication::operator=(const BApplication &rhs) 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)); // 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. -#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 if (fInitError == B_OK) { be_app = this; @@ -402,6 +402,7 @@ BApplication::InitData(const char *signature, status_t *_error) // set the BHandler's name if (fInitError == B_OK) SetName(ref.name); + // create meta MIME if (fInitError == B_OK) { BPath path; @@ -410,16 +411,9 @@ BApplication::InitData(const char *signature, status_t *_error) } #ifndef RUN_WITHOUT_APP_SERVER - // 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. - if (fInitError == B_OK) - 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(); + // app server connection and IK initialization + if (fInitError == B_OK && initGUI) + fInitError = _InitGUIContext(); #endif // RUN_WITHOUT_APP_SERVER // 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() { // 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 // 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 + + 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() { port_id serverPort = find_port(SERVER_PORT_NAME); - if (serverPort < B_OK) { - fInitError = serverPort; - return; - } + if (serverPort < B_OK) + return serverPort; // Create the port so that the app_server knows where to send messages port_id clientPort = create_port(100, "aSetSenderPort(serverPort); } else { fServerLink->SetSenderPort(-1); - fInitError = B_ERROR; debugger("BApplication: couldn't obtain new app_server comm port"); + return B_ERROR; } + + return B_OK; } diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 6a454f5c90..3cc206488e 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -2058,7 +2059,8 @@ BWindow::InitData(BRect frame, const char* title, window_look look, STRACE(("BWindow::InitData(): contacting app_server...\n")); // 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 // we'll lock the be_app to be sure we're the only one writing at BApplication's server port