First the fun bug. The libgpod bindings did the normal thing of defining a managed struct which mirrored the native struct that libgpod uses. This means we can do a trivial byte copy of the unmanaged memory into one of our managed structs and trivially access the information in a safe way. This is all well and good right up until you realise that when you update a property on that struct, you are not actually changing the value of the unmanaged memory. Essentially you have two copies of the same data which are disconnected - one in managed memory and one in native memory. Updating one copy is not reflected in the other and there's no easy way to keep them synced without the risk of losing data.
After a bit of brainstorming with Jeremie, we came up with a rather neat and nifty solution. Take this struct as an example:
struct NativeDate {
public int Day;
public int Month;
public int Year;
}
If native code allocates one of those and passes it to .NET as an IntPtr, there is a trivial way to map this to managed code without requiring a copy of the data.
unsafe class Date {
IntPtr Native {
get; set;
}
public int Day {
get { return ((NativeDate *)Native)->Day; }
set { ((NativeDate *) Native)->Day = value; }
}
public int Month {
get { return ((NativeDate *) Native)->Month; }
set { ((NativeDate *) Native)->Month = value; }
}
public int Year {
get { return ((NativeDate *) Native)->Year; }
set { ((NativeDate *) Native)->Year = value; }
}
public Date (IntPtr native)
{
Native = native;
}
}
All we do is use a bit of unsafe code to take the pointer that we got from native code and cast it to a NativeStruct* and read or write the data as appropriate. Now both managed land and unmanaged land are working off the same hunk of memory so they can never get out of sync.
Now for the features! Banshee can now sync music to my iPhone and remove it aswell! This means all the basic stuff that's required for basic syncing is supported now. It took a lot longer than it should've to get this working because my iPhone wasn't actually set up right. There was a command (i can't remember the name of it now) which should've been run automatically to populate iTunes_Control/Device with some required information. This was never run for some bizarre reason (yay for bleeding edge) which meant nothing I did could ever actually update the database.
However once I got that setup, things progressed pretty rapidly. There's one major feature left which is automatic detection when the device is mounted. If i can get this done tomorrow i'll try to upstream everything and get people testing this by the weekend (or friday!).
6 comments:
Very nice Blog post thanks a lot for this great article post I love to read such a nice blog.
Smith Alan
Good post...Thanks for posting..
Regards,
I read really much helpful information here!
The blog content writing provides different techniques off writing online with great variations.
2019.12.27台北八大行業知名酒店經紀獨家分析:每當看到酒店工作酒店小姐被「框」出場性侵的新聞,就覺得很無奈,一方面是為了有酒店上班姊妹遇到這樣的事情很難過,一方面是被新聞誇張不實報導,引起社會的恐慌甚至各大留言板的對話更讓人翻白眼。某些人,對大學生/上班族酒店上班的新人對於「框」有很大的誤解。八大行業資深經紀人專業酒店打工解釋裡說的「框」,是指直接包下小姐特定的時間。其實最單純來說,功能有兩種:把小姐找過來或留下來、帶小姐出店家。有時候到店家找自己認識的小姐,但酒店小姐目前在手工(打手槍) 、口爆(口交)服務其他客人,想要把該名小姐找過來,如果用點的,遇到對方喊加點,就只能喊框了;或是有其他客人想點走正在服務自己的小姐,加點後對方又喊框,如果這時前桌喊框,效力是優於後桌的。看起來很複雜,但簡言之,就是把小姐留在自己身邊的一種方法。而「框出」的定義和內涵,就值得深入討論了。歡迎想要高收入賺現金酒店兼差的大學生/上班族,可上網求證對八大行業酒店兼職得相關資訊做核對比對甚至多比較,才能賺錢賺得安心,同時也要保護自己。
Very useful information, a java assignment help professional can utilize it to write perfect assignments, they can easily enhance their skills in coding and hacking with this kind of information.
Post a Comment