Updated to make media_addon_server work with the DormantNodeManager class

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@730 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2002-08-13 00:38:09 +00:00
parent f85924fecf
commit d6b71edf06
6 changed files with 170 additions and 52 deletions
+57 -17
View File
@@ -24,9 +24,12 @@
#include <string.h> #include <string.h>
#include <Locker.h> #include <Locker.h>
#include <Path.h> #include <Path.h>
#include <Entry.h>
#include <MediaAddOn.h> #include <MediaAddOn.h>
#include <Debug.h> #include <Debug.h>
#include "debug.h" #include "debug.h"
#include "PortPool.h"
#include "ServerInterface.h"
#include "DormantNodeManager.h" #include "DormantNodeManager.h"
static BPrivate::media::DormantNodeManager manager; static BPrivate::media::DormantNodeManager manager;
@@ -81,6 +84,8 @@ DormantNodeManager::GetAddon(media_addon_id id)
{ {
BMediaAddOn *addon; BMediaAddOn *addon;
printf("DormantNodeManager::GetAddon, id %d\n",id);
// first try to use a already loaded add-on // first try to use a already loaded add-on
addon = TryGetAddon(id); addon = TryGetAddon(id);
if (addon) if (addon)
@@ -91,7 +96,7 @@ DormantNodeManager::GetAddon(media_addon_id id)
// ok, it's not loaded, try to get the path // ok, it's not loaded, try to get the path
BPath path; BPath path;
if (B_OK != FindAddonPath(&path, id)) { if (B_OK != FindAddonPath(&path, id)) {
printf("can't find path for add-on %d\n",id); printf("DormantNodeManager::GetAddon: can't find path for add-on %d\n",id);
return NULL; return NULL;
} }
@@ -99,7 +104,7 @@ DormantNodeManager::GetAddon(media_addon_id id)
BMediaAddOn *newaddon; BMediaAddOn *newaddon;
image_id image; image_id image;
if (B_OK != LoadAddon(&newaddon, &image, path.Path(), id)) { if (B_OK != LoadAddon(&newaddon, &image, path.Path(), id)) {
printf("can't load add-on %d from path %s\n",id, path.Path()); printf("DormantNodeManager::GetAddon: can't load add-on %d from path %s\n",id, path.Path());
return NULL; return NULL;
} }
@@ -134,9 +139,12 @@ DormantNodeManager::PutAddon(media_addon_id id)
image_id image; image_id image;
bool unload; bool unload;
printf("DormantNodeManager::PutAddon, id %d\n",id);
fLock->Lock(); fLock->Lock();
if (!fAddonmap->GetPointer(id, &info)) { if (!fAddonmap->GetPointer(id, &info)) {
printf("failed to put add-on %d\n",id); printf("DormantNodeManager::PutAddon: failed to find add-on %d\n",id);
fLock->Unlock(); fLock->Unlock();
return; return;
} }
@@ -158,50 +166,82 @@ DormantNodeManager::PutAddon(media_addon_id id)
media_addon_id media_addon_id
DormantNodeManager::RegisterAddon(const char *path) DormantNodeManager::RegisterAddon(const char *path)
{ {
/*
xfer_server_register_mediaaddon msg; xfer_server_register_mediaaddon msg;
xfer_server_register_mediaaddon_reply reply; xfer_server_register_mediaaddon_reply reply;
port_id port; port_id port;
status_t rv; status_t rv;
int32 code; int32 code;
entry_ref tempref;
printf("DormantNodeManager::RegisterAddon, path %s\n",path);
rv = get_ref_for_path(path, &tempref);
if (rv != B_OK)
return 0;
msg.ref = tempref;
port = find_port("media_server port"); port = find_port("media_server port");
if (port <= B_OK) if (port <= B_OK)
return; return 0;
msg.reply_port = _PortPool->GetPort(); msg.reply_port = _PortPool->GetPort();
rv = write_port(port, SERVER_REGISTER_MEDIAADDON, &msg, sizeof(msg)); rv = write_port(port, SERVER_REGISTER_MEDIAADDON, &msg, sizeof(msg));
if (rv != B_OK) { if (rv != B_OK) {
_PortPool->PutPort(msg.reply_port); _PortPool->PutPort(msg.reply_port);
return; return 0;
} }
rv = read_port(msg.reply_port, &code, &reply, sizeof(reply)); rv = read_port(msg.reply_port, &code, &reply, sizeof(reply));
_PortPool->PutPort(msg.reply_port); _PortPool->PutPort(msg.reply_port);
if (rv < B_OK) if (rv < B_OK)
return; return 0;
fAddon = reply.addonid;
*/ printf("DormantNodeManager::RegisterAddon finished with id %d\n",reply.addonid);
return reply.addonid;
} }
void void
DormantNodeManager::UnregisterAddon(media_addon_id id) DormantNodeManager::UnregisterAddon(media_addon_id id)
{ {
/* ASSERT(id > 0);
if (_fAddon != 0) {
xfer_server_unregister_mediaaddon msg; xfer_server_unregister_mediaaddon msg;
printf("DormantNodeManager::UnregisterAddon id %d\n",id);
port_id port; port_id port;
port = find_port("media_server port"); port = find_port("media_server port");
if (port <= B_OK) if (port <= B_OK)
return; return;
msg.addonid = _fAddon; msg.addonid = id;
write_port(port, SERVER_UNREGISTER_MEDIAADDON, &msg, sizeof(msg)); write_port(port, SERVER_UNREGISTER_MEDIAADDON, &msg, sizeof(msg));
} }
*/
}
status_t status_t
DormantNodeManager::FindAddonPath(BPath *path, media_addon_id id) DormantNodeManager::FindAddonPath(BPath *path, media_addon_id id)
{ {
xfer_server_get_mediaaddon_ref msg;
xfer_server_get_mediaaddon_ref_reply reply;
port_id port;
entry_ref tempref;
status_t rv;
int32 code;
port = find_port("media_server port");
if (port <= B_OK)
return B_ERROR;
msg.addonid = id;
msg.reply_port = _PortPool->GetPort();
rv = write_port(port, SERVER_GET_MEDIAADDON_REF, &msg, sizeof(msg));
if (rv != B_OK) {
_PortPool->PutPort(msg.reply_port);
return B_ERROR;
}
rv = read_port(msg.reply_port, &code, &reply, sizeof(reply));
_PortPool->PutPort(msg.reply_port);
if (rv < B_OK)
return B_ERROR;
tempref = reply.ref;
return path->SetTo(&tempref);
} }
@@ -215,20 +255,20 @@ DormantNodeManager::LoadAddon(BMediaAddOn **newaddon, image_id *newimage, const
image = load_add_on(path); image = load_add_on(path);
if (image < B_OK) { if (image < B_OK) {
printf("loading failed %lx %s\n", image, strerror(image)); printf("DormantNodeManager::LoadAddon: loading failed %lx %s\n", image, strerror(image));
return B_ERROR; return B_ERROR;
} }
rv = get_image_symbol(image, "make_media_addon", B_SYMBOL_TYPE_TEXT, (void**)&make_addon); rv = get_image_symbol(image, "make_media_addon", B_SYMBOL_TYPE_TEXT, (void**)&make_addon);
if (rv < B_OK) { if (rv < B_OK) {
printf("loading failed, function not found %lx %s\n", rv, strerror(rv)); printf("DormantNodeManager::LoadAddon: loading failed, function not found %lx %s\n", rv, strerror(rv));
unload_add_on(image); unload_add_on(image);
return B_ERROR; return B_ERROR;
} }
addon = make_addon(image); addon = make_addon(image);
if (addon == 0) { if (addon == 0) {
printf("creating BMediaAddOn failed\n"); printf("DormantNodeManager::LoadAddon: creating BMediaAddOn failed\n");
unload_add_on(image); unload_add_on(image);
return B_ERROR; return B_ERROR;
} }
+19 -3
View File
@@ -1,8 +1,10 @@
#include <OS.h> #include <OS.h>
#include <Entry.h>
#include <Message.h> #include <Message.h>
#include <Messenger.h> #include <Messenger.h>
#include <MediaDefs.h> #include <MediaDefs.h>
#include <MediaAddOn.h> #include <MediaAddOn.h>
#include "debug.h"
#include "NodeManager.h" #include "NodeManager.h"
// XXX locking is missing // XXX locking is missing
@@ -11,24 +13,31 @@ NodeManager::NodeManager() :
nextaddonid(1) nextaddonid(1)
{ {
fDormantFlavorList = new List<dormant_flavor_info>; fDormantFlavorList = new List<dormant_flavor_info>;
fAddonPathMap = new Map<media_addon_id,entry_ref>;
} }
NodeManager::~NodeManager() NodeManager::~NodeManager()
{ {
delete fDormantFlavorList; delete fDormantFlavorList;
delete fAddonPathMap;
} }
void void
NodeManager::RegisterAddon(media_addon_id *newid) NodeManager::RegisterAddon(const entry_ref &ref, media_addon_id *newid)
{ {
*newid = nextaddonid++; media_addon_id id;
id = nextaddonid;
nextaddonid += 1;
fAddonPathMap->Insert(id, ref);
*newid = id;
} }
void void
NodeManager::UnregisterAddon(media_addon_id id) NodeManager::UnregisterAddon(media_addon_id id)
{ {
RemoveDormantFlavorInfo(id); RemoveDormantFlavorInfo(id);
// unload the image once it's no longer used (refcounting!) fAddonPathMap->Remove(id);
} }
void void
@@ -40,6 +49,13 @@ NodeManager::AddDormantFlavorInfo(const dormant_flavor_info &dfi)
void void
NodeManager::RemoveDormantFlavorInfo(media_addon_id id) NodeManager::RemoveDormantFlavorInfo(media_addon_id id)
{ {
UNIMPLEMENTED();
}
status_t
NodeManager::GetAddonRef(entry_ref *ref, media_addon_id id)
{
return fAddonPathMap->Get(id, ref) ? B_OK : B_ERROR;
} }
status_t status_t
+4 -1
View File
@@ -1,4 +1,5 @@
#include "TList.h" #include "TList.h"
#include "TMap.h"
class BufferManager; class BufferManager;
@@ -27,8 +28,9 @@ public:
void AddDormantFlavorInfo(const dormant_flavor_info &dfi); void AddDormantFlavorInfo(const dormant_flavor_info &dfi);
void RemoveDormantFlavorInfo(media_addon_id id); void RemoveDormantFlavorInfo(media_addon_id id);
void RegisterAddon(media_addon_id *newid); void RegisterAddon(const entry_ref &ref, media_addon_id *newid);
void UnregisterAddon(media_addon_id id); void UnregisterAddon(media_addon_id id);
status_t GetAddonRef(entry_ref *ref, media_addon_id id);
status_t GetDormantNodes(dormant_node_info * out_info, status_t GetDormantNodes(dormant_node_info * out_info,
int32 * io_count, int32 * io_count,
const media_format * has_input /* = NULL */, const media_format * has_input /* = NULL */,
@@ -45,4 +47,5 @@ private:
media_addon_id nextaddonid; media_addon_id nextaddonid;
List<dormant_flavor_info> *fDormantFlavorList; List<dormant_flavor_info> *fDormantFlavorList;
Map<media_addon_id,entry_ref> *fAddonPathMap;
}; };
+47
View File
@@ -4,6 +4,7 @@
#include <MediaDefs.h> #include <MediaDefs.h>
#include <MediaNode.h> #include <MediaNode.h>
#include <MediaAddOn.h> #include <MediaAddOn.h>
#include <Entry.h>
#define NEW_MEDIA_SERVER_SIGNATURE "application/x-vnd.OpenBeOS-media-server" #define NEW_MEDIA_SERVER_SIGNATURE "application/x-vnd.OpenBeOS-media-server"
@@ -93,6 +94,7 @@ enum {
ADDONSERVER_INSTANTIATE_DORMANT_NODE, ADDONSERVER_INSTANTIATE_DORMANT_NODE,
SERVER_REGISTER_MEDIAADDON, SERVER_REGISTER_MEDIAADDON,
SERVER_UNREGISTER_MEDIAADDON, SERVER_UNREGISTER_MEDIAADDON,
SERVER_GET_MEDIAADDON_REF,
ADDONSERVER_RESCAN_MEDIAADDON_FLAVORS, ADDONSERVER_RESCAN_MEDIAADDON_FLAVORS,
SERVER_REGISTER_DORMANT_NODE, SERVER_REGISTER_DORMANT_NODE,
SERVER_GET_NODE, SERVER_GET_NODE,
@@ -115,6 +117,38 @@ enum node_type
SYSTEM_TIME_SOURCE SYSTEM_TIME_SOURCE
}; };
/* We can't send an entry_ref through a port to another team,
* but we can assign it to an xfer_entry_ref and send this one,
* when we receive it we can assign it to a normal entry_ref
*/
struct xfer_entry_ref
{
public:
xfer_entry_ref()
{
device = -1;
directory = -1;
name[0] = 0;
}
operator entry_ref() const
{
entry_ref ref(device, directory, name);
return ref;
}
void operator=(const entry_ref &ref)
{
device = ref.device;
directory = ref.directory;
strcpy(name, ref.name);
}
private:
dev_t device;
ino_t directory;
char name[B_FILE_NAME_LENGTH];
};
struct xfer_server_get_dormant_flavor_info struct xfer_server_get_dormant_flavor_info
{ {
media_addon_id addon; media_addon_id addon;
@@ -199,6 +233,7 @@ struct xfer_addonserver_rescan_mediaaddon_flavors
struct xfer_server_register_mediaaddon struct xfer_server_register_mediaaddon
{ {
port_id reply_port; port_id reply_port;
xfer_entry_ref ref; // a ref to the file
}; };
struct xfer_server_register_mediaaddon_reply struct xfer_server_register_mediaaddon_reply
@@ -211,6 +246,18 @@ struct xfer_server_unregister_mediaaddon
media_addon_id addonid; media_addon_id addonid;
}; };
struct xfer_server_get_mediaaddon_ref
{
media_addon_id addonid;
port_id reply_port;
};
struct xfer_server_get_mediaaddon_ref_reply
{
status_t result;
xfer_entry_ref ref; // a ref to the file
};
struct xfer_producer_format_suggestion_requested struct xfer_producer_format_suggestion_requested
{ {
media_type type; media_type type;
+12 -1
View File
@@ -152,6 +152,17 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
{ {
status_t rv; status_t rv;
switch (code) { switch (code) {
case SERVER_GET_MEDIAADDON_REF:
{
xfer_server_get_mediaaddon_ref *msg = (xfer_server_get_mediaaddon_ref *)data;
xfer_server_get_mediaaddon_ref_reply reply;
entry_ref tempref;
reply.result = fNodeManager->GetAddonRef(&tempref, msg->addonid);
reply.ref = tempref;
write_port(msg->reply_port, 0, &reply, sizeof(reply));
break;
}
case SERVER_GET_NODE: case SERVER_GET_NODE:
{ {
xfer_server_get_node *msg = (xfer_server_get_node *)data; xfer_server_get_node *msg = (xfer_server_get_node *)data;
@@ -174,7 +185,7 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
{ {
xfer_server_register_mediaaddon *msg = (xfer_server_register_mediaaddon *)data; xfer_server_register_mediaaddon *msg = (xfer_server_register_mediaaddon *)data;
xfer_server_register_mediaaddon_reply reply; xfer_server_register_mediaaddon_reply reply;
fNodeManager->RegisterAddon(&reply.addonid); fNodeManager->RegisterAddon(msg->ref, &reply.addonid);
write_port(msg->reply_port, 0, &reply, sizeof(reply)); write_port(msg->reply_port, 0, &reply, sizeof(reply));
break; break;
} }
+24 -23
View File
@@ -19,11 +19,11 @@
void DumpFlavorInfo(const flavor_info *info); void DumpFlavorInfo(const flavor_info *info);
class Application : BApplication class MediaAddonServer : BApplication
{ {
public: public:
Application(const char *sig); MediaAddonServer(const char *sig);
~Application(); ~MediaAddonServer();
void ReadyToRun(); void ReadyToRun();
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
@@ -44,7 +44,7 @@ public:
thread_id control_thread; thread_id control_thread;
}; };
Application::Application(const char *sig) : MediaAddonServer::MediaAddonServer(const char *sig) :
BApplication(sig) BApplication(sig)
{ {
mediaroster = BMediaRoster::Roster(); mediaroster = BMediaRoster::Roster();
@@ -54,7 +54,7 @@ Application::Application(const char *sig) :
resume_thread(control_thread); resume_thread(control_thread);
} }
Application::~Application() MediaAddonServer::~MediaAddonServer()
{ {
delete_port(control_port); delete_port(control_port);
status_t err; status_t err;
@@ -69,7 +69,7 @@ Application::~Application()
} }
void void
Application::HandleMessage(int32 code, void *data, size_t size) MediaAddonServer::HandleMessage(int32 code, void *data, size_t size)
{ {
switch (code) { switch (code) {
case ADDONSERVER_INSTANTIATE_DORMANT_NODE: case ADDONSERVER_INSTANTIATE_DORMANT_NODE:
@@ -87,7 +87,7 @@ Application::HandleMessage(int32 code, void *data, size_t size)
BMediaAddOn *addon; BMediaAddOn *addon;
addon = _DormantNodeManager->GetAddon(msg->addonid); addon = _DormantNodeManager->GetAddon(msg->addonid);
if (!addon) { if (!addon) {
printf("Can't find a addon object for id %d\n",(int)msg->addonid); printf("rescan flavors: Can't find a addon object for id %d\n",(int)msg->addonid);
break; break;
} }
ScanAddOnFlavors(addon); ScanAddOnFlavors(addon);
@@ -101,14 +101,14 @@ Application::HandleMessage(int32 code, void *data, size_t size)
} }
int32 int32
Application::controlthread(void *arg) MediaAddonServer::controlthread(void *arg)
{ {
char data[B_MEDIA_MESSAGE_SIZE]; char data[B_MEDIA_MESSAGE_SIZE];
Application *app; MediaAddonServer *app;
ssize_t size; ssize_t size;
int32 code; int32 code;
app = (Application *)arg; app = (MediaAddonServer *)arg;
while ((size = read_port_etc(app->control_port, &code, data, sizeof(data), 0, 0)) > 0) while ((size = read_port_etc(app->control_port, &code, data, sizeof(data), 0, 0)) > 0)
app->HandleMessage(code, data, size); app->HandleMessage(code, data, size);
@@ -116,7 +116,7 @@ Application::controlthread(void *arg)
} }
void void
Application::ReadyToRun() MediaAddonServer::ReadyToRun()
{ {
node_ref nref; node_ref nref;
@@ -132,7 +132,7 @@ Application::ReadyToRun()
} }
void void
Application::ScanAddOnFlavors(BMediaAddOn *addon) MediaAddonServer::ScanAddOnFlavors(BMediaAddOn *addon)
{ {
int flavorcount; int flavorcount;
media_addon_id purge_id; media_addon_id purge_id;
@@ -142,7 +142,7 @@ Application::ScanAddOnFlavors(BMediaAddOn *addon)
ASSERT(addon); ASSERT(addon);
ASSERT(addon->AddonID() > 0); ASSERT(addon->AddonID() > 0);
printf("scanning media add-on flavors for id %d\n",addon->AddonID()); printf("MediaAddonServer::ScanAddOnFlavors: id %d\n",addon->AddonID());
port = find_port("media_server port"); port = find_port("media_server port");
if (port <= B_OK) { if (port <= B_OK) {
@@ -188,7 +188,7 @@ Application::ScanAddOnFlavors(BMediaAddOn *addon)
rv = write_port(port, SERVER_REGISTER_DORMANT_NODE, msg, msgsize); rv = write_port(port, SERVER_REGISTER_DORMANT_NODE, msg, msgsize);
if (rv != B_OK) { if (rv != B_OK) {
printf("couldn't register dormant node\n"); printf("MediaAddonServer::ScanAddOnFlavors: couldn't register dormant node\n");
} }
free(msg); free(msg);
@@ -200,9 +200,9 @@ Application::ScanAddOnFlavors(BMediaAddOn *addon)
} }
void void
Application::AddOnAdded(const char *path, ino_t file_node) MediaAddonServer::AddOnAdded(const char *path, ino_t file_node)
{ {
printf("\n\nloading BMediaAddOn from %s\n",path); printf("\n\nMediaAddonServer::AddOnAdded: path %s\n",path);
BMediaAddOn *addon; BMediaAddOn *addon;
media_addon_id id; media_addon_id id;
@@ -210,17 +210,18 @@ Application::AddOnAdded(const char *path, ino_t file_node)
id = _DormantNodeManager->RegisterAddon(path); id = _DormantNodeManager->RegisterAddon(path);
if (id <= 0) { if (id <= 0) {
printf("failed to register add-on\n"); printf("MediaAddonServer::AddOnAdded: failed to register add-on\n");
return; return;
} }
addon = _DormantNodeManager->GetAddon(id); addon = _DormantNodeManager->GetAddon(id);
if (addon == NULL) { if (addon == NULL) {
printf("failed to get add-on\n"); printf("failed to get add-on\n");
_DormantNodeManager->UnregisterAddon(id);
return; return;
} }
printf("adding media add-on %d\n",(int)id); printf("MediaAddonServer::AddOnAdded: loading finished, id %d\n",(int)id);
filemap->Insert(file_node, id); filemap->Insert(file_node, id);
@@ -278,11 +279,11 @@ flavor 0:
void void
Application::AddOnRemoved(ino_t file_node) MediaAddonServer::AddOnRemoved(ino_t file_node)
{ {
media_addon_id id; media_addon_id id;
if (!filemap->Get(file_node,&id)) { if (!filemap->Get(file_node,&id)) {
printf("inode %Ld removed, but no media add-on found\n",file_node); printf("MediaAddonServer::AddOnRemoved: inode %Ld removed, but no media add-on found\n",file_node);
return; return;
} }
filemap->Remove(file_node); filemap->Remove(file_node);
@@ -290,7 +291,7 @@ Application::AddOnRemoved(ino_t file_node)
} }
void void
Application::WatchDir(BEntry *dir) MediaAddonServer::WatchDir(BEntry *dir)
{ {
BEntry e; BEntry e;
BDirectory d(dir); BDirectory d(dir);
@@ -314,7 +315,7 @@ Application::WatchDir(BEntry *dir)
} }
void void
Application::MessageReceived(BMessage *msg) MediaAddonServer::MessageReceived(BMessage *msg)
{ {
switch (msg->what) switch (msg->what)
{ {
@@ -385,7 +386,7 @@ Application::MessageReceived(BMessage *msg)
int main() int main()
{ {
new Application("application/x-vnd.OpenBeOS-media-addon-server"); new MediaAddonServer("application/x-vnd.OpenBeOS-media-addon-server");
be_app->Run(); be_app->Run();
return 0; return 0;
} }