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

View File

@ -24,9 +24,12 @@
#include <string.h>
#include <Locker.h>
#include <Path.h>
#include <Entry.h>
#include <MediaAddOn.h>
#include <Debug.h>
#include "debug.h"
#include "PortPool.h"
#include "ServerInterface.h"
#include "DormantNodeManager.h"
static BPrivate::media::DormantNodeManager manager;
@ -81,6 +84,8 @@ DormantNodeManager::GetAddon(media_addon_id id)
{
BMediaAddOn *addon;
printf("DormantNodeManager::GetAddon, id %d\n",id);
// first try to use a already loaded add-on
addon = TryGetAddon(id);
if (addon)
@ -91,7 +96,7 @@ DormantNodeManager::GetAddon(media_addon_id id)
// ok, it's not loaded, try to get the path
BPath path;
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;
}
@ -99,7 +104,7 @@ DormantNodeManager::GetAddon(media_addon_id id)
BMediaAddOn *newaddon;
image_id image;
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;
}
@ -133,10 +138,13 @@ DormantNodeManager::PutAddon(media_addon_id id)
BMediaAddOn *addon;
image_id image;
bool unload;
printf("DormantNodeManager::PutAddon, id %d\n",id);
fLock->Lock();
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();
return;
}
@ -158,50 +166,82 @@ DormantNodeManager::PutAddon(media_addon_id id)
media_addon_id
DormantNodeManager::RegisterAddon(const char *path)
{
/*
xfer_server_register_mediaaddon msg;
xfer_server_register_mediaaddon_reply reply;
port_id port;
status_t rv;
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");
if (port <= B_OK)
return;
return 0;
msg.reply_port = _PortPool->GetPort();
rv = write_port(port, SERVER_REGISTER_MEDIAADDON, &msg, sizeof(msg));
if (rv != B_OK) {
_PortPool->PutPort(msg.reply_port);
return;
return 0;
}
rv = read_port(msg.reply_port, &code, &reply, sizeof(reply));
_PortPool->PutPort(msg.reply_port);
if (rv < B_OK)
return;
fAddon = reply.addonid;
*/
return 0;
printf("DormantNodeManager::RegisterAddon finished with id %d\n",reply.addonid);
return reply.addonid;
}
void
DormantNodeManager::UnregisterAddon(media_addon_id id)
{
/*
if (_fAddon != 0) {
xfer_server_unregister_mediaaddon msg;
port_id port;
port = find_port("media_server port");
if (port <= B_OK)
return;
msg.addonid = _fAddon;
write_port(port, SERVER_UNREGISTER_MEDIAADDON, &msg, sizeof(msg));
}
*/
ASSERT(id > 0);
xfer_server_unregister_mediaaddon msg;
printf("DormantNodeManager::UnregisterAddon id %d\n",id);
port_id port;
port = find_port("media_server port");
if (port <= B_OK)
return;
msg.addonid = id;
write_port(port, SERVER_UNREGISTER_MEDIAADDON, &msg, sizeof(msg));
}
status_t
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);
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;
}
rv = get_image_symbol(image, "make_media_addon", B_SYMBOL_TYPE_TEXT, (void**)&make_addon);
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);
return B_ERROR;
}
addon = make_addon(image);
if (addon == 0) {
printf("creating BMediaAddOn failed\n");
printf("DormantNodeManager::LoadAddon: creating BMediaAddOn failed\n");
unload_add_on(image);
return B_ERROR;
}

View File

@ -1,8 +1,10 @@
#include <OS.h>
#include <Entry.h>
#include <Message.h>
#include <Messenger.h>
#include <MediaDefs.h>
#include <MediaAddOn.h>
#include "debug.h"
#include "NodeManager.h"
// XXX locking is missing
@ -11,24 +13,31 @@ NodeManager::NodeManager() :
nextaddonid(1)
{
fDormantFlavorList = new List<dormant_flavor_info>;
fAddonPathMap = new Map<media_addon_id,entry_ref>;
}
NodeManager::~NodeManager()
{
delete fDormantFlavorList;
delete fAddonPathMap;
}
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
NodeManager::UnregisterAddon(media_addon_id id)
{
RemoveDormantFlavorInfo(id);
// unload the image once it's no longer used (refcounting!)
fAddonPathMap->Remove(id);
}
void
@ -40,6 +49,13 @@ NodeManager::AddDormantFlavorInfo(const dormant_flavor_info &dfi)
void
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

View File

@ -1,4 +1,5 @@
#include "TList.h"
#include "TMap.h"
class BufferManager;
@ -27,8 +28,9 @@ public:
void AddDormantFlavorInfo(const dormant_flavor_info &dfi);
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);
status_t GetAddonRef(entry_ref *ref, media_addon_id id);
status_t GetDormantNodes(dormant_node_info * out_info,
int32 * io_count,
const media_format * has_input /* = NULL */,
@ -45,4 +47,5 @@ private:
media_addon_id nextaddonid;
List<dormant_flavor_info> *fDormantFlavorList;
Map<media_addon_id,entry_ref> *fAddonPathMap;
};

View File

