예제 #1
0
파일: Printer.cpp 프로젝트: mmanley/Antares
// ---------------------------------------------------------------
// PrintSpooledJob
//
// Loads the printer add-on and calls its take_job function with
// the spool file as argument.
//
// Parameters:
//    spoolFile - the spool file.
//
// Returns:
//    B_OK if successful.
// ---------------------------------------------------------------
status_t Printer::PrintSpooledJob(BFile* spoolFile)
{
	status_t rc;
	image_id id;
	if ((rc = LoadPrinterAddon(id)) == B_OK) {
		take_job_func_t func;
		// Addon was loaded, so try and get the take_job symbol
		if ((rc = get_image_symbol(id, "take_job", B_SYMBOL_TYPE_TEXT,
			(void**)&func)) == B_OK) {
			// This seems to be required for legacy?
			// HP PCL3 add-on crashes without it!
			BMessage params(B_REFS_RECEIVED);
			params.AddInt32("file", (int32)spoolFile);
			params.AddInt32("printer", (int32)SpoolDir());
				// call the function and check its result
			BMessage* result = (*func)(spoolFile, SpoolDir(), &params);

			if (result == NULL || result->what != 'okok')
				rc = B_ERROR;
			delete result;
		}

		::unload_add_on(id);
	}
	return rc;
}
예제 #2
0
파일: Printer.cpp 프로젝트: mmanley/Antares
// ---------------------------------------------------------------
// LoadPrinterAddon
//
// Try to load the printer addon into memory.
//
// Parameters:
//    id - image_id set to the image id of the loaded addon.
//
// Returns:
//    B_OK if successful or errorcode otherwise.
// ---------------------------------------------------------------
status_t Printer::LoadPrinterAddon(image_id& id)
{
	status_t rc;
	BString drName;
	if ((rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_DRV_NAME, &drName)) == B_OK) {
		// try to locate the driver
		BPath path;
		if ((rc= ::TestForAddonExistence(drName.String(), B_USER_ADDONS_DIRECTORY,
			"Print", path)) != B_OK) {
			if ((rc = ::TestForAddonExistence(drName.String(), B_COMMON_ADDONS_DIRECTORY,
				"Print", path)) != B_OK) {
				rc = ::TestForAddonExistence(drName.String(), B_BEOS_ADDONS_DIRECTORY,
					"Print", path);
			}
		}

		// If the driver was found
		if (rc == B_OK) {
			// If we cannot load the addon
			if ((id=::load_add_on(path.Path())) < 0)
				rc = id;
		}
	}
	return rc;
}
예제 #3
0
파일: Printer.cpp 프로젝트: mmanley/Antares
// ---------------------------------------------------------------
// GetDefaultSettings
//
// Retrieve the default configuration message from printer add-on
//
// Parameters:
//   settings, output paramter.
//
// Returns:
//    B_OK if successful or errorcode otherwise.
// ---------------------------------------------------------------
status_t Printer::GetDefaultSettings(BMessage& settings)
{
	status_t rc;
	image_id id;
	if ((rc = LoadPrinterAddon(id)) == B_OK) {
			// Addon was loaded, so try and get the default_settings symbol
		default_settings_t func;
		if ((rc = get_image_symbol(id, "default_settings", B_SYMBOL_TYPE_TEXT,
			(void**)&func)) == B_OK) {
				// call the function and check its result
			BMessage* new_settings = (*func)(SpoolDir());
			if (new_settings) {
				settings = *new_settings;
				settings.what = 'okok';
				AddCurrentPrinter(settings);
			} else {
				rc = B_ERROR;
			}
			delete new_settings;
		}

		::unload_add_on(id);
	}
	return rc;
}
예제 #4
0
파일: Printer.cpp 프로젝트: mmanley/Antares
// ---------------------------------------------------------------
// ConfigureJob
//
// Handles calling the printer addon's config_job function.
//
// Parameters:
//    settings - Job settings to display. The contents of this
//               message will be replaced with the new settings
//               if the function returns success.
//
// Returns:
//    B_OK if successful or errorcode otherwise.
// ---------------------------------------------------------------
status_t Printer::ConfigureJob(BMessage& settings)
{
	status_t rc;
	image_id id;
	if ((rc = LoadPrinterAddon(id)) == B_OK) {
			// Addon was loaded, so try and get the config_job symbol
		config_func_t func;
		if ((rc = get_image_symbol(id, "config_job", B_SYMBOL_TYPE_TEXT,
			(void**)&func)) == B_OK) {
			// call the function and check its result
			BMessage* new_settings = (*func)(SpoolDir(), &settings);
			if ((new_settings != NULL) && (new_settings->what != 'baad')) {
				settings = *new_settings;
				settings.what = 'okok';
				AddCurrentPrinter(settings);
			} else {
				rc = B_ERROR;
			}
			delete new_settings;
		}

		::unload_add_on(id);
	}

	return rc;
}
예제 #5
0
void Printer::HandleScriptingCommand(BMessage* msg)
{
	status_t rc = B_ERROR;
	BString propName;
	BString result;
	BMessage spec;
	int32 idx;

	if ((rc=msg->GetCurrentSpecifier(&idx,&spec)) == B_OK &&
		(rc=spec.FindString("property",&propName)) == B_OK) {
		switch(msg->what) {
			case B_GET_PROPERTY:
				if (propName == "Name")
					rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &result);
				else if (propName == "TransportAddon")
					rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_TRANSPORT, &result);
				else if (propName == "TransportConfig")
					rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, &result);
				else if (propName == "PrinterAddon")
					rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_DRV_NAME, &result);
				else if (propName == "Comments")
					rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_COMMENTS, &result);
				else { // If unknown scripting request, let superclas handle it
					Inherited::MessageReceived(msg);
					break;
				}

				BMessage reply(B_REPLY);
				reply.AddString("result", result);
				reply.AddInt32("error", rc);
				msg->SendReply(&reply);
				break;
		}
	}
	else {
			// If GetSpecifier failed
		if (idx == -1) {
			BMessage reply(B_REPLY);
			reply.AddMessenger("result", BMessenger(this));
			reply.AddInt32("error", B_OK);
			msg->SendReply(&reply);
		}
	}
}
예제 #6
0
// ---------------------------------------------------------------
// PrintSpooledJob
//
// Loads the printer add-on and calls its take_job function with
// the spool file as argument.
//
// Parameters:
//    spoolFile - the path to the spool file.
//
// Returns:
//    B_OK if successful.
// ---------------------------------------------------------------
status_t 
Printer::PrintSpooledJob(const char* spoolFile)
{
	BString driver;
	status_t result = GetDriverName(&driver);
	if (result != B_OK)
		return result;

	PrintAddOnServer addOn(driver.String());
	return addOn.TakeJob(spoolFile, SpoolDir());
}
예제 #7
0
// ---------------------------------------------------------------
// GetDefaultSettings
//
// Retrieve the default configuration message from printer add-on
//
// Parameters:
//   settings, output paramter.
//
// Returns:
//    B_OK if successful or errorcode otherwise.
// ---------------------------------------------------------------
status_t 
Printer::GetDefaultSettings(BMessage& settings)
{
	BString driver;
	status_t result = GetDriverName(&driver);
	if (result != B_OK)
		return result;

	PrintAddOnServer addOn(driver.String());
	result = addOn.DefaultSettings(SpoolDir(), &settings);
	if (result == B_OK)
		AddCurrentPrinter(settings);

	return result;
}
예제 #8
0
// ---------------------------------------------------------------
// ConfigurePage
//
// Handles calling the printer addon's config_page function.
//
// Parameters:
//    settings - Page settings to display. The contents of this
//               message will be replaced with the new settings
//               if the function returns success.
//
// Returns:
//    B_OK if successful or errorcode otherwise.
// ---------------------------------------------------------------
status_t 
Printer::ConfigurePage(BMessage& settings)
{
	BString driver;
	status_t result = GetDriverName(&driver);
	if (result != B_OK)
		return result;

	PrintAddOnServer addOn(driver.String());
	result = addOn.ConfigPage(SpoolDir(), &settings);
	if (result == B_OK) {
		AddCurrentPrinter(settings);
	}
	return result;
}
예제 #9
0
// ---------------------------------------------------------------
// Printer [constructor]
//
// Initializes the printer object with data read from the
// attributes attached to the printer definition node.
//
// Parameters:
//    node - Printer definition node for this printer.
//
// Returns:
//    none.
// ---------------------------------------------------------------
Printer::Printer(const BDirectory* node, Resource* res)
	: Inherited(B_EMPTY_STRING),
	fPrinter(gLock, be_app, *node),
	fResource(res),
	fSinglePrintThread(res->NeedsLocking()),
	fJob(NULL),
	fProcessing(0),
	fAbort(false)
{
	BString name;
		// Set our name to the name of the passed node
	if (SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &name) == B_OK)
		SetName(name.String());

		// Add us to the global list of known printer definitions
	sPrinters.AddItem(this);

	ResetJobStatus();
}
예제 #10
0
// ---------------------------------------------------------------
// GetName
//
// Get the name from spool directory.
//
// Parameters:
//    name - the name of the printer.
// ---------------------------------------------------------------
void 
Printer::GetName(BString& name)
{
	if (SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &name) != B_OK)
		name = "Unknown Printer";
}
예제 #11
0
status_t
Printer::GetDriverName(BString* name)
{
	return SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_DRV_NAME, name);
}