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.
34 #include "AddOnHostApp.h"
35 #include "AddOnHostProtocol.h"
39 #include <MediaRoster.h>
44 __USE_CORTEX_NAMESPACE
45 using namespace addon_host
;
49 : BApplication(g_appSignature
)
67 App::MessageReceived(BMessage
* message
)
71 // message->PrintToStream();
73 switch(message
->what
) {
77 dormant_node_info info
;
80 err
= message
->FindData("info", B_RAW_TYPE
, &data
, &dataSize
);
83 "!!! App::MessageReceived(M_INSTANTIATE):\n"
84 " missing 'info'\n"));
87 if (dataSize
!= sizeof(info
)) {
89 "* App::MessageReceived(M_INSTANTIATE):\n"
90 " warning: 'info' size mismatch\n"));
91 if (dataSize
> ssize_t(sizeof(info
)))
92 dataSize
= sizeof(info
);
94 memcpy(reinterpret_cast<void *>(&info
), data
, dataSize
);
96 // attempt to instantiate
97 BMediaRoster
* r
= BMediaRoster::Roster();
99 err
= r
->InstantiateDormantNode(info
, &node
);
103 // err = r->GetNodeFor(node.node, &node);
107 BMessage
m(M_INSTANTIATE_COMPLETE
);
108 m
.AddInt32("node_id", node
.node
);
109 message
->SendReply(&m
);
112 BMessage
m(M_INSTANTIATE_FAILED
);
113 m
.AddInt32("error", err
);
114 message
->SendReply(&m
);
126 err
= message
->FindData("info", B_RAW_TYPE
, &data
, &dataSize
);
129 "!!! App::MessageReceived(M_RELEASE):\n"
130 " missing 'info'\n"));
133 if (dataSize
!= sizeof(info
)) {
135 "* App::MessageReceived(M_RELEASE):\n"
136 " warning: 'info' size mismatch\n"));
137 if(dataSize
> ssize_t(sizeof(info
)))
138 dataSize
= sizeof(info
);
140 memcpy(reinterpret_cast<void *>(&info
), data
, dataSize
);
142 // attempt to release
143 BMediaRoster
* r
= BMediaRoster::Roster();
145 err
= r
->ReleaseNode(info
.node
);
149 BMessage
m(M_RELEASE_COMPLETE
);
150 m
.AddInt32("node_id", info
.node
.node
);
151 message
->SendReply(&m
);
154 BMessage
m(M_RELEASE_FAILED
);
155 m
.AddInt32("error", err
);
156 message
->SendReply(&m
);
163 _inherited::MessageReceived(message
);
169 main(int argc
, char** argv
)
172 if (argc
< 2 || strcmp(argv
[1], "--addon-host") != 0) {
173 BAlert
* alert
= new BAlert("Cortex AddOnHost",
174 "This program runs in the background, and is started automatically "
175 "by Cortex when necessary. You probably don't want to start it manually.",
177 alert
->SetShortcut(1, B_ESCAPE
);
178 int32 response
= alert
->Go();