@ -4,6 +4,7 @@
#include <MediaDefs.h>
#include <MediaNode.h>
#include <MediaAddOn.h>
#include <Entry.h>
#define NEW_MEDIA_SERVER_SIGNATURE "application/x-vnd.OpenBeOS-media-server"
@ -93,6 +94,7 @@ enum {
ADDONSERVER_INSTANTIATE_DORMANT_NODE,
SERVER_REGISTER_MEDIAADDON,
SERVER_UNREGISTER_MEDIAADDON,
SERVER_GET_MEDIAADDON_REF,
ADDONSERVER_RESCAN_MEDIAADDON_FLAVORS,
SERVER_REGISTER_DORMANT_NODE,
SERVER_GET_NODE,
@ -115,6 +117,38 @@ enum node_type
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
{
media_addon_id addon;
@ -198,7 +232,8 @@ struct xfer_addonserver_rescan_mediaaddon_flavors
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
@ -211,6 +246,18 @@ struct xfer_server_unregister_mediaaddon
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
{
media_type type;

View File

@ -152,6 +152,17 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
{
status_t rv;
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:
{
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_reply reply;
fNodeManager->RegisterAddon(&reply.addonid);
fNodeManager->RegisterAddon(msg->ref, &reply.addonid);
write_port(msg->reply_port, 0, &reply, sizeof(reply));
break;
}

View File

@ -19,11 +19,11 @@
void DumpFlavorInfo(const flavor_info *info);
class Application : BApplication
class MediaAddonServer : BApplication
{
public:
Application(const char *sig);
~Application();
MediaAddonServer(const char *sig);
~MediaAddonServer();
void ReadyToRun();
void MessageReceived(BMessage *msg);
@ -44,7 +44,7 @@ public:
thread_id control_thread;
};
Application::Application(const char *sig) :
MediaAddonServer::MediaAddonServer(const char *sig) :
BApplication(sig)
{
mediaroster = BMediaRoster::Roster();
@ -54,7 +54,7 @@ Application::Application(const char *sig) :
resume_thread(control_thread);
}
Application::~Application()
MediaAddonServer::~MediaAddonServer()
{
delete_port(control_port);
status_t err;
@ -69,7 +69,7 @@ Application::~Application()
}
void
Application::HandleMessage(int32 code, void *data, size_t size)
MediaAddonServer::HandleMessage(int32 code, void *data, size_t size)
{
switch (code) {
case ADDONSERVER_INSTANTIATE_DORMANT_NODE:
@ -87,7 +87,7 @@ Application::HandleMessage(int32 code, void *data, size_t size)
BMediaAddOn *addon;
addon = _DormantNodeManager->GetAddon(msg->addonid);
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;
}
ScanAddOnFlavors(addon);
@ -101,14 +101,14 @@ Application::HandleMessage(int32 code, void *data, size_t size)
}
int32
Application::controlthread(void *arg)
MediaAddonServer::controlthread(void *arg)
{
char data[B_MEDIA_MESSAGE_SIZE];
Application *app;
MediaAddonServer *app;
ssize_t size;
int32 code;
app = (Application *)arg;
app = (MediaAddonServer *)arg;
while ((size = read_port_etc(app->control_port, &code, data, sizeof(data), 0, 0)) > 0)
app->HandleMessage(code, data, size);
@ -116,7 +116,7 @@ Application::controlthread(void *arg)
}
void
Application::ReadyToRun()
MediaAddonServer::ReadyToRun()
{
node_ref nref;
@ -132,7 +132,7 @@ Application::ReadyToRun()
}
void
Application::ScanAddOnFlavors(BMediaAddOn *addon)
MediaAddonServer::ScanAddOnFlavors(BMediaAddOn *addon)
{
int flavorcount;
media_addon_id purge_id;
@ -142,7 +142,7 @@ Application::ScanAddOnFlavors(BMediaAddOn *addon)
ASSERT(addon);
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");
if (port <= B_OK) {
@ -188,7 +188,7 @@ Application::ScanAddOnFlavors(BMediaAddOn *addon)
rv = write_port(port, SERVER_REGISTER_DORMANT_NODE, msg, msgsize);
if (rv != B_OK) {
printf("couldn't register dormant node\n");
printf("MediaAddonServer::ScanAddOnFlavors: couldn't register dormant node\n");
}
free(msg);
@ -200,9 +200,9 @@ Application::ScanAddOnFlavors(BMediaAddOn *addon)
}
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;
media_addon_id id;
@ -210,17 +210,18 @@ Application::AddOnAdded(const char *path, ino_t file_node)
id = _DormantNodeManager->RegisterAddon(path);
if (id <= 0) {
printf("failed to register add-on\n");
printf("MediaAddonServer::AddOnAdded: failed to register add-on\n");
return;
}
addon = _DormantNodeManager->GetAddon(id);
if (addon == NULL) {
printf("failed to get add-on\n");
_DormantNodeManager->UnregisterAddon(id);
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);
@ -278,11 +279,11 @@ flavor 0:
void
Application::AddOnRemoved(ino_t file_node)
MediaAddonServer::AddOnRemoved(ino_t file_node)
{
media_addon_id 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;
}
filemap->Remove(file_node);
@ -290,7 +291,7 @@ Application::AddOnRemoved(ino_t file_node)
}
void
Application::WatchDir(BEntry *dir)
MediaAddonServer::WatchDir(BEntry *dir)
{
BEntry e;
BDirectory d(dir);
@ -314,7 +315,7 @@ Application::WatchDir(BEntry *dir)
}
void
Application::MessageReceived(BMessage *msg)
MediaAddonServer::MessageReceived(BMessage *msg)
{
switch (msg->what)
{
@ -385,7 +386,7 @@ Application::MessageReceived(BMessage *msg)
int main()
{
new Application("application/x-vnd.OpenBeOS-media-addon-server");
new MediaAddonServer("application/x-vnd.OpenBeOS-media-addon-server");
be_app->Run();
return 0;
}