commit 5dd2da26eabf21451fc64664af6c5b1c3b3a8f5d
Author: Alan McGovern <[email protected]>
Date: Sun Jun 13 16:42:00 2010 +0100
Rewrite IpodInfo so that we marshal the native table properly.
Signed-off-by: Nathaniel McCallum <[email protected]>
bindings/mono/libgpod-sharp/Device.cs | 2 +-
bindings/mono/libgpod-sharp/IpodInfo.cs | 65 ++++++++++++++++++++++---------
2 files changed, 47 insertions(+), 20 deletions(-)
---
diff --git a/bindings/mono/libgpod-sharp/Device.cs
b/bindings/mono/libgpod-sharp/Device.cs
index 0e04f16..2f76e05 100644
--- a/bindings/mono/libgpod-sharp/Device.cs
+++ b/bindings/mono/libgpod-sharp/Device.cs
@@ -91,7 +91,7 @@ namespace GPod {
public bool SupportsPodcast { get {
return Itdb_Device.itdb_device_supports_podcast(Handle); } }
public bool SupportsVideo { get {
return Itdb_Device.itdb_device_supports_video(Handle); } }
//public SysInfo SysInfo
{ get { return new SysInfo(Handle); } }
- public IpodInfo IpodInfo { get {
return new IpodInfo(Itdb_Device.itdb_device_get_ipod_info(Handle), true); } }
+ public IpodInfo IpodInfo { get {
return IpodInfo.Find (Itdb_Device.itdb_device_get_ipod_info(Handle)); } }
public string Mountpoint { get {
return PtrToStringUTF8 (((Itdb_Device *)Native)->mountpoint); }
set { Itdb_Device.itdb_device_set_mountpoint(Handle, value);
} }
diff --git a/bindings/mono/libgpod-sharp/IpodInfo.cs
b/bindings/mono/libgpod-sharp/IpodInfo.cs
index ef2c8e4..ffde03a 100644
--- a/bindings/mono/libgpod-sharp/IpodInfo.cs
+++ b/bindings/mono/libgpod-sharp/IpodInfo.cs
@@ -20,6 +20,7 @@ namespace GPod {
using System;
using System.Runtime.InteropServices;
using native;
+ using System.Collections.Generic;
namespace native {
internal struct Itdb_IpodInfo {
@@ -27,7 +28,13 @@ namespace GPod {
public double capacity;
public IpodModel ipod_model;
public IpodGeneration ipod_generation;
- // Ignore the rest
+
+ /* We don't use these 5 fields but this struct must
mirror the native one exactly */
+ uint musicdirs;
+ int reserved_int1;
+ int reserved_int2;
+ IntPtr reserved1;
+ IntPtr reserved2;
[DllImport ("gpod")]
internal static extern IntPtr
itdb_info_get_ipod_info_table();
@@ -115,24 +122,31 @@ namespace GPod {
IphoneBlack,
}
- public unsafe class IpodInfo : GPodBase {
- public static IpodInfo[] GetTable() {
- IntPtr table =
Itdb_IpodInfo.itdb_info_get_ipod_info_table();
-
- // Count the number of returned structs
- int count=0;
- while (Marshal.ReadIntPtr(table, count * IntPtr.Size)
!= IntPtr.Zero) count++;
-
- // Create our array
- IpodInfo[] retval = new IpodInfo[count];
-
- // Assign to the array
- for (int i=0 ; i < count ; i++)
- retval[i] = new
IpodInfo(Marshal.ReadIntPtr(table, i * IntPtr.Size), true);
+ public sealed unsafe class IpodInfo : GPodBase {
+ public static IpodInfo[] Table = GetTable ();
+
+ static unsafe IpodInfo[] GetTable() {
+ Itdb_IpodInfo *table = (Itdb_IpodInfo *)
Itdb_IpodInfo.itdb_info_get_ipod_info_table();
- return retval;
+ List <IpodInfo> retval = new List<IpodInfo> ();
+ while (true) {
+ Itdb_IpodInfo *item = &table [retval.Count];
+ if (item->model_number == IntPtr.Zero)
+ break;
+ retval.Add (new IpodInfo ((IntPtr)item, true));
+ }
+ return retval.ToArray ();
+ }
+
+ internal static IpodInfo Find (IntPtr native)
+ {
+ for (int i = 0; i < Table.Length; i++)
+ if (Table [i].Native == native)
+ return Table [i];
+ return null;
}
+ // Capacity is in gigabytes
public double Capacity {
get { return ((Itdb_IpodInfo *) Native)->capacity; }
}
@@ -157,8 +171,21 @@ namespace GPod {
get { return PtrToStringUTF8
(Itdb_IpodInfo.itdb_info_get_ipod_model_name_string(this.Model)); }
}
- public IpodInfo(IntPtr handle, bool borrowed) : base(handle,
borrowed) {}
- public IpodInfo(IntPtr handle) : base(handle) {}
- protected override void Destroy() { }
+ IpodInfo (IntPtr handle, bool borrowed)
+ : base (handle, borrowed)
+ {
+
+ }
+
+ IpodInfo (IntPtr handle)
+ : base (handle)
+ {
+
+ }
+
+ protected override void Destroy()
+ {
+ // No need to free anything as it's a static array in
native code.
+ }
}
}
\ No newline at end of file
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2