2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "AddOnHost.h"
33 #include "AddOnHostProtocol.h"
35 #include <Application.h>
38 #include <MediaNode.h>
39 #include <MediaRoster.h>
40 #include <Messenger.h>
49 __USE_CORTEX_NAMESPACE
51 // -------------------------------------------------------- //
53 // -------------------------------------------------------- //
55 BMessenger
AddOnHost::s_messenger
;
57 // -------------------------------------------------------- //
58 // *** static interface
59 // -------------------------------------------------------- //
62 status_t
AddOnHost::FindInstance(
63 BMessenger
* outMessenger
) {
67 // no current app? launch one
68 if(!s_messenger
.IsValid()) {
69 s_messenger
= BMessenger(
70 addon_host::g_appSignature
,
76 if(!s_messenger
.IsValid())
80 *outMessenger
= s_messenger
;
85 status_t
AddOnHost::Kill(
88 if(!s_messenger
.IsValid())
91 status_t err
= kill_team(s_messenger
.Team());
96 status_t
AddOnHost::Launch(
97 BMessenger
* outMessenger
) {
99 if(s_messenger
.IsValid())
100 return B_NOT_ALLOWED
;
106 err
= be_roster
->FindApp(addon_host::g_appSignature
, &appRef
);
112 const char* arg
= "--addon-host";
113 err
= be_roster
->Launch(
121 // fetch messenger to the new app and return it
122 s_messenger
= BMessenger(
123 addon_host::g_appSignature
,
129 if(!s_messenger
.IsValid())
133 *outMessenger
= s_messenger
;
139 status_t
AddOnHost::InstantiateDormantNode(
140 const dormant_node_info
& info
,
146 if(!s_messenger
.IsValid()) {
152 "!!! AddOnHost::InstantiateDormantNode(): Launch() failed:\n"
160 ASSERT(s_messenger
.IsValid());
161 BMessage
request(addon_host::M_INSTANTIATE
);
162 request
.AddData("info", B_RAW_TYPE
, &info
, sizeof(dormant_node_info
));
164 BMessage
reply(B_NO_REPLY
);
165 err
= s_messenger
.SendMessage(
172 // "### SendMessage() returned '%s'\n", strerror(err)));
176 "!!! AddOnHost::InstantiateDormantNode(): SendMessage() failed:\n"
182 if(reply
.what
== B_NO_REPLY
) {
184 "!!! AddOnHost::InstantiateDormantNode(): no reply.\n"));
188 if(reply
.what
== addon_host::M_INSTANTIATE_COMPLETE
) {
189 media_node_id nodeID
;
192 err
= reply
.FindInt32("node_id", &nodeID
);
195 "!!! AddOnHost::InstantiateDormantNode(): 'node_id' missing from reply.\n"));
200 err
= BMediaRoster::Roster()->GetNodeFor(nodeID
, outNode
);
203 "!!! AddOnHost::InstantiateDormantNode(): node missing!\n"));
207 // // now solely owned by the add-on host team
208 // BMediaRoster::Roster()->ReleaseNode(*outNode);
214 return (reply
.FindInt32("error", &err
) == B_OK
) ? err
: B_ERROR
;
218 status_t
AddOnHost::ReleaseInternalNode(
219 const live_node_info
& info
,
224 if(!s_messenger
.IsValid()) {
230 "!!! AddOnHost::ReleaseInternalNode(): Launch() failed:\n"
238 ASSERT(s_messenger
.IsValid());
239 BMessage
request(addon_host::M_RELEASE
);
240 request
.AddData("info", B_RAW_TYPE
, &info
, sizeof(live_node_info
));
242 BMessage
reply(B_NO_REPLY
);
243 err
= s_messenger
.SendMessage(
252 "!!! AddOnHost::ReleaseInternalNode(): SendMessage() failed:\n"
258 if(reply
.what
== B_NO_REPLY
) {
260 "!!! AddOnHost::InstantiateDormantNode(): no reply.\n"));
264 if(reply
.what
== addon_host::M_RELEASE_COMPLETE
) {
269 return (reply
.FindInt32("error", &err
) == B_OK
) ? err
: B_ERROR
;