cddb_daemon: renamed to cddb_lookup, moved to /src/bin.
* It's now a standard command line tool that is launched automatically via the launch_daemon whenver a volume is mounted.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
include [ FDirName $(HAIKU_BUILD_RULES_DIR) images definitions minimum ] ;
|
||||
|
||||
SYSTEM_BIN += [ FFilterByBuildFeatures
|
||||
cddb_lookup
|
||||
clipboard CortexAddOnHost
|
||||
FirstBootPrompt fwcontrol@x86
|
||||
installsound
|
||||
@@ -91,7 +92,6 @@ rule HaikuImageGetPrivateSystemLibs
|
||||
|
||||
|
||||
SYSTEM_SERVERS += [ FFilterByBuildFeatures
|
||||
cddb_daemon
|
||||
mail_daemon media_addon_server media_server midi_server
|
||||
nfs4_idmapper_server
|
||||
print_server print_addon_server
|
||||
|
||||
+6
-6
@@ -55,12 +55,6 @@ service x-vnd.Haiku-net_server {
|
||||
legacy
|
||||
}
|
||||
|
||||
service x-vnd.Haiku-cddb_daemon {
|
||||
launch /system/servers/cddb_daemon
|
||||
no_safemode
|
||||
legacy
|
||||
}
|
||||
|
||||
service x-vnd.Haiku-print_server {
|
||||
launch /system/servers/print_server
|
||||
no_safemode
|
||||
@@ -79,6 +73,12 @@ service x-vnd.Haiku-power_daemon {
|
||||
legacy
|
||||
}
|
||||
|
||||
job x-vnd.Haiku-cddb_lookup {
|
||||
launch /system/bin/cddb_lookup
|
||||
no_safemode
|
||||
on volume_mounted
|
||||
}
|
||||
|
||||
job post-install {
|
||||
launch /bin/sh /system/boot/PostInstallScript
|
||||
if file_exists /boot/system/settings/fresh_install
|
||||
|
||||
@@ -265,6 +265,7 @@ DoCatalogs filepanel
|
||||
SubInclude HAIKU_TOP src bin addattr ;
|
||||
SubInclude HAIKU_TOP src bin bc ;
|
||||
SubInclude HAIKU_TOP src bin bfs_tools ;
|
||||
SubInclude HAIKU_TOP src bin cddb_lookup ;
|
||||
SubInclude HAIKU_TOP src bin compress ;
|
||||
SubInclude HAIKU_TOP src bin consoled ;
|
||||
SubInclude HAIKU_TOP src bin coreutils ;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
SubDir HAIKU_TOP src bin cddb_lookup ;
|
||||
|
||||
UsePrivateHeaders drivers ;
|
||||
|
||||
AddResources cddb_lookup : cddb_lookup.rdef ;
|
||||
|
||||
BinCommand cddb_lookup :
|
||||
cddb_lookup.cpp
|
||||
cddb_server.cpp
|
||||
: be bnetapi [ TargetLibsupc++ ]
|
||||
;
|
||||
@@ -1,80 +1,80 @@
|
||||
/*
|
||||
* Copyright 2008-2009, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2008-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Bruno Albuquerque, bga@bug-br.org.br
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
* Bruno Albuquerque, bga@bug-br.org.br
|
||||
*/
|
||||
|
||||
#include "cddb_daemon.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Application.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <fs_info.h>
|
||||
#include <Message.h>
|
||||
#include <NodeMonitor.h>
|
||||
#include <Volume.h>
|
||||
#include <VolumeRoster.h>
|
||||
|
||||
#include <scsi_cmds.h>
|
||||
|
||||
#include "cddb_server.h"
|
||||
|
||||
|
||||
class CDDBLookup : public BApplication {
|
||||
public:
|
||||
CDDBLookup();
|
||||
virtual ~CDDBLookup();
|
||||
|
||||
void LookupAll();
|
||||
status_t Lookup(const dev_t device);
|
||||
|
||||
private:
|
||||
bool _CanLookup(const dev_t device, uint32* cddbId,
|
||||
scsi_toc_toc* toc) const;
|
||||
QueryResponseData* _SelectResult(BList* response) const;
|
||||
status_t _WriteCDData(dev_t device,
|
||||
QueryResponseData* diskData,
|
||||
ReadResponseData* readResponse);
|
||||
};
|
||||
|
||||
|
||||
extern const char *__progname;
|
||||
static const char *kProgramName = __progname;
|
||||
|
||||
static const char* kCddaFsName = "cdda";
|
||||
static const int kMaxTocSize = 1024;
|
||||
|
||||
|
||||
CDDBDaemon::CDDBDaemon()
|
||||
: BApplication("application/x-vnd.Haiku-cddb_daemon"),
|
||||
fVolumeRoster(new BVolumeRoster)
|
||||
CDDBLookup::CDDBLookup()
|
||||
:
|
||||
BApplication("application/x-vnd.Haiku-cddb_lookup")
|
||||
{
|
||||
fVolumeRoster->StartWatching();
|
||||
|
||||
BVolume volume;
|
||||
printf("Checking currently mounted volumes ...\n");
|
||||
while (fVolumeRoster->GetNextVolume(&volume) == B_OK) {
|
||||
if (_Lookup(volume.Device()) != B_OK) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
printf("Checking complete. Listening for device mounts.\n");
|
||||
}
|
||||
|
||||
|
||||
CDDBDaemon::~CDDBDaemon()
|
||||
CDDBLookup::~CDDBLookup()
|
||||
{
|
||||
fVolumeRoster->StopWatching();
|
||||
delete fVolumeRoster;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CDDBDaemon::MessageReceived(BMessage* message)
|
||||
CDDBLookup::LookupAll()
|
||||
{
|
||||
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) {
|
||||
if (_Lookup(device) != B_OK)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
BVolumeRoster roster;
|
||||
BVolume volume;
|
||||
while (roster.GetNextVolume(&volume) == B_OK) {
|
||||
Lookup(volume.Device());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
CDDBDaemon::_Lookup(const dev_t device)
|
||||
CDDBLookup::Lookup(const dev_t device)
|
||||
{
|
||||
scsi_toc_toc* toc = (scsi_toc_toc*)malloc(kMaxTocSize);
|
||||
if (toc == NULL)
|
||||
@@ -140,7 +140,7 @@ CDDBDaemon::_Lookup(const dev_t device)
|
||||
|
||||
|
||||
bool
|
||||
CDDBDaemon::_CanLookup(const dev_t device, uint32* cddbId,
|
||||
CDDBLookup::_CanLookup(const dev_t device, uint32* cddbId,
|
||||
scsi_toc_toc* toc) const
|
||||
{
|
||||
if (cddbId == NULL || toc == NULL)
|
||||
@@ -177,7 +177,7 @@ CDDBDaemon::_CanLookup(const dev_t device, uint32* cddbId,
|
||||
|
||||
|
||||
QueryResponseData*
|
||||
CDDBDaemon::_SelectResult(BList* response) const
|
||||
CDDBLookup::_SelectResult(BList* response) const
|
||||
{
|
||||
// Select a single CD match from the response and return it.
|
||||
//
|
||||
@@ -206,19 +206,19 @@ CDDBDaemon::_SelectResult(BList* response) const
|
||||
|
||||
|
||||
status_t
|
||||
CDDBDaemon::_WriteCDData(dev_t device, QueryResponseData* diskData,
|
||||
CDDBLookup::_WriteCDData(dev_t device, QueryResponseData* diskData,
|
||||
ReadResponseData* readResponse)
|
||||
{
|
||||
// Rename volume.
|
||||
BVolume volume(device);
|
||||
|
||||
status_t result;
|
||||
status_t error = B_OK;
|
||||
|
||||
BString name = diskData->artist << " - " << diskData->title;
|
||||
name.ReplaceSet("/", " ");
|
||||
|
||||
if ((result = volume.SetName(name.String())) != B_OK) {
|
||||
status_t result = volume.SetName(name.String());
|
||||
if (result != B_OK) {
|
||||
printf("Can't set volume name.\n");
|
||||
return result;
|
||||
}
|
||||
@@ -237,9 +237,10 @@ CDDBDaemon::_WriteCDData(dev_t device, QueryResponseData* diskData,
|
||||
name.SetToFormat("%02d %s.wav", trackNum, data->title.String());
|
||||
name.ReplaceSet("/", " ");
|
||||
|
||||
if ((result = entry.Rename(name.String())) != B_OK) {
|
||||
printf("Failed renaming entry at index %d to \"%s\".\n", index,
|
||||
name.String());
|
||||
result = entry.Rename(name.String());
|
||||
if (result != B_OK) {
|
||||
fprintf(stderr, "%s: Failed renaming entry at index %d to "
|
||||
"\"%s\".\n", kProgramName, index, name.String());
|
||||
error = result;
|
||||
// User can benefit from continuing through all tracks.
|
||||
// Report error later.
|
||||
@@ -247,28 +248,28 @@ CDDBDaemon::_WriteCDData(dev_t device, QueryResponseData* diskData,
|
||||
|
||||
// Add relevant attributes. We consider an error here as non-fatal.
|
||||
BNode node(&entry);
|
||||
node.WriteAttr("Media:Title", B_STRING_TYPE, 0, (data->title).String(),
|
||||
(data->title).Length());
|
||||
node.WriteAttr("Media:Title", B_STRING_TYPE, 0, data->title.String(),
|
||||
data->title.Length());
|
||||
node.WriteAttr("Audio:Album", B_STRING_TYPE, 0,
|
||||
(readResponse->title).String(),
|
||||
(readResponse->title).Length());
|
||||
readResponse->title.String(),
|
||||
readResponse->title.Length());
|
||||
if (readResponse->genre.Length() != 0) {
|
||||
node.WriteAttr("Media:Genre", B_STRING_TYPE, 0,
|
||||
(readResponse->genre).String(),
|
||||
(readResponse->genre).Length());
|
||||
readResponse->genre.String(),
|
||||
readResponse->genre.Length());
|
||||
}
|
||||
if (readResponse->year != 0) {
|
||||
node.WriteAttr("Media:Year", B_INT32_TYPE, 0,
|
||||
&(readResponse->year), sizeof(int32));
|
||||
&readResponse->year, sizeof(int32));
|
||||
}
|
||||
|
||||
if (data->artist == "") {
|
||||
node.WriteAttr("Audio:Artist", B_STRING_TYPE, 0,
|
||||
(readResponse->artist).String(),
|
||||
(readResponse->artist).Length());
|
||||
readResponse->artist.String(),
|
||||
readResponse->artist.Length());
|
||||
} else {
|
||||
node.WriteAttr("Audio:Artist", B_STRING_TYPE, 0,
|
||||
(data->artist).String(), (data->artist).Length());
|
||||
data->artist.String(), data->artist.Length());
|
||||
}
|
||||
|
||||
index++;
|
||||
@@ -278,9 +279,15 @@ CDDBDaemon::_WriteCDData(dev_t device, QueryResponseData* diskData,
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
printf("CDDB Daemon for Haiku v1.0.0 started.\n");
|
||||
CDDBDaemon* cddbDaemon = new CDDBDaemon();
|
||||
cddbDaemon->Run();
|
||||
delete cddbDaemon;
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
// TODO: support arguments to specify a device
|
||||
CDDBLookup cddb;
|
||||
cddb.LookupAll();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
resource app_signature "application/x-vnd.Haiku-cddb_daemon";
|
||||
resource app_signature "application/x-vnd.Haiku-cddb_lookup";
|
||||
|
||||
resource app_flags B_EXCLUSIVE_LAUNCH | B_BACKGROUND_APP;
|
||||
|
||||
@@ -10,8 +10,8 @@ resource app_version {
|
||||
variety = B_APPV_FINAL,
|
||||
internal = 3,
|
||||
|
||||
short_info = "Haiku CDDB Daemon",
|
||||
long_info = "Haiku CDDB Daemon ©2009 Haiku"
|
||||
short_info = "Haiku CDDB Lookup",
|
||||
long_info = "Haiku CDDB Lookup ©2009-2015 Haiku"
|
||||
};
|
||||
|
||||
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
||||
@@ -1,11 +1,12 @@
|
||||
/*
|
||||
* Copyright 2008-2009, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2008-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Bruno Albuquerque, bga@bug-br.org.br
|
||||
*/
|
||||
|
||||
|
||||
#include "cddb_server.h"
|
||||
|
||||
#include <errno.h>
|
||||
@@ -21,7 +22,8 @@ static const uint32 kFramesPerSecond = 75;
|
||||
static const uint32 kFramesPerMinute = kFramesPerSecond * 60;
|
||||
|
||||
|
||||
CDDBServer::CDDBServer(const BString& cddbServer):
|
||||
CDDBServer::CDDBServer(const BString& cddbServer)
|
||||
:
|
||||
fInitialized(false),
|
||||
fConnected(false)
|
||||
{
|
||||
@@ -92,7 +94,7 @@ CDDBServer::Query(uint32 cddbId, const scsi_toc_toc* toc, BList* queryResponse)
|
||||
output.MoveInto(statusCode, 0, 3);
|
||||
if (statusCode == "210" || statusCode == "211") {
|
||||
// TODO(bga): We can get around with returning the first result
|
||||
// in case of multiple matches, but we most definitely needs a
|
||||
// in case of multiple matches, but we most definitely need a
|
||||
// better handling of inexact matches.
|
||||
if (statusCode == "211")
|
||||
printf("Warning : Inexact match found.\n");
|
||||
@@ -367,7 +369,7 @@ CDDBServer::_SendCddbCommand(const BString& command, BString* output)
|
||||
// Assemble full command string.
|
||||
BString fullCommand;
|
||||
fullCommand << command << "&hello=" << fLocalUserName << " " <<
|
||||
fLocalHostName << " cddb_daemon 1.0&proto=6";
|
||||
fLocalHostName << " cddb_lookup 1.0&proto=6";
|
||||
|
||||
// Replace spaces by + signs.
|
||||
fullCommand.ReplaceAll(" ", "+");
|
||||
@@ -2,7 +2,6 @@ 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 index ;
|
||||
SubInclude HAIKU_TOP src servers input ;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
SubDir HAIKU_TOP src servers cddb_daemon ;
|
||||
|
||||
UsePrivateHeaders drivers ;
|
||||
|
||||
AddResources cddb_daemon : cddb_daemon.rdef ;
|
||||
|
||||
Server cddb_daemon :
|
||||
cddb_daemon.cpp
|
||||
cddb_server.cpp
|
||||
: be bnetapi [ TargetLibsupc++ ]
|
||||
;
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008-2009, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Bruno Albuquerque, [email protected]
|
||||
*/
|
||||
|
||||
#ifndef _CDDB_DAEMON_H
|
||||
#define _CDDB_DAEMON_H
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#include <scsi_cmds.h>
|
||||
|
||||
struct ReadResponseData;
|
||||
struct QueryResponseData;
|
||||
|
||||
class BList;
|
||||
class BMessage;
|
||||
class BVolumeRoster;
|
||||
|
||||
class CDDBDaemon : public BApplication {
|
||||
public:
|
||||
CDDBDaemon();
|
||||
virtual ~CDDBDaemon();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
status_t _Lookup(const dev_t device);
|
||||
bool _CanLookup(const dev_t device, uint32* cddbId,
|
||||
scsi_toc_toc* toc) const;
|
||||
QueryResponseData* _SelectResult(BList* response) const;
|
||||
status_t _WriteCDData(dev_t device, QueryResponseData* diskData,
|
||||
ReadResponseData* readResponse);
|
||||
|
||||
BVolumeRoster* fVolumeRoster;
|
||||
};
|
||||
|
||||
#endif // _CDDB_DAEMON_H
|
||||
Reference in New Issue
Block a user