Slight rework of my previous commit... now ports can be asked too ;)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23928 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -35,18 +35,18 @@ THE SOFTWARE.
|
||||
#include <Directory.h>
|
||||
#include <Message.h>
|
||||
|
||||
// int transport_features; symbol name
|
||||
#define B_TRANSPORT_LIST_PORTS_SYMBOL "list_transport_ports"
|
||||
#define B_TRANSPORT_FEATURES_SYMBOL "transport_features"
|
||||
|
||||
// Bit values for 'transport_features'
|
||||
enum {
|
||||
B_TRANSPORT_SUPPORTS_PROBE = 1,
|
||||
B_TRANSPORT_SUPPORTS_SHARING = 2,
|
||||
B_TRANSPORT_IS_HOTPLUG = 1,
|
||||
B_TRANSPORT_IS_NETWORK = 2,
|
||||
};
|
||||
|
||||
// to be implemented by the transport add-on
|
||||
extern "C" BDataIO* instantiate_transport(BDirectory* printer, BMessage* msg);
|
||||
extern "C" status_t install_transport_probe(void);
|
||||
extern "C" status_t list_transport_ports(BMessage* msg);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
static property_info prop_list[] = {
|
||||
{ "Name", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER },
|
||||
"Get name of transport" },
|
||||
{ "Ports", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER },
|
||||
"Get currently available ports/devices" },
|
||||
{ 0 } // terminate list
|
||||
};
|
||||
|
||||
@@ -33,8 +35,16 @@ void Transport::HandleScriptingCommand(BMessage* msg)
|
||||
switch(msg->what) {
|
||||
case B_GET_PROPERTY:
|
||||
if (propName == "Name")
|
||||
result = fName;
|
||||
else { // If unknown scripting request, let superclas handle it
|
||||
result = Name();
|
||||
else if (propName == "Ports") {
|
||||
// Need to duplicate messaging code, as our result is a complex
|
||||
// bmessage, not a string :(
|
||||
BMessage reply(B_REPLY);
|
||||
rc = ListAvailablePorts(&reply);
|
||||
reply.AddInt32("error", rc);
|
||||
msg->SendReply(&reply);
|
||||
break;
|
||||
} else { // If unknown scripting request, let superclas handle it
|
||||
Inherited::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ status_t Transport::Scan(directory_which which)
|
||||
// ---------------------------------------------------------------
|
||||
Transport::Transport(const BPath& path)
|
||||
: BHandler(B_EMPTY_STRING),
|
||||
fName(path.Leaf()),
|
||||
fPath(path),
|
||||
fImageID(-1),
|
||||
fFeatures(0)
|
||||
{
|
||||
@@ -130,9 +130,8 @@ Transport::Transport(const BPath& path)
|
||||
} else {
|
||||
fFeatures = *transport_features_ptr;
|
||||
|
||||
if (*transport_features_ptr & B_TRANSPORT_SUPPORTS_PROBE) {
|
||||
// Transport supports probing, so it needs to stay loaded...
|
||||
printf("IRA: Transport %s supports probing!\n", path.Path());
|
||||
if (*transport_features_ptr & B_TRANSPORT_IS_HOTPLUG) {
|
||||
// We are hotpluggable; so keep us loaded!
|
||||
fImageID = id;
|
||||
}
|
||||
else // No extended Transport support; so no need to keep loaded
|
||||
@@ -148,6 +147,33 @@ Transport::~Transport()
|
||||
sTransports.RemoveItem(this);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
status_t Transport::ListAvailablePorts(BMessage* msg)
|
||||
{
|
||||
status_t (*list_ports)(BMessage*);
|
||||
image_id id = fImageID;
|
||||
status_t rc = B_OK;
|
||||
|
||||
// Load image if not loaded yet
|
||||
if (id == -1 && (id=load_add_on(fPath.Path())) < 0)
|
||||
return id;
|
||||
|
||||
// Get pointer to addon function
|
||||
if ((rc=get_image_symbol(id, B_TRANSPORT_LIST_PORTS_SYMBOL,
|
||||
B_SYMBOL_TYPE_TEXT, (void**)&list_ports)) != B_OK)
|
||||
goto done;
|
||||
|
||||
// run addon...
|
||||
rc = (*list_ports)(msg);
|
||||
|
||||
done:
|
||||
// clean up if needed
|
||||
if (fImageID != id)
|
||||
unload_add_on(id);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// MessageReceived
|
||||
//
|
||||
|
||||
@@ -24,7 +24,9 @@ public:
|
||||
Transport(const BPath& path);
|
||||
~Transport();
|
||||
|
||||
const BString& Name() const { return fName; }
|
||||
BString Name() const { return fPath.Leaf(); }
|
||||
|
||||
status_t ListAvailablePorts(BMessage* msg);
|
||||
|
||||
static status_t Scan(directory_which which);
|
||||
|
||||
@@ -42,7 +44,7 @@ public:
|
||||
int32 form, const char* prop);
|
||||
|
||||
private:
|
||||
BString fName;
|
||||
BPath fPath;
|
||||
long fImageID;
|
||||
int fFeatures;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user