* Style changes. No functional changes.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36966 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2010-05-28 15:55:07 +00:00
parent 8b0a06ad7a
commit 9abbe87f8c
10 changed files with 184 additions and 75 deletions
+27 -13
View File
@@ -96,7 +96,8 @@ static struct PageFormat
}; };
static void GetPageFormat(float w, float h, BString& label) static void
GetPageFormat(float w, float h, BString& label)
{ {
w = floor(w + 0.5); h = floor(h + 0.5); w = floor(w + 0.5); h = floor(h + 0.5);
for (uint i = 0; i < sizeof(pageFormat) / sizeof(struct PageFormat); i ++) { for (uint i = 0; i < sizeof(pageFormat) / sizeof(struct PageFormat); i ++) {
@@ -240,6 +241,7 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter,
UpdateSettings(true); UpdateSettings(true);
} }
ConfigWindow::~ConfigWindow() ConfigWindow::~ConfigWindow()
{ {
if (fCurrentPrinter) if (fCurrentPrinter)
@@ -248,7 +250,8 @@ ConfigWindow::~ConfigWindow()
} }
void ConfigWindow::Go() void
ConfigWindow::Go()
{ {
sem_id sid = create_sem(0, "finished"); sem_id sid = create_sem(0, "finished");
if (sid >= 0) { if (sid >= 0) {
@@ -262,7 +265,8 @@ void ConfigWindow::Go()
} }
void ConfigWindow::MessageReceived(BMessage* m) void
ConfigWindow::MessageReceived(BMessage* m)
{ {
switch (m->what) { switch (m->what) {
case MSG_PAGE_SETUP: case MSG_PAGE_SETUP:
@@ -313,7 +317,8 @@ ConfigWindow::AboutRequested()
} }
void ConfigWindow::FrameMoved(BPoint p) void
ConfigWindow::FrameMoved(BPoint p)
{ {
BRect frame = GetWindowFrame(); BRect frame = GetWindowFrame();
frame.OffsetTo(p); frame.OffsetTo(p);
@@ -321,7 +326,8 @@ void ConfigWindow::FrameMoved(BPoint p)
} }
BRect ConfigWindow::GetWindowFrame() BRect
ConfigWindow::GetWindowFrame()
{ {
BAutolock lock(gLock); BAutolock lock(gLock);
if (lock.IsLocked()) if (lock.IsLocked())
@@ -331,7 +337,8 @@ BRect ConfigWindow::GetWindowFrame()
} }
void ConfigWindow::SetWindowFrame(BRect r) void
ConfigWindow::SetWindowFrame(BRect r)
{ {
BAutolock lock(gLock); BAutolock lock(gLock);
if (lock.IsLocked()) if (lock.IsLocked())
@@ -339,7 +346,8 @@ void ConfigWindow::SetWindowFrame(BRect r)
} }
BPictureButton* ConfigWindow::AddPictureButton(BView* panel, BRect frame, BPictureButton*
ConfigWindow::AddPictureButton(BView* panel, BRect frame,
const char* name, const char* on, const char* off, uint32 what) const char* name, const char* on, const char* off, uint32 what)
{ {
BBitmap* onBM = LoadBitmap(on); BBitmap* onBM = LoadBitmap(on);
@@ -379,7 +387,8 @@ BPictureButton* ConfigWindow::AddPictureButton(BView* panel, BRect frame,
} }
void ConfigWindow::PrinterForMimeType() void
ConfigWindow::PrinterForMimeType()
{ {
BAutolock lock(gLock); BAutolock lock(gLock);
if (fCurrentPrinter) { if (fCurrentPrinter) {
@@ -402,7 +411,8 @@ void ConfigWindow::PrinterForMimeType()
} }
void ConfigWindow::SetupPrintersMenu(BMenu* menu) void
ConfigWindow::SetupPrintersMenu(BMenu* menu)
{ {
// clear menu // clear menu
while (menu->CountItems() != 0) while (menu->CountItems() != 0)
@@ -426,7 +436,8 @@ void ConfigWindow::SetupPrintersMenu(BMenu* menu)
} }
void ConfigWindow::UpdateAppSettings(const char* mime, const char* printer) void
ConfigWindow::UpdateAppSettings(const char* mime, const char* printer)
{ {
BAutolock lock(gLock); BAutolock lock(gLock);
if (lock.IsLocked()) { if (lock.IsLocked()) {
@@ -440,7 +451,8 @@ void ConfigWindow::UpdateAppSettings(const char* mime, const char* printer)
} }
void ConfigWindow::UpdateSettings(bool read) void
ConfigWindow::UpdateSettings(bool read)
{ {
BAutolock lock(gLock); BAutolock lock(gLock);
if (lock.IsLocked()) { if (lock.IsLocked()) {
@@ -463,7 +475,8 @@ void ConfigWindow::UpdateSettings(bool read)
} }
void ConfigWindow::UpdateUI() void
ConfigWindow::UpdateUI()
{ {
if (fCurrentPrinter == NULL) { if (fCurrentPrinter == NULL) {
fPageSetup->SetEnabled(false); fPageSetup->SetEnabled(false);
@@ -545,7 +558,8 @@ void ConfigWindow::UpdateUI()
} }
void ConfigWindow::Setup(config_setup_kind kind) void
ConfigWindow::Setup(config_setup_kind kind)
{ {
if (fCurrentPrinter) { if (fCurrentPrinter) {
Hide(); Hide();
+9 -3
View File
@@ -48,7 +48,9 @@ struct AsyncThreadParams {
} }
}; };
status_t PrintServerApp::async_thread(void* data)
status_t
PrintServerApp::async_thread(void* data)
{ {
AsyncThreadParams* p = (AsyncThreadParams*)data; AsyncThreadParams* p = (AsyncThreadParams*)data;
@@ -153,7 +155,8 @@ status_t PrintServerApp::async_thread(void* data)
// Async. processing of received message // Async. processing of received message
void PrintServerApp::AsyncHandleMessage(BMessage* msg) void
PrintServerApp::AsyncHandleMessage(BMessage* msg)
{ {
AsyncThreadParams* data = new AsyncThreadParams(this, fDefaultPrinter, msg); AsyncThreadParams* data = new AsyncThreadParams(this, fDefaultPrinter, msg);
@@ -167,7 +170,9 @@ void PrintServerApp::AsyncHandleMessage(BMessage* msg)
} }
} }
void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
void
PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
{ {
switch(msg->what) { switch(msg->what) {
// Get currently selected printer // Get currently selected printer
@@ -218,3 +223,4 @@ void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
break; break;
} }
} }
@@ -41,6 +41,7 @@ static property_info prop_list[] = {
{ 0 } // terminate list { 0 } // terminate list
}; };
void void
PrintServerApp::HandleScriptingCommand(BMessage* msg) PrintServerApp::HandleScriptingCommand(BMessage* msg)
{ {
@@ -131,7 +132,9 @@ PrintServerApp::HandleScriptingCommand(BMessage* msg)
} }
} }
Printer* PrintServerApp::GetPrinterFromSpecifier(BMessage* msg)
Printer*
PrintServerApp::GetPrinterFromSpecifier(BMessage* msg)
{ {
switch(msg->what) { switch(msg->what) {
case B_NAME_SPECIFIER: { case B_NAME_SPECIFIER: {
@@ -162,7 +165,9 @@ Printer* PrintServerApp::GetPrinterFromSpecifier(BMessage* msg)
return NULL; return NULL;
} }
Transport* PrintServerApp::GetTransportFromSpecifier(BMessage* msg)
Transport*
PrintServerApp::GetTransportFromSpecifier(BMessage* msg)
{ {
switch(msg->what) { switch(msg->what) {
case B_NAME_SPECIFIER: { case B_NAME_SPECIFIER: {
@@ -193,6 +198,7 @@ Transport* PrintServerApp::GetTransportFromSpecifier(BMessage* msg)
return NULL; return NULL;
} }
BHandler* BHandler*
PrintServerApp::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec, PrintServerApp::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
int32 form, const char* prop) int32 form, const char* prop)
@@ -234,6 +240,7 @@ PrintServerApp::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
return rc; return rc;
} }
status_t status_t
PrintServerApp::GetSupportedSuites(BMessage* msg) PrintServerApp::GetSupportedSuites(BMessage* msg)
{ {
+23 -7
View File
@@ -41,17 +41,22 @@
#define B_TRANSLATE_CONTEXT "PrintServerApp" #define B_TRANSLATE_CONTEXT "PrintServerApp"
BLocker *gLock = NULL;
// ---------------------------------------------------------------
typedef struct _printer_data { typedef struct _printer_data {
char defaultPrinterName[256]; char defaultPrinterName[256];
} printer_data_t; } printer_data_t;
typedef BMessage* (*config_func_t)(BNode*, const BMessage*); typedef BMessage* (*config_func_t)(BNode*, const BMessage*);
typedef BMessage* (*take_job_func_t)(BFile*, BNode*, const BMessage*); typedef BMessage* (*take_job_func_t)(BFile*, BNode*, const BMessage*);
typedef char* (*add_printer_func_t)(const char* printer_name); typedef char* (*add_printer_func_t)(const char* printer_name);
static const char* kSettingsName = "print_server_settings";
BLocker *gLock = NULL;
/** /**
* Main entry point of print_server. * Main entry point of print_server.
* *
@@ -71,6 +76,7 @@ main()
return rc; return rc;
} }
/** /**
* Constructor for print_server's application class. Retrieves the * Constructor for print_server's application class. Retrieves the
* name of the default printer from storage, caches the icons for * name of the default printer from storage, caches the icons for
@@ -373,6 +379,7 @@ PrintServerApp::MessageReceived(BMessage* msg)
} }
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// CreatePrinter(const char* printerName, const char* driverName, // CreatePrinter(const char* printerName, const char* driverName,
// const char* connection, const char* transportName, // const char* connection, const char* transportName,
@@ -504,6 +511,7 @@ error:
return rc; return rc;
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// SelectPrinter(const char* printerName) // SelectPrinter(const char* printerName)
// //
@@ -555,6 +563,7 @@ PrintServerApp::SelectPrinter(const char* printerName)
return rc; return rc;
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// HandleSpooledJobs() // HandleSpooledJobs()
// //
@@ -571,6 +580,7 @@ PrintServerApp::HandleSpooledJobs()
} }
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// RetrieveDefaultPrinter() // RetrieveDefaultPrinter()
// //
@@ -590,6 +600,7 @@ PrintServerApp::RetrieveDefaultPrinter()
return B_OK; return B_OK;
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// StoreDefaultPrinter() // StoreDefaultPrinter()
// //
@@ -612,6 +623,7 @@ PrintServerApp::StoreDefaultPrinter()
return B_OK; return B_OK;
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// FindPrinterNode(const char* name, BNode& node) // FindPrinterNode(const char* name, BNode& node)
// //
@@ -638,6 +650,7 @@ PrintServerApp::FindPrinterNode(const char* name, BNode& node)
return node.SetTo(path.Path()); return node.SetTo(path.Path());
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// FindPrinterDriver(const char* name, BPath& outPath) // FindPrinterDriver(const char* name, BPath& outPath)
// //
@@ -667,7 +680,8 @@ PrintServerApp::FindPrinterDriver(const char* name, BPath& outPath)
} }
bool PrintServerApp::OpenSettings(BFile& file, const char* name, bool
PrintServerApp::OpenSettings(BFile& file, const char* name,
bool forReading) bool forReading)
{ {
BPath path; BPath path;
@@ -678,9 +692,9 @@ bool PrintServerApp::OpenSettings(BFile& file, const char* name,
&& file.SetTo(path.Path(), openMode) == B_OK; && file.SetTo(path.Path(), openMode) == B_OK;
} }
static const char* kSettingsName = "print_server_settings";
void PrintServerApp::LoadSettings() { void
PrintServerApp::LoadSettings() {
BFile file; BFile file;
if (OpenSettings(file, kSettingsName, true)) { if (OpenSettings(file, kSettingsName, true)) {
fSettings->Load(&file); fSettings->Load(&file);
@@ -688,7 +702,9 @@ void PrintServerApp::LoadSettings() {
} }
} }
void PrintServerApp::SaveSettings() {
void
PrintServerApp::SaveSettings() {
BFile file; BFile file;
if (OpenSettings(file, kSettingsName, false)) { if (OpenSettings(file, kSettingsName, false)) {
fSettings->SetUseConfigWindow(fUseConfigWindow); fSettings->SetUseConfigWindow(fUseConfigWindow);
+6 -3
View File
@@ -37,7 +37,8 @@ static property_info prop_list[] = {
}; };
void Printer::HandleScriptingCommand(BMessage* msg) void
Printer::HandleScriptingCommand(BMessage* msg)
{ {
status_t rc = B_ERROR; status_t rc = B_ERROR;
BString propName; BString propName;
@@ -82,7 +83,8 @@ void Printer::HandleScriptingCommand(BMessage* msg)
} }
} }
BHandler* Printer::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec, BHandler*
Printer::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
int32 form, const char* prop) int32 form, const char* prop)
{ {
BPropertyInfo prop_info(prop_list); BPropertyInfo prop_info(prop_list);
@@ -98,7 +100,8 @@ BHandler* Printer::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
return rc; return rc;
} }
status_t Printer::GetSupportedSuites(BMessage* msg) status_t
Printer::GetSupportedSuites(BMessage* msg)
{ {
msg->AddString("suites", "application/x-vnd.OpenBeOS-printer"); msg->AddString("suites", "application/x-vnd.OpenBeOS-printer");
+32 -16
View File
@@ -226,7 +226,8 @@ status_t Printer::ConfigurePrinter()
// Returns: // Returns:
// B_OK if successful or errorcode otherwise. // B_OK if successful or errorcode otherwise.
// --------------------------------------------------------------- // ---------------------------------------------------------------
status_t Printer::ConfigurePage(BMessage& settings) status_t
Printer::ConfigurePage(BMessage& settings)
{ {
status_t rc; status_t rc;
image_id id; image_id id;
@@ -267,7 +268,8 @@ status_t Printer::ConfigurePage(BMessage& settings)
// Returns: // Returns:
// B_OK if successful or errorcode otherwise. // B_OK if successful or errorcode otherwise.
// --------------------------------------------------------------- // ---------------------------------------------------------------
status_t Printer::ConfigureJob(BMessage& settings) status_t
Printer::ConfigureJob(BMessage& settings)
{ {
status_t rc; status_t rc;
image_id id; image_id id;
@@ -300,7 +302,8 @@ status_t Printer::ConfigureJob(BMessage& settings)
// //
// Print spooled jobs in a new thread. // Print spooled jobs in a new thread.
// --------------------------------------------------------------- // ---------------------------------------------------------------
void Printer::HandleSpooledJob() void
Printer::HandleSpooledJob()
{ {
BAutolock lock(gLock); BAutolock lock(gLock);
if (lock.IsLocked() if (lock.IsLocked()
@@ -321,7 +324,8 @@ void Printer::HandleSpooledJob()
// Returns: // Returns:
// B_OK if successful or errorcode otherwise. // B_OK if successful or errorcode otherwise.
// --------------------------------------------------------------- // ---------------------------------------------------------------
status_t Printer::GetDefaultSettings(BMessage& settings) status_t
Printer::GetDefaultSettings(BMessage& settings)
{ {
status_t rc; status_t rc;
image_id id; image_id id;
@@ -348,7 +352,8 @@ status_t Printer::GetDefaultSettings(BMessage& settings)
} }
void Printer::AbortPrintThread() void
Printer::AbortPrintThread()
{ {
fAbort = true; fAbort = true;
} }
@@ -365,7 +370,8 @@ void Printer::AbortPrintThread()
// Returns: // Returns:
// B_OK if successful or errorcode otherwise. // B_OK if successful or errorcode otherwise.
// --------------------------------------------------------------- // ---------------------------------------------------------------
status_t Printer::LoadPrinterAddon(image_id& id) status_t
Printer::LoadPrinterAddon(image_id& id)
{ {
status_t rc; status_t rc;
BString drName; BString drName;
@@ -400,7 +406,8 @@ status_t Printer::LoadPrinterAddon(image_id& id)
// Parameters: // Parameters:
// msg - message. // msg - message.
// --------------------------------------------------------------- // ---------------------------------------------------------------
void Printer::AddCurrentPrinter(BMessage& message) void
Printer::AddCurrentPrinter(BMessage& message)
{ {
BString name; BString name;
GetName(name); GetName(name);
@@ -418,7 +425,8 @@ void Printer::AddCurrentPrinter(BMessage& message)
// Parameters: // Parameters:
// name - the name of the printer. // name - the name of the printer.
// --------------------------------------------------------------- // ---------------------------------------------------------------
void Printer::GetName(BString& name) void
Printer::GetName(BString& name)
{ {
if (SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &name) != B_OK) if (SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &name) != B_OK)
name = "Unknown Printer"; name = "Unknown Printer";
@@ -430,7 +438,8 @@ void Printer::GetName(BString& name)
// //
// Reset status of "processing" jobs to "waiting" at print_server start. // Reset status of "processing" jobs to "waiting" at print_server start.
// --------------------------------------------------------------- // ---------------------------------------------------------------
void Printer::ResetJobStatus() void
Printer::ResetJobStatus()
{ {
if (fPrinter.Lock()) { if (fPrinter.Lock()) {
const int32 n = fPrinter.CountJobs(); const int32 n = fPrinter.CountJobs();
@@ -455,7 +464,8 @@ void Printer::ResetJobStatus()
// Returns: // Returns:
// true if successful. // true if successful.
// --------------------------------------------------------------- // ---------------------------------------------------------------
bool Printer::HasCurrentPrinter(BString& name) bool
Printer::HasCurrentPrinter(BString& name)
{ {
BMessage settings; BMessage settings;
// read settings from spool file and get printer name // read settings from spool file and get printer name
@@ -478,7 +488,8 @@ bool Printer::HasCurrentPrinter(BString& name)
// Returns: // Returns:
// true if successful. // true if successful.
// --------------------------------------------------------------- // ---------------------------------------------------------------
bool Printer::MoveJob(const BString& name) bool
Printer::MoveJob(const BString& name)
{ {
BPath file(&fJob->EntryRef()); BPath file(&fJob->EntryRef());
BPath path; BPath path;
@@ -506,7 +517,8 @@ bool Printer::MoveJob(const BString& name)
// Returns: // Returns:
// true if there is a job present in fJob. // true if there is a job present in fJob.
// --------------------------------------------------------------- // ---------------------------------------------------------------
bool Printer::FindSpooledJob() bool
Printer::FindSpooledJob()
{ {
BString name2; BString name2;
GetName(name2); GetName(name2);
@@ -541,7 +553,8 @@ bool Printer::FindSpooledJob()
// Returns: // Returns:
// B_OK if successful. // B_OK if successful.
// --------------------------------------------------------------- // ---------------------------------------------------------------
status_t Printer::PrintSpooledJob(BFile* spoolFile) status_t
Printer::PrintSpooledJob(BFile* spoolFile)
{ {
status_t rc; status_t rc;
image_id id; image_id id;
@@ -578,7 +591,8 @@ status_t Printer::PrintSpooledJob(BFile* spoolFile)
// Parameters: // Parameters:
// job - the spool job. // job - the spool job.
// --------------------------------------------------------------- // ---------------------------------------------------------------
void Printer::PrintThread(Job* job) void
Printer::PrintThread(Job* job)
{ {
// Wait until resource is available // Wait until resource is available
fResource->Lock(); fResource->Lock();
@@ -615,7 +629,8 @@ void Printer::PrintThread(Job* job)
// Returns: // Returns:
// 0 always. // 0 always.
// --------------------------------------------------------------- // ---------------------------------------------------------------
status_t Printer::print_thread(void* data) status_t
Printer::print_thread(void* data)
{ {
Job* job = static_cast<Job*>(data); Job* job = static_cast<Job*>(data);
job->GetPrinter()->PrintThread(job); job->GetPrinter()->PrintThread(job);
@@ -629,7 +644,8 @@ status_t Printer::print_thread(void* data)
// Sets the status of the current spool job to "processing" and // Sets the status of the current spool job to "processing" and
// starts the print_thread. // starts the print_thread.
// --------------------------------------------------------------- // ---------------------------------------------------------------
void Printer::StartPrintThread() void
Printer::StartPrintThread()
{ {
Acquire(); Acquire();
thread_id tid = spawn_thread(print_thread, "print", B_NORMAL_PRIORITY, (void*)fJob); thread_id tid = spawn_thread(print_thread, "print", B_NORMAL_PRIORITY, (void*)fJob);
+22 -7
View File
@@ -22,11 +22,14 @@ Resource::Resource(const char* transport, const char* address, const char* conne
} }
} }
Resource::~Resource() { Resource::~Resource() {
if (fResourceAvailable > 0) delete_sem(fResourceAvailable); if (fResourceAvailable > 0) delete_sem(fResourceAvailable);
} }
bool Resource::NeedsLocking() {
bool
Resource::NeedsLocking() {
// TODO R2: Provide API to query that information // TODO R2: Provide API to query that information
// ATM: Print jobs are not processed sequentially // ATM: Print jobs are not processed sequentially
// if the transport add-on is either "Print To File" // if the transport add-on is either "Print To File"
@@ -38,30 +41,39 @@ bool Resource::NeedsLocking() {
|| fTransport == ""); || fTransport == "");
} }
bool Resource::Equals(const char* transport, const char* address, const char* connection) {
bool
Resource::Equals(const char* transport, const char* address, const char* connection) {
return fTransport == transport && return fTransport == transport &&
fTransportAddress == address && fTransportAddress == address &&
fConnection == connection; fConnection == connection;
} }
bool Resource::Lock() {
bool
Resource::Lock() {
if (fResourceAvailable > 0) { if (fResourceAvailable > 0) {
return acquire_sem(fResourceAvailable) == B_NO_ERROR; return acquire_sem(fResourceAvailable) == B_NO_ERROR;
} }
return true; return true;
} }
void Resource::Unlock() {
void
Resource::Unlock() {
if (fResourceAvailable > 0) { if (fResourceAvailable > 0) {
release_sem(fResourceAvailable); release_sem(fResourceAvailable);
} }
} }
ResourceManager::~ResourceManager() { ResourceManager::~ResourceManager() {
ASSERT(fResources.CountItems() == 0); ASSERT(fResources.CountItems() == 0);
} }
Resource* ResourceManager::Find(const char* transport, const char* address, const char* connection) {
Resource*
ResourceManager::Find(const char* transport, const char* address, const char* connection) {
for (int i = 0; i < fResources.CountItems(); i ++) { for (int i = 0; i < fResources.CountItems(); i ++) {
Resource* r = fResources.ItemAt(i); Resource* r = fResources.ItemAt(i);
if (r->Equals(transport, address, connection)) return r; if (r->Equals(transport, address, connection)) return r;
@@ -69,7 +81,9 @@ Resource* ResourceManager::Find(const char* transport, const char* address, cons
return NULL; return NULL;
} }
Resource* ResourceManager::Allocate(const char* transport, const char* address, const char* connection) {
Resource*
ResourceManager::Allocate(const char* transport, const char* address, const char* connection) {
Resource* r = Find(transport, address, connection); Resource* r = Find(transport, address, connection);
if (r == NULL) { if (r == NULL) {
r = new Resource(transport, address, connection); r = new Resource(transport, address, connection);
@@ -81,7 +95,8 @@ Resource* ResourceManager::Allocate(const char* transport, const char* address,
} }
void ResourceManager::Free(Resource* r) { void
ResourceManager::Free(Resource* r) {
if (r->Release()) { if (r->Release()) {
fResources.RemoveItem(r); fResources.RemoveItem(r);
} }
+23 -7
View File
@@ -9,6 +9,7 @@
#include <StorageKit.h> #include <StorageKit.h>
// Implementation of AppSettings // Implementation of AppSettings
AppSettings::AppSettings(const char* mimetype, const char* printer) AppSettings::AppSettings(const char* mimetype, const char* printer)
@@ -42,24 +43,33 @@ Settings::Settings()
{ {
} }
Settings::~Settings() { Settings::~Settings() {
fSingleton = NULL; fSingleton = NULL;
} }
Settings* Settings::GetSettings() {
Settings*
Settings::GetSettings() {
if (fSingleton == NULL) fSingleton = new Settings(); if (fSingleton == NULL) fSingleton = new Settings();
return fSingleton; return fSingleton;
} }
void Settings::RemoveAppSettings(int i) {
void
Settings::RemoveAppSettings(int i) {
delete fApps.RemoveItemAt(i); delete fApps.RemoveItemAt(i);
} }
void Settings::RemovePrinterSettings(int i) {
void
Settings::RemovePrinterSettings(int i) {
delete fPrinters.RemoveItemAt(i); delete fPrinters.RemoveItemAt(i);
} }
AppSettings* Settings::FindAppSettings(const char* mimeType) {
AppSettings*
Settings::FindAppSettings(const char* mimeType) {
for (int i = AppSettingsCount()-1; i >= 0; i --) { for (int i = AppSettingsCount()-1; i >= 0; i --) {
if (strcmp(AppSettingsAt(i)->GetMimeType(), mimeType) == 0) if (strcmp(AppSettingsAt(i)->GetMimeType(), mimeType) == 0)
return AppSettingsAt(i); return AppSettingsAt(i);
@@ -67,7 +77,9 @@ AppSettings* Settings::FindAppSettings(const char* mimeType) {
return NULL; return NULL;
} }
PrinterSettings* Settings::FindPrinterSettings(const char* printer) {
PrinterSettings*
Settings::FindPrinterSettings(const char* printer) {
for (int i = PrinterSettingsCount()-1; i >= 0; i --) { for (int i = PrinterSettingsCount()-1; i >= 0; i --) {
if (strcmp(PrinterSettingsAt(i)->GetPrinter(), printer) == 0) if (strcmp(PrinterSettingsAt(i)->GetPrinter(), printer) == 0)
return PrinterSettingsAt(i); return PrinterSettingsAt(i);
@@ -75,7 +87,9 @@ PrinterSettings* Settings::FindPrinterSettings(const char* printer) {
return NULL; return NULL;
} }
void Settings::Save(BFile* file) {
void
Settings::Save(BFile* file) {
BMessage m; BMessage m;
// store application settings // store application settings
for (int i = 0; i < AppSettingsCount(); i++) { for (int i = 0; i < AppSettingsCount(); i++) {
@@ -97,7 +111,9 @@ void Settings::Save(BFile* file) {
m.Flatten(file); m.Flatten(file);
} }
void Settings::Load(BFile* file) {
void
Settings::Load(BFile* file) {
BMessage m; BMessage m;
if (m.Unflatten(file) == B_OK) { if (m.Unflatten(file) == B_OK) {
// restore application settings // restore application settings
+9 -3
View File
@@ -27,7 +27,9 @@ static property_info prop_list[] = {
{ 0 } // terminate list { 0 } // terminate list
}; };
void Transport::HandleScriptingCommand(BMessage* msg)
void
Transport::HandleScriptingCommand(BMessage* msg)
{ {
status_t rc = B_ERROR; status_t rc = B_ERROR;
BString propName; BString propName;
@@ -72,7 +74,9 @@ void Transport::HandleScriptingCommand(BMessage* msg)
} }
} }
BHandler* Transport::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
BHandler*
Transport::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
int32 form, const char* prop) int32 form, const char* prop)
{ {
BPropertyInfo prop_info(prop_list); BPropertyInfo prop_info(prop_list);
@@ -88,7 +92,9 @@ BHandler* Transport::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec
return rc; return rc;
} }
status_t Transport::GetSupportedSuites(BMessage* msg)
status_t
Transport::GetSupportedSuites(BMessage* msg)
{ {
msg->AddString("suites", "application/x-vnd.OpenBeOS-transport"); msg->AddString("suites", "application/x-vnd.OpenBeOS-transport");
+24 -14
View File
@@ -14,9 +14,10 @@
#include <image.h> #include <image.h>
#include <Entry.h> #include <Entry.h>
// ---------------------------------------------------------------
BObjectList<Transport> Transport::sTransports; BObjectList<Transport> Transport::sTransports;
// --------------------------------------------------------------- // ---------------------------------------------------------------
// Find [static] // Find [static]
// //
@@ -29,7 +30,8 @@ BObjectList<Transport> Transport::sTransports;
// Returns: // Returns:
// Pointer to Transport object, or NULL if not found. // Pointer to Transport object, or NULL if not found.
// --------------------------------------------------------------- // ---------------------------------------------------------------
Transport* Transport::Find(const BString& name) Transport*
Transport::Find(const BString& name)
{ {
// Look in list to find printer definition // Look in list to find printer definition
for (int32 idx=0; idx < sTransports.CountItems(); idx++) { for (int32 idx=0; idx < sTransports.CountItems(); idx++) {
@@ -42,26 +44,30 @@ Transport* Transport::Find(const BString& name)
return NULL; return NULL;
} }
// ---------------------------------------------------------------
Transport* Transport::At(int32 idx) Transport*
Transport::At(int32 idx)
{ {
return sTransports.ItemAt(idx); return sTransports.ItemAt(idx);
} }
// ---------------------------------------------------------------
void Transport::Remove(Transport* transport) void
Transport::Remove(Transport* transport)
{ {
sTransports.RemoveItem(transport); sTransports.RemoveItem(transport);
} }
// ---------------------------------------------------------------
int32 Transport::CountTransports() int32
Transport::CountTransports()
{ {
return sTransports.CountItems(); return sTransports.CountItems();
} }
// ---------------------------------------------------------------
status_t Transport::Scan(directory_which which) status_t
Transport::Scan(directory_which which)
{ {
BDirectory dir; BDirectory dir;
status_t rc; status_t rc;
@@ -98,6 +104,7 @@ status_t Transport::Scan(directory_which which)
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// Transport [constructor] // Transport [constructor]
// //
@@ -141,14 +148,15 @@ Transport::Transport(const BPath& path)
sTransports.AddItem(this); sTransports.AddItem(this);
} }
// ---------------------------------------------------------------
Transport::~Transport() Transport::~Transport()
{ {
sTransports.RemoveItem(this); sTransports.RemoveItem(this);
} }
// ---------------------------------------------------------------
status_t Transport::ListAvailablePorts(BMessage* msg) status_t
Transport::ListAvailablePorts(BMessage* msg)
{ {
status_t (*list_ports)(BMessage*); status_t (*list_ports)(BMessage*);
image_id id = fImageID; image_id id = fImageID;
@@ -174,6 +182,7 @@ done:
return rc; return rc;
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// MessageReceived // MessageReceived
// //
@@ -182,7 +191,8 @@ done:
// Parameters: // Parameters:
// msg - message. // msg - message.
// --------------------------------------------------------------- // ---------------------------------------------------------------
void Transport::MessageReceived(BMessage* msg) void
Transport::MessageReceived(BMessage* msg)
{ {
switch(msg->what) { switch(msg->what) {
case B_GET_PROPERTY: case B_GET_PROPERTY: