mirror of
				https://github.com/Ryujinx/GtkSharp.git
				synced 2025-11-04 14:24:52 +00:00 
			
		
		
		
	2004-01-29 Mike Kestner <mkestner@ximian.com>
* glib/time_t_CustomMarshaler.cs : new custom marshaler form time_t. * glue/time_t.c : glue for time_t. * glue/Makefile.am : add time_t.c * glue/makefile.win32 : ditto svn path=/trunk/gtk-sharp/; revision=22595
This commit is contained in:
		
							parent
							
								
									a987ae2982
								
							
						
					
					
						commit
						ae5ab001be
					
				| 
						 | 
					@ -1,3 +1,10 @@
 | 
				
			||||||
 | 
					2004-01-29  Mike Kestner  <mkestner@ximian.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* glib/time_t_CustomMarshaler.cs : new custom marshaler form time_t.
 | 
				
			||||||
 | 
						* glue/time_t.c : glue for time_t.
 | 
				
			||||||
 | 
						* glue/Makefile.am : add time_t.c
 | 
				
			||||||
 | 
						* glue/makefile.win32 : ditto
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2004-01-28  John Luke  <jluke@cfl.rr.com>
 | 
					2004-01-28  John Luke  <jluke@cfl.rr.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	* glade/XML.custom : some null checking for crash prevention.
 | 
						* glade/XML.custom : some null checking for crash prevention.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										70
									
								
								glib/time_t_CustomMarshaler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								glib/time_t_CustomMarshaler.cs
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,70 @@
 | 
				
			||||||
 | 
					// time_t_CustomMarshaler.cs - Custom marshaling between time_t and DateTime
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Author: Mike Kestner <mkestner@ximian.com>
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Copyright (c) 2004 Novell, Inc.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace GLib {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						using System;
 | 
				
			||||||
 | 
						using System.Runtime.InteropServices;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public class time_t_CustomMarshaler : ICustomMarshaler {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							static time_t_CustomMarshaler marshaler;
 | 
				
			||||||
 | 
							int utc_offset;
 | 
				
			||||||
 | 
							DateTime local_epoch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							private time_t_CustomMarshaler () 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								utc_offset = DateTime.Now.Subtract (DateTime.UtcNow).Seconds;
 | 
				
			||||||
 | 
								local_epoch = new DateTime (1970, 1, 1, 0, 0, 0);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public static ICustomMarshaler GetInstance (string cookie)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (marshaler == null)
 | 
				
			||||||
 | 
									marshaler = new time_t_CustomMarshaler ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return marshaler;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[DllImport ("gtksharpglue")]
 | 
				
			||||||
 | 
							static extern int gtksharp_time_t_sizeof ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[DllImport ("gtksharpglue")]
 | 
				
			||||||
 | 
							static extern void gtksharp_time_t_print (int time_t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public IntPtr MarshalManagedToNative (object obj)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								DateTime dt = (DateTime) obj;
 | 
				
			||||||
 | 
								int size = Marshal.SizeOf (typeof (int)) + gtksharp_time_t_sizeof ();
 | 
				
			||||||
 | 
								IntPtr ptr = Marshal.AllocCoTaskMem (size);
 | 
				
			||||||
 | 
								IntPtr time_t_ptr = new IntPtr (ptr.ToInt32 () + Marshal.SizeOf (typeof(int)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								int secs = dt.Subtract (local_epoch).Seconds + utc_offset;
 | 
				
			||||||
 | 
								Console.WriteLine ("Marshaling DateTime: " + dt);
 | 
				
			||||||
 | 
								Marshal.WriteInt32 (time_t_ptr, secs);
 | 
				
			||||||
 | 
								gtksharp_time_t_print (secs);
 | 
				
			||||||
 | 
								return time_t_ptr;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void CleanUpNativeData (IntPtr data)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								IntPtr ptr = new IntPtr (data.ToInt32 () - Marshal.SizeOf (typeof (int)));
 | 
				
			||||||
 | 
								Marshal.FreeCoTaskMem (ptr);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public object MarshalNativeToManaged (IntPtr data)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								throw new NotImplementedException ();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void CleanUpManagedData (object obj) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public int GetNativeDataSize ()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								throw new NotImplementedException ();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,7 @@ BASESOURCES = 			\
 | 
				
			||||||
	selectiondata.c		\
 | 
						selectiondata.c		\
 | 
				
			||||||
	slist.c			\
 | 
						slist.c			\
 | 
				
			||||||
	style.c			\
 | 
						style.c			\
 | 
				
			||||||
 | 
						time_t.c		\
 | 
				
			||||||
	type.c			\
 | 
						type.c			\
 | 
				
			||||||
	value.c			\
 | 
						value.c			\
 | 
				
			||||||
	valuearray.c		\
 | 
						valuearray.c		\
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,7 @@ GLUE_OBJS = \
 | 
				
			||||||
        selectiondata.o         \
 | 
					        selectiondata.o         \
 | 
				
			||||||
        slist.o                 \
 | 
					        slist.o                 \
 | 
				
			||||||
        style.o                 \
 | 
					        style.o                 \
 | 
				
			||||||
 | 
					        time_t.o                \
 | 
				
			||||||
        type.o                  \
 | 
					        type.o                  \
 | 
				
			||||||
        value.o                 \
 | 
					        value.o                 \
 | 
				
			||||||
        valuearray.o            \
 | 
					        valuearray.o            \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										26
									
								
								glue/time_t.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								glue/time_t.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,26 @@
 | 
				
			||||||
 | 
					/* time_t.c : Glue to allocate time_t.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Author: Mike Kestner <mkestner@ximian.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright <c> 2004 Novell, Inc.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <glib.h>
 | 
				
			||||||
 | 
					#include <time.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Forward declarations */
 | 
				
			||||||
 | 
					gint gtksharp_time_t_sizeof (void);
 | 
				
			||||||
 | 
					void gtksharp_time_t_print (time_t t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gint
 | 
				
			||||||
 | 
					gtksharp_time_t_sizeof ()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return sizeof (time_t);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					gtksharp_time_t_print (time_t t)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						printf ("%s\n", ctime (&t));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in a new issue