[banshee] MusicBrainz: Enable FreeBSD support
- From: Alexander Kojevnikov <alexk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] MusicBrainz: Enable FreeBSD support
- Date: Sun, 22 Jan 2012 07:22:51 +0000 (UTC)
commit c5e2433c3c82e96996eb04fb690300728da20d4c
Author: Alexander Kojevnikov <alexk gnome org>
Date: Sun Jan 22 15:19:52 2012 +0800
MusicBrainz: Enable FreeBSD support
* Sync with patches from BSD#
* s/DiscFreeBSD/DiscFreeBsd/g
* HACKING compliance
src/Libraries/MusicBrainz/Makefile.am | 1 +
src/Libraries/MusicBrainz/MusicBrainz.csproj | 1 +
.../MusicBrainz/MusicBrainz/DiscFreeBsd.cs | 88 ++++++++++---------
src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs | 13 ++-
4 files changed, 56 insertions(+), 47 deletions(-)
---
diff --git a/src/Libraries/MusicBrainz/Makefile.am b/src/Libraries/MusicBrainz/Makefile.am
index 006b834..904d3fa 100644
--- a/src/Libraries/MusicBrainz/Makefile.am
+++ b/src/Libraries/MusicBrainz/Makefile.am
@@ -4,6 +4,7 @@ LINK = $(REF_MUSICBRAINZ)
SOURCES = \
MusicBrainz/Artist.cs \
MusicBrainz/Disc.cs \
+ MusicBrainz/DiscFreeBsd.cs \
MusicBrainz/DiscLinux.cs \
MusicBrainz/DiscWin32.cs \
MusicBrainz/Event.cs \
diff --git a/src/Libraries/MusicBrainz/MusicBrainz.csproj b/src/Libraries/MusicBrainz/MusicBrainz.csproj
index adf85e7..e59d1a8 100644
--- a/src/Libraries/MusicBrainz/MusicBrainz.csproj
+++ b/src/Libraries/MusicBrainz/MusicBrainz.csproj
@@ -52,6 +52,7 @@
<Compile Include="MusicBrainz\Track.cs" />
<Compile Include="MusicBrainz\Utils.cs" />
<Compile Include="MusicBrainz\XmlRequestEventArgs.cs" />
+ <Compile Include="MusicBrainz\DiscFreeBsd.cs" />
<Compile Include="MusicBrainz\DiscLinux.cs" />
<Compile Include="MusicBrainz\DiscWin32.cs" />
</ItemGroup>
diff --git a/src/Libraries/MusicBrainz/MusicBrainz/DiscFreeBsd.cs b/src/Libraries/MusicBrainz/MusicBrainz/DiscFreeBsd.cs
index a89e387..85b094a 100644
--- a/src/Libraries/MusicBrainz/MusicBrainz/DiscFreeBsd.cs
+++ b/src/Libraries/MusicBrainz/MusicBrainz/DiscFreeBsd.cs
@@ -1,5 +1,5 @@
-// DiskFreeBSD.cs
-//
+// DiskFreeBsd.cs
+//
// Copyright (c) 2009 Romain TartiÃre <romain blogreen org>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,36 +25,36 @@ using System.Runtime.InteropServices;
namespace MusicBrainz
{
- internal sealed class DiscFreeBSD : LocalDisc
+ internal sealed class DiscFreeBsd : LocalDisc
{
- #region <fcntl.h>
- const int O_RDONLY = 0x0;
+#region <fcntl.h>
// open for reading only
- const int O_NONBLOCK = 0x4;
+ const int O_RDONLY = 0x0000;
// no delay
- [DllImport("libc.so.7", CharSet = CharSet.Auto, SetLastError = true)]
+ const int O_NONBLOCK = 0x0004;
+
+ [DllImport ("libc", CharSet = CharSet.Auto, SetLastError = true)]
static extern int open (string path, int flags);
- #endregion
+#endregion
- #region <unistd.h>
- [DllImport("libc.so.7", SetLastError = true)]
+#region <unistd.h>
+ [DllImport ("libc", SetLastError = true)]
static extern int close (int d);
- #endregion
+#endregion
- #region <sys/cdio.h>
+#region <sys/cdio.h>
struct msf_lba
{
- public int lba;
- // network byte order
+ public int lba; // network byte order
}
- [StructLayout(LayoutKind.Explicit)]
+ [StructLayout (LayoutKind.Explicit)]
struct cd_toc_entry
{
- [FieldOffset(2)]
+ [FieldOffset (2)]
public byte track;
- [FieldOffset(4)]
+ [FieldOffset (4)]
public msf_lba addr;
}
@@ -69,7 +69,7 @@ namespace MusicBrainz
public byte ending_track;
}
const ulong CDIOREADTOCHEADER = 1074029316;
- [DllImport("libc.so.7", EntryPoint = "ioctl")]
+ [DllImport ("libc", EntryPoint = "ioctl")]
static extern int cd_read_toc_header (int fd, ulong request, ref ioc_toc_header data);
static int cd_read_toc_header (int fd, ref ioc_toc_header data)
{
@@ -81,64 +81,68 @@ namespace MusicBrainz
public byte address_format;
public byte starting_track;
public ushort data_len;
- public IntPtr data;
- // cd_toc_entry*
+ public IntPtr data; // cd_toc_entry*
}
- const ulong CDIOREADTOCENTRYS = 3222299397u;
- [DllImport("libc.so.7", EntryPoint = "ioctl")]
+ const ulong CDIOREADTOCENTRYS = 3222299397;
+ [DllImport ("libc", EntryPoint = "ioctl")]
static extern int cd_read_toc_entrys (int fd, ulong request, ref ioc_read_toc_entry data);
static int cd_read_toc_entrys (int fd, ref ioc_read_toc_entry data)
{
return cd_read_toc_entrys (fd, CDIOREADTOCENTRYS, ref data);
}
- #endregion
+#endregion
- internal DiscFreeBSD (string device)
+ internal DiscFreeBsd (string device)
{
int fd = open (device, O_RDONLY | O_NONBLOCK);
-
- if (fd < 0)
+
+ if (fd < 0) {
throw new LocalDiscException (String.Format ("Cannot open device `{0}'", device));
-
+ }
+
try {
ioc_toc_header h = new ioc_toc_header ();
- if (cd_read_toc_header (fd, ref h) < 0)
+ if (cd_read_toc_header (fd, ref h) < 0) {
throw new LocalDiscException ("Cannot read table of contents header");
- if (h.ending_track == 0)
+ }
+ if (h.ending_track == 0) {
throw new LocalDiscException ("This disc has no tracks");
-
+ }
+
first_track = h.starting_track;
last_track = h.ending_track;
-
+
int n = h.ending_track - h.starting_track + 1;
- int len = (n + 1) * Marshal.SizeOf (typeof(cd_toc_entry));
-
+ int len = (n + 1) * Marshal.SizeOf (typeof (cd_toc_entry));
+
ioc_read_toc_entry t = new ioc_read_toc_entry ();
t.address_format = CD_LBA_FORMAT;
t.starting_track = 0;
- t.data_len = (ushort)len;
+ t.data_len = (ushort) len;
t.data = Marshal.AllocHGlobal (len);
try {
-
- if (cd_read_toc_entrys (fd, ref t) < 0)
+
+ if (cd_read_toc_entrys (fd, ref t) < 0) {
throw new LocalDiscException ("Cannot read table of contents entries");
-
+ }
+
for (int i = 0; i <= n; i++) {
- ulong offset = (ulong)(i * Marshal.SizeOf (typeof(cd_toc_entry)));
- cd_toc_entry e = (cd_toc_entry)Marshal.PtrToStructure ((IntPtr)((ulong)t.data + offset), typeof(cd_toc_entry));
+ ulong offset = (ulong) (i * Marshal.SizeOf (typeof (cd_toc_entry)));
+ cd_toc_entry e = (cd_toc_entry) Marshal.PtrToStructure ((IntPtr) ((ulong)t.data + offset), typeof (cd_toc_entry));
track_offsets[first_track + i] = System.Net.IPAddress.NetworkToHostOrder (e.addr.lba) + 150;
}
+
// Move Leadout to the beginning.
- track_offsets[0] = track_offsets[last_track + 1];
- track_offsets[last_track + 1] = 0;
+ track_offsets [0] = track_offsets [last_track + 1];
+ track_offsets [last_track + 1] = 0;
} finally {
Marshal.FreeHGlobal (t.data);
}
} finally {
close (fd);
}
-
+
Init ();
}
}
diff --git a/src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs b/src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs
index e129126..90bfe55 100644
--- a/src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs
+++ b/src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs
@@ -128,16 +128,19 @@ namespace MusicBrainz
public static LocalDisc GetFromDevice (string device)
{
- if (device == null) throw new ArgumentNullException ("device");
+ if (device == null) {
+ throw new ArgumentNullException ("device");
+ }
+
try {
switch (Environment.OSVersion.Platform){
case PlatformID.Unix:
// TODO can we actually detect the environment?
- //try {
+ try {
return new DiscLinux (device);
- //} catch {
- // return new DiscFreeBSD (device);
- //}
+ } catch {
+ return new DiscFreeBsd (device);
+ }
//case PlatformID.Win32NT:
//return new DiscWin32NT (device);
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]