1 /* 2 * Copyright 2008, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ithamar R. Adema 7 */ 8 9 #include "Transport.h" 10 11 // BeOS API 12 #include <PropertyInfo.h> 13 #include <Messenger.h> 14 #include <Message.h> 15 #include <AppDefs.h> 16 17 static property_info prop_list[] = { 18 { "Name", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 19 "Get name of transport" }, 20 { "Ports", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 21 "Get currently available ports/devices" }, 22 { 0 } // terminate list 23 }; 24 25 void Transport::HandleScriptingCommand(BMessage* msg) 26 { 27 status_t rc = B_ERROR; 28 BString propName; 29 BString result; 30 BMessage spec; 31 int32 idx; 32 33 if ((rc=msg->GetCurrentSpecifier(&idx,&spec)) == B_OK && 34 (rc=spec.FindString("property",&propName)) == B_OK) { 35 switch(msg->what) { 36 case B_GET_PROPERTY: 37 if (propName == "Name") 38 result = Name(); 39 else if (propName == "Ports") { 40 // Need to duplicate messaging code, as our result is a complex 41 // bmessage, not a string :( 42 BMessage reply(B_REPLY); 43 rc = ListAvailablePorts(&reply); 44 reply.AddInt32("error", rc); 45 msg->SendReply(&reply); 46 break; 47 } else { // If unknown scripting request, let superclas handle it 48 Inherited::MessageReceived(msg); 49 break; 50 } 51 52 BMessage reply(B_REPLY); 53 reply.AddString("result", result); 54 reply.AddInt32("error", rc); 55 msg->SendReply(&reply); 56 break; 57 } 58 } 59 else { 60 // If GetSpecifier failed 61 if (idx == -1) { 62 BMessage reply(B_REPLY); 63 reply.AddMessenger("result", BMessenger(this)); 64 reply.AddInt32("error", B_OK); 65 msg->SendReply(&reply); 66 } 67 } 68 } 69 70 BHandler* Transport::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec, 71 int32 form, const char* prop) 72 { 73 BPropertyInfo prop_info(prop_list); 74 BHandler* rc = this; 75 76 int32 idx; 77 switch( idx=prop_info.FindMatch(msg,0,spec,form,prop) ) { 78 case B_ERROR: 79 rc = Inherited::ResolveSpecifier(msg,index,spec,form,prop); 80 break; 81 } 82 83 return rc; 84 } 85 86 status_t Transport::GetSupportedSuites(BMessage* msg) 87 { 88 msg->AddString("suites", "application/x-vnd.OpenBeOS-transport"); 89 90 BPropertyInfo prop_info(prop_list); 91 msg->AddFlat("messages", &prop_info); 92 93 return Inherited::GetSupportedSuites(msg); 94 } 95