Skip to content

Commit

Permalink
- Added skeleton for new cddb_server.
Browse files Browse the repository at this point in the history
- Includes all relevant handling of CDDA exported attributes so you guys can
  see where I am going with this.
 
CDDB handling (including server connection, request and response parsing)
will come up next. In the future we will also have a configuration panel
and a Deskbar replicant for controlling it.

Do we really have to edit the Jamfile in the parent dir to get something
building with our build system?



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27096 a95241bf-73f2-0310-859d-f6bbb57e9c96
  • Loading branch information
Bruno G. Albuquerque committed Aug 21, 2008
1 parent 009aa36 commit 8242707
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/servers/Jamfile
Expand Up @@ -2,6 +2,7 @@ SubDir HAIKU_TOP src servers ;

SubInclude HAIKU_TOP src servers app ;
SubInclude HAIKU_TOP src servers bluetooth ;
SubInclude HAIKU_TOP src servers cddb_daemon ;
SubInclude HAIKU_TOP src servers debug ;
SubInclude HAIKU_TOP src servers input ;
SubInclude HAIKU_TOP src servers mail ;
Expand Down
6 changes: 6 additions & 0 deletions src/servers/cddb_daemon/Jamfile
@@ -0,0 +1,6 @@
SubDir HAIKU_TOP src servers cddb_daemon ;

Server cddb_daemon :
cddb_daemon.cpp
: be
;
103 changes: 103 additions & 0 deletions src/servers/cddb_daemon/cddb_daemon.cpp
@@ -0,0 +1,103 @@
/*
* Copyright 2008, Bruno Albuquerque, bga@bug-br.org.br. All rights reserved.
* Distributed under the terms of the MIT License.
*/

#include "cddb_daemon.h"

#include <stdio.h>
#include <string.h>

#include <Directory.h>
#include <NodeMonitor.h>
#include <Volume.h>

#include <fs_info.h>


static const char* kCddaFsName = "cdda";


CDDBDaemon::CDDBDaemon()
: BApplication("application/x-vnd.Haiku-CDDBDaemon")
, _volumeRoster(new BVolumeRoster)
{
_volumeRoster->StartWatching();

BVolume volume;
while (_volumeRoster->GetNextVolume(&volume) == B_OK) {
uint32 cddbId;
if (CanLookup(volume.Device(), &cddbId)) {
printf("CD can be looked up. CDDB id = %lu.\n", cddbId);
// TODO(bga): Implement and enable CDDB database lookup.
}
}
}


CDDBDaemon::~CDDBDaemon()
{
_volumeRoster->StopWatching();
delete _volumeRoster;
}


void
CDDBDaemon::MessageReceived(BMessage* message)
{
switch(message->what) {
case B_NODE_MONITOR:
int32 opcode;
if (message->FindInt32("opcode", &opcode) == B_OK) {
if (opcode == B_DEVICE_MOUNTED) {
dev_t device;
if (message->FindInt32("new device", &device) == B_OK) {
uint32 cddbId;
if (CanLookup(device, &cddbId)) {
printf("CD can be looked up. CDDB id = %lu.\n",
cddbId);
// TODO(bga): Implement and enable CDDB database lookup.
}
}
}
}
break;
default:
BApplication::MessageReceived(message);
}
}


bool
CDDBDaemon::CanLookup(const dev_t device, uint32* cddbId) const
{
// Is it an Audio disk?
fs_info info;
fs_stat_dev(device, &info);
if (strncmp(info.fsh_name, kCddaFsName, strlen(kCddaFsName)) != 0)
return false;

// Does it have the CD:do_lookup attribute and is it true?
BVolume volume(device);
BDirectory directory;
volume.GetRootDirectory(&directory);

bool doLookup;
if (directory.ReadAttr("CD:do_lookup", B_BOOL_TYPE, 0, (void *)&doLookup,
sizeof(bool)) < B_OK || !doLookup)
return false;

// Does it have the CD:cddbid attribute?
if (directory.ReadAttr("CD:cddbid", B_UINT32_TYPE, 0, (void *)cddbId,
sizeof(uint32)) < B_OK)
return false;

return true;
}


int main(void) {
CDDBDaemon* cddbDaemon = new CDDBDaemon();
cddbDaemon->Run();
delete cddbDaemon;
}
26 changes: 26 additions & 0 deletions src/servers/cddb_daemon/cddb_daemon.h
@@ -0,0 +1,26 @@
/*
* Copyright 2008, Bruno Albuquerque, bga@bug-br.org.br. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef CDDB_DAEMON_H
#define CDDB_DAEMON_H

#include <Application.h>
#include <Message.h>
#include <VolumeRoster.h>

class CDDBDaemon : public BApplication
{
public:
CDDBDaemon();
virtual ~CDDBDaemon();

virtual void MessageReceived(BMessage* message);

private:
bool CanLookup(const dev_t device, uint32* cddbId) const;

BVolumeRoster* _volumeRoster;
};

#endif

0 comments on commit 8242707

Please sign in to comment.