2 * Copyright 2008, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
12 #include <PrintTransportAddOn.h>
13 #include <Application.h>
18 BObjectList
<Transport
> Transport::sTransports
;
21 // ---------------------------------------------------------------
24 // Searches the static object list for a transport object with the
28 // name - Printer definition name we're looking for.
31 // Pointer to Transport object, or NULL if not found.
32 // ---------------------------------------------------------------
34 Transport::Find(const BString
& name
)
36 // Look in list to find printer definition
37 for (int32 index
= 0; index
< sTransports
.CountItems(); index
++) {
38 if (name
== sTransports
.ItemAt(index
)->Name())
39 return sTransports
.ItemAt(index
);
42 // None found, so return NULL
48 Transport::At(int32 index
)
50 return sTransports
.ItemAt(index
);
55 Transport::Remove(Transport
* transport
)
57 sTransports
.RemoveItem(transport
);
62 Transport::CountTransports()
64 return sTransports
.CountItems();
69 Transport::Scan(directory_which which
)
74 // Try to find specified transport addon directory
75 if ((result
= find_directory(which
, &path
)) != B_OK
)
78 if ((result
= path
.Append("Print/transport")) != B_OK
)
82 if ((result
= dir
.SetTo(path
.Path())) != B_OK
)
85 // Walk over all entries in directory
87 while(dir
.GetNextEntry(&entry
) == B_OK
) {
91 if (entry
.GetPath(&path
) != B_OK
)
94 // If we have loaded the transport from a previous scanned directory,
96 if (Transport::Find(path
.Leaf()) != NULL
)
99 be_app
->AddHandler(new Transport(path
));
106 // ---------------------------------------------------------------
107 // Transport [constructor]
109 // Initializes the transport object with data read from the
110 // attributes attached to the printer definition node.
113 // node - Printer definition node for this printer.
117 // ---------------------------------------------------------------
118 Transport::Transport(const BPath
& path
)
119 : BHandler(B_EMPTY_STRING
),
124 // Load transport addon
125 image_id id
= ::load_add_on(path
.Path());
129 // Find transport_features symbol, to determine if we need to keep
130 // this transport loaded
131 int* transportFeaturesPointer
;
132 if (get_image_symbol(id
, B_TRANSPORT_FEATURES_SYMBOL
,
133 B_SYMBOL_TYPE_DATA
, (void**)&transportFeaturesPointer
) != B_OK
) {
136 fFeatures
= *transportFeaturesPointer
;
138 if (fFeatures
& B_TRANSPORT_IS_HOTPLUG
) {
139 // We are hotpluggable; so keep us loaded!
142 // No extended Transport support; so no need to keep loaded
147 sTransports
.AddItem(this);
151 Transport::~Transport()
153 sTransports
.RemoveItem(this);
158 Transport::ListAvailablePorts(BMessage
* msg
)
160 status_t (*list_ports
)(BMessage
*);
161 image_id id
= fImageID
;
164 // Load image if not loaded yet
165 if (id
== -1 && (id
= load_add_on(fPath
.Path())) < 0)
168 // Get pointer to addon function
169 if ((rc
= get_image_symbol(id
, B_TRANSPORT_LIST_PORTS_SYMBOL
,
170 B_SYMBOL_TYPE_TEXT
, (void**)&list_ports
)) != B_OK
)
174 rc
= (*list_ports
)(msg
);
177 // clean up if needed
185 // ---------------------------------------------------------------
188 // Handle scripting messages.
192 // ---------------------------------------------------------------
194 Transport::MessageReceived(BMessage
* msg
)
199 case B_CREATE_PROPERTY
:
200 case B_DELETE_PROPERTY
:
201 case B_COUNT_PROPERTIES
:
202 case B_EXECUTE_PROPERTY
:
203 HandleScriptingCommand(msg
);
207 Inherited::MessageReceived(msg
);