162cb58a8SIthamar R. Adema /* 262cb58a8SIthamar R. Adema * Copyright 2008, Haiku. All rights reserved. 362cb58a8SIthamar R. Adema * Distributed under the terms of the MIT License. 462cb58a8SIthamar R. Adema * 562cb58a8SIthamar R. Adema * Authors: 662cb58a8SIthamar R. Adema * Ithamar R. Adema 762cb58a8SIthamar R. Adema */ 862cb58a8SIthamar R. Adema 9cc507fa3SWim van der Meer 1062cb58a8SIthamar R. Adema #include "Transport.h" 1162cb58a8SIthamar R. Adema 1262cb58a8SIthamar R. Adema #include <AppDefs.h> 138b0a06adSMichael Pfeiffer #include <Catalog.h> 148b0a06adSMichael Pfeiffer #include <Locale.h> 158b0a06adSMichael Pfeiffer #include <Message.h> 168b0a06adSMichael Pfeiffer #include <Messenger.h> 178b0a06adSMichael Pfeiffer #include <PropertyInfo.h> 188b0a06adSMichael Pfeiffer 198b0a06adSMichael Pfeiffer 20*546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 21*546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Transport Scripting" 228b0a06adSMichael Pfeiffer 2362cb58a8SIthamar R. Adema 2462cb58a8SIthamar R. Adema static property_info prop_list[] = { 2562cb58a8SIthamar R. Adema { "Name", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 268b0a06adSMichael Pfeiffer B_TRANSLATE_MARK("Get name of transport") }, 27eb5a25caSIthamar R. Adema { "Ports", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 288b0a06adSMichael Pfeiffer B_TRANSLATE_MARK("Get currently available ports/devices") }, 2962cb58a8SIthamar R. Adema { 0 } // terminate list 3062cb58a8SIthamar R. Adema }; 3162cb58a8SIthamar R. Adema 329abbe87fSMichael Pfeiffer 339abbe87fSMichael Pfeiffer void 349abbe87fSMichael Pfeiffer Transport::HandleScriptingCommand(BMessage* msg) 3562cb58a8SIthamar R. Adema { 3662cb58a8SIthamar R. Adema status_t rc = B_ERROR; 3762cb58a8SIthamar R. Adema BString propName; 3862cb58a8SIthamar R. Adema BString result; 3962cb58a8SIthamar R. Adema BMessage spec; 4062cb58a8SIthamar R. Adema int32 idx; 4162cb58a8SIthamar R. Adema 42cc507fa3SWim van der Meer if ((rc=msg->GetCurrentSpecifier(&idx,&spec)) == B_OK 43cc507fa3SWim van der Meer && (rc=spec.FindString("property",&propName)) == B_OK) { 4462cb58a8SIthamar R. Adema switch(msg->what) { 4562cb58a8SIthamar R. Adema case B_GET_PROPERTY: 4662cb58a8SIthamar R. Adema if (propName == "Name") 47eb5a25caSIthamar R. Adema result = Name(); 48eb5a25caSIthamar R. Adema else if (propName == "Ports") { 49cc507fa3SWim van der Meer // Need to duplicate messaging code, as our result is a 50cc507fa3SWim van der Meer // complex bmessage, not a string :( 51eb5a25caSIthamar R. Adema BMessage reply(B_REPLY); 52eb5a25caSIthamar R. Adema rc = ListAvailablePorts(&reply); 53eb5a25caSIthamar R. Adema reply.AddInt32("error", rc); 54eb5a25caSIthamar R. Adema msg->SendReply(&reply); 55eb5a25caSIthamar R. Adema break; 56cc507fa3SWim van der Meer } else { 57cc507fa3SWim van der Meer // If unknown scripting request, let superclas handle it 5862cb58a8SIthamar R. Adema Inherited::MessageReceived(msg); 5962cb58a8SIthamar R. Adema break; 6062cb58a8SIthamar R. Adema } 6162cb58a8SIthamar R. Adema 6262cb58a8SIthamar R. Adema BMessage reply(B_REPLY); 6362cb58a8SIthamar R. Adema reply.AddString("result", result); 6462cb58a8SIthamar R. Adema reply.AddInt32("error", rc); 6562cb58a8SIthamar R. Adema msg->SendReply(&reply); 6662cb58a8SIthamar R. Adema break; 6762cb58a8SIthamar R. Adema } 68cc507fa3SWim van der Meer } else { 6962cb58a8SIthamar R. Adema // If GetSpecifier failed 7062cb58a8SIthamar R. Adema if (idx == -1) { 7162cb58a8SIthamar R. Adema BMessage reply(B_REPLY); 7262cb58a8SIthamar R. Adema reply.AddMessenger("result", BMessenger(this)); 7362cb58a8SIthamar R. Adema reply.AddInt32("error", B_OK); 7462cb58a8SIthamar R. Adema msg->SendReply(&reply); 7562cb58a8SIthamar R. Adema } 7662cb58a8SIthamar R. Adema } 7762cb58a8SIthamar R. Adema } 7862cb58a8SIthamar R. Adema 799abbe87fSMichael Pfeiffer 809abbe87fSMichael Pfeiffer BHandler* 819abbe87fSMichael Pfeiffer Transport::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec, 8262cb58a8SIthamar R. Adema int32 form, const char* prop) 8362cb58a8SIthamar R. Adema { 8462cb58a8SIthamar R. Adema BPropertyInfo prop_info(prop_list); 8562cb58a8SIthamar R. Adema BHandler* rc = this; 8662cb58a8SIthamar R. Adema 8762cb58a8SIthamar R. Adema int32 idx; 8862cb58a8SIthamar R. Adema switch (idx=prop_info.FindMatch(msg,0,spec,form,prop)) { 8962cb58a8SIthamar R. Adema case B_ERROR: 9062cb58a8SIthamar R. Adema rc = Inherited::ResolveSpecifier(msg,index,spec,form,prop); 9162cb58a8SIthamar R. Adema break; 9262cb58a8SIthamar R. Adema } 9362cb58a8SIthamar R. Adema 9462cb58a8SIthamar R. Adema return rc; 9562cb58a8SIthamar R. Adema } 9662cb58a8SIthamar R. Adema 979abbe87fSMichael Pfeiffer 989abbe87fSMichael Pfeiffer status_t 999abbe87fSMichael Pfeiffer Transport::GetSupportedSuites(BMessage* msg) 10062cb58a8SIthamar R. Adema { 10162cb58a8SIthamar R. Adema msg->AddString("suites", "application/x-vnd.OpenBeOS-transport"); 10262cb58a8SIthamar R. Adema 1038b0a06adSMichael Pfeiffer static bool localized = false; 1048b0a06adSMichael Pfeiffer if (!localized) { 1058b0a06adSMichael Pfeiffer localized = true; 1068b0a06adSMichael Pfeiffer for (int i = 0; prop_list[i].name != NULL; i ++) 1078eff03f5SOliver Tappe prop_list[i].usage = B_TRANSLATE_NOCOLLECT(prop_list[i].usage); 1088b0a06adSMichael Pfeiffer } 1098b0a06adSMichael Pfeiffer 11062cb58a8SIthamar R. Adema BPropertyInfo prop_info(prop_list); 11162cb58a8SIthamar R. Adema msg->AddFlat("messages", &prop_info); 11262cb58a8SIthamar R. Adema 11362cb58a8SIthamar R. Adema return Inherited::GetSupportedSuites(msg); 11462cb58a8SIthamar R. Adema } 115