2 * Copyright 2008, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
10 #include "Transport.h"
16 #include <Messenger.h>
17 #include <PropertyInfo.h>
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "Transport Scripting"
24 static property_info prop_list
[] = {
25 { "Name", { B_GET_PROPERTY
}, { B_DIRECT_SPECIFIER
},
26 B_TRANSLATE_MARK("Get name of transport") },
27 { "Ports", { B_GET_PROPERTY
}, { B_DIRECT_SPECIFIER
},
28 B_TRANSLATE_MARK("Get currently available ports/devices") },
30 { 0 } // terminate list
35 Transport::HandleScriptingCommand(BMessage
* msg
)
37 status_t rc
= B_ERROR
;
43 if ((rc
=msg
->GetCurrentSpecifier(&idx
,&spec
)) == B_OK
44 && (rc
=spec
.FindString("property",&propName
)) == B_OK
) {
47 if (propName
== "Name")
49 else if (propName
== "Ports") {
50 // Need to duplicate messaging code, as our result is a
51 // complex bmessage, not a string :(
52 BMessage
reply(B_REPLY
);
53 rc
= ListAvailablePorts(&reply
);
54 reply
.AddInt32("error", rc
);
55 msg
->SendReply(&reply
);
58 // If unknown scripting request, let superclas handle it
59 Inherited::MessageReceived(msg
);
63 BMessage
reply(B_REPLY
);
64 reply
.AddString("result", result
);
65 reply
.AddInt32("error", rc
);
66 msg
->SendReply(&reply
);
70 // If GetSpecifier failed
72 BMessage
reply(B_REPLY
);
73 reply
.AddMessenger("result", BMessenger(this));
74 reply
.AddInt32("error", B_OK
);
75 msg
->SendReply(&reply
);
82 Transport::ResolveSpecifier(BMessage
* msg
, int32 index
, BMessage
* spec
,
83 int32 form
, const char* prop
)
85 BPropertyInfo
prop_info(prop_list
);
89 switch (idx
=prop_info
.FindMatch(msg
,0,spec
,form
,prop
)) {
91 rc
= Inherited::ResolveSpecifier(msg
,index
,spec
,form
,prop
);
100 Transport::GetSupportedSuites(BMessage
* msg
)
102 msg
->AddString("suites", "application/x-vnd.OpenBeOS-transport");
104 static bool localized
= false;
107 for (int i
= 0; prop_list
[i
].name
!= NULL
; i
++)
108 prop_list
[i
].usage
= B_TRANSLATE_NOCOLLECT(prop_list
[i
].usage
);
111 BPropertyInfo
prop_info(prop_list
);
112 msg
->AddFlat("messages", &prop_info
);
114 return Inherited::GetSupportedSuites(msg
);