[haiku-commits] haiku: hrev49682 - in src/servers: print launch

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 13 Oct 2015 17:25:07 +0200 (CEST)

hrev49682 adds 4 changesets to branch 'master'
old head: aaac25441d0161e897d1ec92291e50c64747828f
new head: 37e5a036605931f55d82e971f8ab99c48023a5c4
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=37e5a0366059+%5Eaaac25441d01

----------------------------------------------------------------------------

6c3e186cebca: print_server: minor coding style cleanup.

74b10f8e82c6: print_server: No need to build on BeOS.

e048384d7784: launch_daemon: launching on demand now actually works.

* Was broken in two ways: if only the shortcut "on_demand" was used,
the event didn't get created at all due to a bug in
Events::AddOnDemand().
* Furthermore, _LaunchJob() always triggered a demand, but it should
only do this when not called from a target.

37e5a0366059: print_server: Converted to launch_daemon, run on demand only.

* Seems to work fine, although it should probably also be triggered when
there are still jobs in the queue -- someone more knowledgeable might
want to chime in here, please :-)
* If this turns out to be problematic, we can just drop the "on_demand"
job config again.

[ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

7 files changed, 209 insertions(+), 274 deletions(-)
data/launch/system | 2 +-
src/servers/launch/Events.cpp | 10 +-
src/servers/launch/Events.h | 2 +-
src/servers/launch/LaunchDaemon.cpp | 26 ++-
src/servers/print/Jamfile | 2 +-
src/servers/print/PrintServerApp.cpp | 319 ++++++++++++-------------------
src/servers/print/PrintServerApp.h | 122 ++++++------

############################################################################

Commit: 6c3e186cebca576ff69d04e68c5cb462e1e819f0
URL: http://cgit.haiku-os.org/haiku/commit/?id=6c3e186cebca
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Mon Oct 12 18:52:58 2015 UTC

print_server: minor coding style cleanup.

----------------------------------------------------------------------------

diff --git a/src/servers/print/PrintServerApp.cpp
b/src/servers/print/PrintServerApp.cpp
index 34bc22b..a1354cd 100644
--- a/src/servers/print/PrintServerApp.cpp
+++ b/src/servers/print/PrintServerApp.cpp
@@ -1,19 +1,18 @@
/*
- * Copyright 2001-2010, Haiku, Inc. All rights reserved.
+ * Copyright 2001-2015, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ithamar R. Adema
* Michael Pfeiffer
*/
+
+
#include "PrintServerApp.h"

-#include "BeUtils.h"
-#include "Printer.h"
-#include "pr_server.h"
-#include "Transport.h"
+#include <stdio.h>
+#include <unistd.h>

-// BeOS API
#include <Alert.h>
#include <Autolock.h>
#include <Catalog.h>
@@ -30,11 +29,10 @@
#include <PrintJob.h>
#include <String.h>

-// ANSI C
-#include <stdio.h>
- // for printf
-#include <unistd.h>
- // for unlink
+#include "BeUtils.h"
+#include "Printer.h"
+#include "pr_server.h"
+#include "Transport.h"


#undef B_TRANSLATION_CONTEXT
@@ -46,45 +44,42 @@ typedef struct _printer_data {
} printer_data_t;


-
static const char* kSettingsName = "print_server_settings";

-
BLocker *gLock = NULL;


-/**
- * Main entry point of print_server.
- *
- * @returns B_OK if application was started, or an errorcode if
- * application failed to start.
- */
+/*! Main entry point of print_server.
+
+ @returns B_OK if application was started, or an errorcode if
+ the application failed to start.
+*/
int
main()
{
- status_t rc = B_OK;
gLock = new BLocker();
- PrintServerApp print_server(&rc);
- if (rc == B_OK) {
- print_server.Run();
- }
+
+ status_t status = B_OK;
+ PrintServerApp printServer(&status);
+ if (status == B_OK)
+ printServer.Run();
+
delete gLock;
- return rc;
+ return status;
}


-/**
- * Constructor for print_server's application class. Retrieves the
- * name of the default printer from storage, caches the icons for
- * a selected printer.
- *
- * @param err Pointer to status_t for storing result of application
- * initialisation.
- *
- * @see BApplication
- */
+/*! Constructor for print_server's application class. Retrieves the
+ name of the default printer from storage, caches the icons for
+ a selected printer.
+
+ @param err Pointer to status_t for storing result of application
+ initialisation.
+ @see BApplication
+*/
PrintServerApp::PrintServerApp(status_t* err)
- : Inherited(PSRV_SIGNATURE_TYPE, err),
+ :
+ Inherited(PSRV_SIGNATURE_TYPE, err),
fDefaultPrinter(NULL),
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
fIconSize(0),
@@ -209,7 +204,6 @@ PrintServerApp::RegisterPrinter(BDirectory* printer)
&& printer->ReadAttrString(PSRV_PRINTER_ATTR_CNX, &connection)
== B_OK
&& printer->ReadAttrString(PSRV_PRINTER_ATTR_STATE, &state) ==
B_OK
&& state == "free") {
-
BAutolock lock(gLock);
if (lock.IsLocked()) {
// check if printer is already registered
@@ -221,9 +215,9 @@ PrintServerApp::RegisterPrinter(BDirectory* printer)
return;

// register new printer
- Resource* r =
fResourceManager.Allocate(transport.String(),
+ Resource* resource =
fResourceManager.Allocate(transport.String(),
address.String(), connection.String());
- AddHandler(new Printer(printer, r));
+ AddHandler(new Printer(printer, resource));
Acquire();
}
}
@@ -266,7 +260,8 @@ PrintServerApp::EntryRemoved(node_ref* node)
{
Printer* printer = Printer::Find(node);
if (printer) {
- if (printer == fDefaultPrinter) fDefaultPrinter = NULL;
+ if (printer == fDefaultPrinter)
+ fDefaultPrinter = NULL;
UnregisterPrinter(printer);
}
}
@@ -276,44 +271,34 @@ void
PrintServerApp::AttributeChanged(node_ref* node)
{
BDirectory printer(node);
- if (printer.InitCheck() == B_OK) {
+ if (printer.InitCheck() == B_OK)
RegisterPrinter(&printer);
- }
}


-// ---------------------------------------------------------------
-// SetupPrinterList
-//
-// This method builds the internal list of printers from disk. It
-// also installs a node monitor to be sure that the list keeps
-// updated with the definitions on disk.
-//
-// Parameters:
-// none.
-//
-// Returns:
-// B_OK if successful, or an errorcode if failed.
-// ---------------------------------------------------------------
+/*! This method builds the internal list of printers from disk. It
+ also installs a node monitor to be sure that the list keeps
+ updated with the definitions on disk.
+
+ @return B_OK if successful, or an errorcode if failed.
+*/
status_t
PrintServerApp::SetupPrinterList()
{
- status_t rc;
-
// Find directory containing printer definition nodes
BPath path;
- rc = ::find_directory(B_USER_PRINTERS_DIRECTORY, &path);
- if (rc != B_OK)
- return rc;
+ status_t status = find_directory(B_USER_PRINTERS_DIRECTORY, &path);
+ if (status != B_OK)
+ return status;

// Directory has to exist in order to watch it
mode_t mode = 0777;
create_directory(path.Path(), mode);

BDirectory dir(path.Path());
- rc = dir.InitCheck();
- if (rc != B_OK)
- return rc;
+ status = dir.InitCheck();
+ if (status != B_OK)
+ return status;

// Register printer definition nodes
BEntry entry;
@@ -337,17 +322,11 @@ PrintServerApp::SetupPrinterList()
return B_OK;
}

-// ---------------------------------------------------------------
-// void MessageReceived(BMessage* msg)
-//
-// Message handling method for print_server application class.
-//
-// Parameters:
-// msg - Actual message sent to application class.
-//
-// Returns:
-// void.
-// ---------------------------------------------------------------
+
+/*! Message handling method for print_server application class.
+
+ @param msg Actual message sent to application class.
+*/
void
PrintServerApp::MessageReceived(BMessage* msg)
{
@@ -378,44 +357,35 @@ PrintServerApp::MessageReceived(BMessage* msg)
}


-// ---------------------------------------------------------------
-// CreatePrinter(const char* printerName, const char* driverName,
-// const char* connection, const char* transportName,
-// const char* transportPath)
-//
-// Creates printer definition/spool directory. It sets the
-// attributes of the directory to the values passed and calls
-// the driver's add_printer method to handle any configuration
-// needed.
-//
-// Parameters:
-// printerName - Name of printer to create.
-// driverName - Name of driver to use for this printer.
-// connection - "Local" or "Network".
-// transportName - Name of transport driver to use.
-// transportPath - Configuration data for transport driver.
-//
-// Returns:
-// ---------------------------------------------------------------
+/*! Creates printer definition/spool directory. It sets the
+ attributes of the directory to the values passed and calls
+ the driver's add_printer method to handle any configuration
+ needed.
+
+ @param printerName Name of printer to create.
+ @param driverName Name of driver to use for this printer.
+ @param connection "Local" or "Network".
+ @param transportName Name of transport driver to use.
+ @param transportPath Configuration data for transport driver.
+*/
status_t
PrintServerApp::CreatePrinter(const char* printerName, const char* driverName,
const char* connection, const char* transportName,
const char* transportPath)
{
- status_t rc;
-
// Find directory containing printer definitions
BPath path;
- rc = ::find_directory(B_USER_PRINTERS_DIRECTORY,&path,true,NULL);
- if (rc != B_OK)
- return rc;
+ status_t status = find_directory(B_USER_PRINTERS_DIRECTORY, &path, true,
+ NULL);
+ if (status != B_OK)
+ return status;

// Create our printer definition/spool directory
BDirectory printersDir(path.Path());
BDirectory printer;

- rc = printersDir.CreateDirectory(printerName, &printer);
- if (rc == B_FILE_EXISTS) {
+ status = printersDir.CreateDirectory(printerName, &printer);
+ if (status == B_FILE_EXISTS) {
printer.SetTo(&printersDir, printerName);

BString info;
@@ -427,8 +397,8 @@ PrintServerApp::CreatePrinter(const char* printerName,
const char* driverName,
if (fDefaultPrinter) {
// the printer exists, but is not the
default printer
if (strcmp(fDefaultPrinter->Name(),
printerName) != 0)
- rc = B_OK;
- return rc;
+ status = B_OK;
+ return status;
}
// the printer exists, but no default at all
return B_OK;
@@ -448,10 +418,10 @@ PrintServerApp::CreatePrinter(const char* printerName,
const char* driverName,
B_TRANSLATE("Cancel"), B_TRANSLATE("OK"));
alert->SetShortcut(0, B_ESCAPE);
if (alert->Go() == 0)
- return rc;
+ return status;
}
- } else if (rc != B_OK) {
- return rc;
+ } else if (status != B_OK) {
+ return status;
}

// Set its type to a printer
@@ -470,46 +440,38 @@ PrintServerApp::CreatePrinter(const char* printerName,
const char* driverName,
printer.WriteAttr(PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, 0, connection,
::strlen(connection) + 1);

- rc = Printer::ConfigurePrinter(driverName, printerName);
- if (rc == B_OK) {
+ status = Printer::ConfigurePrinter(driverName, printerName);
+ if (status == B_OK) {
// Notify printer driver that a new printer definition node
// has been created.
printer.WriteAttr(PSRV_PRINTER_ATTR_STATE, B_STRING_TYPE, 0,
"free",
::strlen("free")+1);
}

- if (rc != B_OK) {
+ if (status != B_OK) {
BEntry entry;
if (printer.GetEntry(&entry) == B_OK)
entry.Remove();
}

- return rc;
+ return status;
}


-// ---------------------------------------------------------------
-// SelectPrinter(const char* printerName)
-//
-// Makes a new printer the active printer. This is done simply
-// by changing our class attribute fDefaultPrinter, and changing
-// the icon of the BNode for the printer. Ofcourse, we need to
-// change the icon of the "old" default printer first back to a
-// "non-active" printer icon first.
-//
-// Parameters:
-// printerName - Name of the new active printer.
-//
-// Returns:
-// B_OK on success, or error code otherwise.
-// ---------------------------------------------------------------
+/*! Makes a new printer the active printer. This is done simply
+ by changing our class attribute fDefaultPrinter, and changing
+ the icon of the BNode for the printer. Ofcourse, we need to
+ change the icon of the "old" default printer first back to a
+ "non-active" printer icon first.
+
+ @param printerName Name of the new active printer.
+ @return B_OK on success, or error code otherwise.
+*/
status_t
PrintServerApp::SelectPrinter(const char* printerName)
{
- status_t rc;
- BNode node;
-
// Find the node of the "old" default printer
+ BNode node;
if (fDefaultPrinter != NULL
&& FindPrinterNode(fDefaultPrinter->Name(), node) == B_OK) {
// and remove the custom icon
@@ -519,8 +481,8 @@ PrintServerApp::SelectPrinter(const char* printerName)
}

// Find the node for the new default printer
- rc=FindPrinterNode(printerName, node);
- if (rc == B_OK) {
+ status_t status = FindPrinterNode(printerName, node);
+ if (status == B_OK) {
// and add the custom icon
BNodeInfo info(&node);
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
@@ -536,16 +498,11 @@ PrintServerApp::SelectPrinter(const char* printerName)
// update our pref file
be_roster->Broadcast(new BMessage(B_PRINTER_CHANGED));

- return rc;
+ return status;
}


-// ---------------------------------------------------------------
-// HandleSpooledJobs()
-//
-// Handles calling the printer drivers for printing a spooled job.
-//
-// ---------------------------------------------------------------
+//! Handles calling the printer drivers for printing a spooled job.
void
PrintServerApp::HandleSpooledJobs()
{
@@ -557,18 +514,11 @@ PrintServerApp::HandleSpooledJobs()
}


-// ---------------------------------------------------------------
-// RetrieveDefaultPrinter()
-//
-// Loads the currently selected printer from a private settings
-// file.
-//
-// Parameters:
-// none.
-//
-// Returns:
-// Error code on failore, or B_OK if all went fine.
-// ---------------------------------------------------------------
+/*! Loads the currently selected printer from a private settings
+ file.
+
+ @return Error code on failore, or B_OK if all went fine.
+*/
status_t
PrintServerApp::RetrieveDefaultPrinter()
{
@@ -577,18 +527,11 @@ PrintServerApp::RetrieveDefaultPrinter()
}


-// ---------------------------------------------------------------
-// StoreDefaultPrinter()
-//
-// Stores the currently selected printer in a private settings
-// file.
-//
-// Parameters:
-// none.
-//
-// Returns:
-// Error code on failore, or B_OK if all went fine.
-// ---------------------------------------------------------------
+/*! Stores the currently selected printer in a private settings
+ file.
+
+ @return Error code on failore, or B_OK if all went fine.
+*/
status_t
PrintServerApp::StoreDefaultPrinter()
{
@@ -600,27 +543,22 @@ PrintServerApp::StoreDefaultPrinter()
}


-// ---------------------------------------------------------------
-// FindPrinterNode(const char* name, BNode& node)
-//
-// Find the BNode representing the specified printer. It searches
-// *only* in the users printer definitions.
-//
-// Parameters:
-// name - Name of the printer to look for.
-// node - BNode to set to the printer definition node.
-//
-// Returns:
-// B_OK if found, an error code otherwise.
-// ---------------------------------------------------------------
+/*! Find the BNode representing the specified printer. It searches
+ *only* in the users printer definitions.
+
+ @param name Name of the printer to look for.
+ @param node BNode to set to the printer definition node.
+ @return B_OK if found, an error code otherwise.
+*/
status_t
PrintServerApp::FindPrinterNode(const char* name, BNode& node)
{
// Find directory containing printer definitions
BPath path;
- status_t rc = ::find_directory(B_USER_PRINTERS_DIRECTORY, &path, true,
NULL);
- if (rc != B_OK)
- return rc;
+ status_t status = find_directory(B_USER_PRINTERS_DIRECTORY, &path, true,
+ NULL);
+ if (status != B_OK)
+ return status;

path.Append(name);
return node.SetTo(path.Path());
@@ -628,8 +566,7 @@ PrintServerApp::FindPrinterNode(const char* name, BNode&
node)


bool
-PrintServerApp::OpenSettings(BFile& file, const char* name,
- bool forReading)
+PrintServerApp::OpenSettings(BFile& file, const char* name, bool forReading)
{
BPath path;
uint32 openMode = forReading ? B_READ_ONLY : B_CREATE_FILE |
B_ERASE_FILE
@@ -641,7 +578,8 @@ PrintServerApp::OpenSettings(BFile& file, const char* name,


void
-PrintServerApp::LoadSettings() {
+PrintServerApp::LoadSettings()
+{
BFile file;
if (OpenSettings(file, kSettingsName, true)) {
fSettings->Load(&file);
@@ -651,7 +589,8 @@ PrintServerApp::LoadSettings() {


void
-PrintServerApp::SaveSettings() {
+PrintServerApp::SaveSettings()
+{
BFile file;
if (OpenSettings(file, kSettingsName, false)) {
fSettings->SetUseConfigWindow(fUseConfigWindow);
diff --git a/src/servers/print/PrintServerApp.h
b/src/servers/print/PrintServerApp.h
index 3c242aa..b7ca0a4 100644
--- a/src/servers/print/PrintServerApp.h
+++ b/src/servers/print/PrintServerApp.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2010, Haiku, Inc. All rights reserved.
+ * Copyright 2001-2015, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -9,6 +9,7 @@
#ifndef _PRINT_SERVER_APP_H
#define _PRINT_SERVER_APP_H

+
#include <Application.h>
#include <Bitmap.h>
#include <Catalog.h>
@@ -19,81 +20,91 @@
#include "ResourceManager.h"
#include "Settings.h"

+
class Printer;
class Transport;

+
// The global BLocker for synchronisation.
extern BLocker *gLock;

+
// The print_server application.
class PrintServerApp : public BApplication, public FolderListener {
- private:
+private:
typedef BApplication Inherited;

- public:
- PrintServerApp(status_t *err);
- ~PrintServerApp();
+public:
+
PrintServerApp(status_t* error);
+
~PrintServerApp();

- void Acquire();
- void Release();
+ void Acquire();
+ void Release();

- bool QuitRequested();
- void MessageReceived(BMessage *msg);
- void NotifyPrinterDeletion(Printer *printer);
+ virtual bool QuitRequested();
+ virtual void MessageReceived(BMessage* msg);
+ void
NotifyPrinterDeletion(Printer* printer);

- // Scripting support, see PrintServerApp.Scripting.cpp
- status_t GetSupportedSuites(BMessage *msg);
- void HandleScriptingCommand(BMessage *msg);
- Printer *GetPrinterFromSpecifier(BMessage *msg);
- Transport *GetTransportFromSpecifier(BMessage *msg);
- BHandler *ResolveSpecifier(BMessage *msg, int32 index, BMessage
*spec,
- int32 form, const char *prop);
- private:
- bool OpenSettings(BFile &file, const char *name, bool
forReading);
- void LoadSettings();
- void SaveSettings();
+ // Scripting support, see PrintServerApp.Scripting.cpp
+ virtual status_t GetSupportedSuites(BMessage*
msg);
+ void
HandleScriptingCommand(BMessage* msg);
+ Printer*
GetPrinterFromSpecifier(BMessage* msg);
+ Transport*
GetTransportFromSpecifier(BMessage* msg);
+ virtual BHandler* ResolveSpecifier(BMessage* msg,
int32 index,
+
BMessage* specifier, int32 form,
+ const
char* property);

- status_t SetupPrinterList();
+private:
+ bool OpenSettings(BFile&
file, const char* name,
+ bool
forReading);
+ void LoadSettings();
+ void SaveSettings();

- void HandleSpooledJobs();
+ status_t SetupPrinterList();

- status_t SelectPrinter(const char *printerName);
- status_t CreatePrinter(const char *printerName, const char
*driverName,
- const char *connection, const char *transportName,
- const char *transportPath);
+ void HandleSpooledJobs();

- void RegisterPrinter(BDirectory *node);
- void UnregisterPrinter(Printer *printer);
+ status_t SelectPrinter(const
char* printerName);
+ status_t CreatePrinter(const
char* printerName,
+ const
char* driverName,
+ const
char* connection,
+ const
char* transportName,
+ const
char* transportPath);

- // FolderListener
- void EntryCreated(node_ref *node, entry_ref *entry);
- void EntryRemoved(node_ref *node);
- void AttributeChanged(node_ref *node);
+ void
RegisterPrinter(BDirectory* node);
+ void
UnregisterPrinter(Printer* printer);

- status_t StoreDefaultPrinter();
- status_t RetrieveDefaultPrinter();
+ // FolderListener
+ void EntryCreated(node_ref*
node, entry_ref* entry);
+ void EntryRemoved(node_ref*
node);
+ void
AttributeChanged(node_ref* node);

- status_t FindPrinterNode(const char *name, BNode &node);
+ status_t StoreDefaultPrinter();
+ status_t
RetrieveDefaultPrinter();
+
+ status_t FindPrinterNode(const
char* name, BNode& node);

// "Classic" BeOS R5 support, see PrintServerApp.R5.cpp
- static status_t async_thread(void *data);
- void AsyncHandleMessage(BMessage *msg);
- void Handle_BeOSR5_Message(BMessage *msg);
+ static status_t async_thread(void* data);
+ void
AsyncHandleMessage(BMessage* msg);
+ void
Handle_BeOSR5_Message(BMessage* msg);

- ResourceManager fResourceManager;
- Printer *fDefaultPrinter;
+private:
+ ResourceManager fResourceManager;
+ Printer* fDefaultPrinter;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
- size_t fIconSize;
- uint8 *fSelectedIcon;
+ size_t fIconSize;
+ uint8* fSelectedIcon;
#else
- BBitmap *fSelectedIconMini;
- BBitmap *fSelectedIconLarge;
+ BBitmap* fSelectedIconMini;
+ BBitmap* fSelectedIconLarge;
#endif
- int32 fReferences;
- sem_id fHasReferences;
- Settings *fSettings;
- bool fUseConfigWindow;
- FolderWatcher *fFolder;
+ int32 fReferences;
+ sem_id fHasReferences;
+ Settings* fSettings;
+ bool fUseConfigWindow;
+ FolderWatcher* fFolder;
};

-#endif
+
+#endif // _PRINT_SERVER_APP_H

############################################################################

Commit: 74b10f8e82c67dcf2e13b834b9c4a32fea040559
URL: http://cgit.haiku-os.org/haiku/commit/?id=74b10f8e82c6
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Mon Oct 12 19:23:57 2015 UTC

print_server: No need to build on BeOS.

----------------------------------------------------------------------------

diff --git a/src/servers/print/PrintServerApp.cpp
b/src/servers/print/PrintServerApp.cpp
index a1354cd..f591781 100644
--- a/src/servers/print/PrintServerApp.cpp
+++ b/src/servers/print/PrintServerApp.cpp
@@ -111,16 +111,8 @@ PrintServerApp::PrintServerApp(status_t* err)
RetrieveDefaultPrinter();

// Cache icons for selected printer
-#ifdef HAIKU_TARGET_PLATFORM_HAIKU
BMimeType type(PSRV_PRINTER_FILETYPE);
type.GetIcon(&fSelectedIcon, &fIconSize);
-#else
- fSelectedIconMini = new BBitmap(BRect(0,0,B_MINI_ICON-1,B_MINI_ICON-1),
B_CMAP8);
- fSelectedIconLarge = new
BBitmap(BRect(0,0,B_LARGE_ICON-1,B_LARGE_ICON-1), B_CMAP8);
- BMimeType type(PRNT_SIGNATURE_TYPE);
- type.GetIcon(fSelectedIconMini, B_MINI_ICON);
- type.GetIcon(fSelectedIconLarge, B_LARGE_ICON);
-#endif

PostMessage(PSRV_PRINT_SPOOLED_JOB);
// Start handling of spooled files
@@ -163,15 +155,8 @@ PrintServerApp::QuitRequested()
fHasReferences = 0;
}

-#ifdef HAIKU_TARGET_PLATFORM_HAIKU
delete [] fSelectedIcon;
fSelectedIcon = NULL;
-#else
- delete fSelectedIconMini;
- fSelectedIconMini = NULL;
- delete fSelectedIconLarge;
- fSelectedIconLarge = NULL;
-#endif

return true;
}
@@ -485,12 +470,7 @@ PrintServerApp::SelectPrinter(const char* printerName)
if (status == B_OK) {
// and add the custom icon
BNodeInfo info(&node);
-#ifdef HAIKU_TARGET_PLATFORM_HAIKU
info.SetIcon(fSelectedIcon, fIconSize);
-#else
- info.SetIcon(fSelectedIconMini, B_MINI_ICON);
- info.SetIcon(fSelectedIconLarge, B_LARGE_ICON);
-#endif
}

fDefaultPrinter = Printer::Find(printerName);
diff --git a/src/servers/print/PrintServerApp.h
b/src/servers/print/PrintServerApp.h
index b7ca0a4..a0a83a3 100644
--- a/src/servers/print/PrintServerApp.h
+++ b/src/servers/print/PrintServerApp.h
@@ -92,13 +92,8 @@ private:
private:
ResourceManager fResourceManager;
Printer* fDefaultPrinter;
-#ifdef HAIKU_TARGET_PLATFORM_HAIKU
size_t fIconSize;
uint8* fSelectedIcon;
-#else
- BBitmap* fSelectedIconMini;
- BBitmap* fSelectedIconLarge;
-#endif
int32 fReferences;
sem_id fHasReferences;
Settings* fSettings;

############################################################################

Commit: e048384d778494243edf0187eaa8550dae58c840
URL: http://cgit.haiku-os.org/haiku/commit/?id=e048384d7784
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Tue Oct 13 14:26:13 2015 UTC

launch_daemon: launching on demand now actually works.

* Was broken in two ways: if only the shortcut "on_demand" was used,
the event didn't get created at all due to a bug in
Events::AddOnDemand().
* Furthermore, _LaunchJob() always triggered a demand, but it should
only do this when not called from a target.

----------------------------------------------------------------------------

diff --git a/src/servers/launch/Events.cpp b/src/servers/launch/Events.cpp
index 8714339..29b6edb 100644
--- a/src/servers/launch/Events.cpp
+++ b/src/servers/launch/Events.cpp
@@ -474,15 +474,15 @@ Events::FromMessage(const BMessenger& target, const
BMessage& message)


/*static*/ Event*
-Events::AddOnDemand(Event* event)
+Events::AddOnDemand(const BMessenger& target, Event* event)
{
OrEvent* orEvent = dynamic_cast<OrEvent*>(event);
if (orEvent == NULL) {
EventContainer* container =
dynamic_cast<EventContainer*>(event);
- if (container == NULL)
- return NULL;
-
- orEvent = new OrEvent(container->Owner(), container->Target());
+ if (container != NULL)
+ orEvent = new OrEvent(container->Owner(),
container->Target());
+ else
+ orEvent = new OrEvent(NULL, target);
}
if (orEvent != event && event != NULL)
orEvent->AddEvent(event);
diff --git a/src/servers/launch/Events.h b/src/servers/launch/Events.h
index ac7afd0..a41707b 100644
--- a/src/servers/launch/Events.h
+++ b/src/servers/launch/Events.h
@@ -52,7 +52,7 @@ class Events {
public:
static Event* FromMessage(const BMessenger& target,
const BMessage&
message);
- static Event* AddOnDemand(Event* event);
+ static Event* AddOnDemand(const BMessenger& target,
Event* event);
static bool ResolveRegisteredEvent(Event* event,
const char*
name);
static void TriggerRegisteredEvent(Event* event,
diff --git a/src/servers/launch/LaunchDaemon.cpp
b/src/servers/launch/LaunchDaemon.cpp
index 8b0d220..ef3f576 100644
--- a/src/servers/launch/LaunchDaemon.cpp
+++ b/src/servers/launch/LaunchDaemon.cpp
@@ -53,6 +53,12 @@ static const char* kLaunchDirectory = "launch";
static const char* kUserLaunchDirectory = "user_launch";


+enum launch_options {
+ FORCE_NOW = 0x01,
+ TRIGGER_DEMAND = 0x02
+};
+
+
class Session {
public:
Session(uid_t
user, const BMessenger& target);
@@ -138,7 +144,7 @@ private:
void _InitJobs(Target*
target);
void _LaunchJobs(Target*
target,
bool
forceNow = false);
- void _LaunchJob(Job* job,
bool forceNow = false);
+ void _LaunchJob(Job* job,
uint32 options = 0);
void _AddTarget(Target*
target);
void _SetCondition(BaseJob*
job,
const
BMessage& message);
@@ -490,7 +496,7 @@ LaunchDaemon::_HandleGetLaunchData(BMessage* message)
if (reply.what == B_OK) {
// Launch the job if it hasn't been launched already
if (launchJob)
- _LaunchJob(job);
+ _LaunchJob(job, TRIGGER_DEMAND);

DetachCurrentMessage();
status_t result = job->HandleGetLaunchData(message);
@@ -1021,19 +1027,23 @@ LaunchDaemon::_LaunchJobs(Target* target, bool forceNow)
Calling this method will trigger a demand event.
*/
void
-LaunchDaemon::_LaunchJob(Job* job, bool forceNow)
+LaunchDaemon::_LaunchJob(Job* job, uint32 options)
{
- if (job == NULL || job->IsLaunched() || (!forceNow
+ if (job == NULL || job->IsLaunched() || ((options & FORCE_NOW) == 0
&& (!job->EventHasTriggered() || !job->CheckCondition(*this)
- || Events::TriggerDemand(job->Event())))) {
+ || ((options & TRIGGER_DEMAND) != 0
+ &&
Events::TriggerDemand(job->Event()))))) {
return;
}

int32 count = job->Requirements().CountStrings();
for (int32 index = 0; index < count; index++) {
Job* requirement = FindJob(job->Requirements().StringAt(index));
- if (requirement != NULL)
- _LaunchJob(requirement);
+ if (requirement != NULL) {
+ // TODO: For jobs that have their communication
channels set up,
+ // we would not need to trigger demand at this point
+ _LaunchJob(requirement, TRIGGER_DEMAND);
+ }
}

if (job->Target() != NULL)
@@ -1087,7 +1097,7 @@ LaunchDaemon::_SetEvent(BaseJob* job, const BMessage&
message)
}

if (message.GetBool("on_demand")) {
- event = Events::AddOnDemand(event);
+ event = Events::AddOnDemand(this, event);
updated = true;
}


############################################################################

Revision: hrev49682
Commit: 37e5a036605931f55d82e971f8ab99c48023a5c4
URL: http://cgit.haiku-os.org/haiku/commit/?id=37e5a0366059
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Tue Oct 13 14:37:16 2015 UTC

print_server: Converted to launch_daemon, run on demand only.

* Seems to work fine, although it should probably also be triggered when
there are still jobs in the queue -- someone more knowledgeable might
want to chime in here, please :-)
* If this turns out to be problematic, we can just drop the "on_demand"
job config again.

----------------------------------------------------------------------------

diff --git a/data/launch/system b/data/launch/system
index b777b47..fddac8f 100644
--- a/data/launch/system
+++ b/data/launch/system
@@ -64,7 +64,7 @@ service x-vnd.Haiku-cddb_daemon {
service x-vnd.Haiku-print_server {
launch /system/servers/print_server
no_safemode
- legacy
+ on_demand
}

service x-vnd.Haiku-notification_server {
diff --git a/src/servers/print/Jamfile b/src/servers/print/Jamfile
index 1d9fdfb..847a05d 100644
--- a/src/servers/print/Jamfile
+++ b/src/servers/print/Jamfile
@@ -1,6 +1,6 @@
SubDir HAIKU_TOP src servers print ;

-UsePrivateHeaders shared print ;
+UsePrivateHeaders app shared print ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers libs print libprint ] ;

AddResources print_server :
diff --git a/src/servers/print/PrintServerApp.cpp
b/src/servers/print/PrintServerApp.cpp
index f591781..4a5be6e 100644
--- a/src/servers/print/PrintServerApp.cpp
+++ b/src/servers/print/PrintServerApp.cpp
@@ -79,7 +79,7 @@ main()
*/
PrintServerApp::PrintServerApp(status_t* err)
:
- Inherited(PSRV_SIGNATURE_TYPE, err),
+ Inherited(PSRV_SIGNATURE_TYPE, true, err),
fDefaultPrinter(NULL),
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
fIconSize(0),
diff --git a/src/servers/print/PrintServerApp.h
b/src/servers/print/PrintServerApp.h
index a0a83a3..d4c5a16 100644
--- a/src/servers/print/PrintServerApp.h
+++ b/src/servers/print/PrintServerApp.h
@@ -10,10 +10,10 @@
#define _PRINT_SERVER_APP_H


-#include <Application.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <OS.h>
+#include <Server.h>
#include <String.h>

#include "FolderWatcher.h"
@@ -30,9 +30,9 @@ extern BLocker *gLock;


// The print_server application.
-class PrintServerApp : public BApplication, public FolderListener {
+class PrintServerApp : public BServer, public FolderListener {
private:
- typedef BApplication Inherited;
+ typedef BServer Inherited;

public:

PrintServerApp(status_t* error);


Other related posts:

  • » [haiku-commits] haiku: hrev49682 - in src/servers: print launch - axeld