2 # This file is part of gtkD.
4 # gtkD is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU Lesser General Public License as published by
6 # the Free Software Foundation; either version 2.1 of the License, or
7 # (at your option) any later version.
9 # gtkD is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with gtkD; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # Definitions for wrapping GLib
30 /* The GLib Basic Types */
31 public alias int gint;
32 public alias uint guint;
33 public alias int gboolean;
34 public alias void* gpointer;
35 public alias void* gconstpointer;
36 public alias char gchar;
37 public alias char guchar;
38 public alias short gshort;
39 public alias ushort gushort;
40 public alias int glong;
41 public alias uint gulong;
42 public alias byte gint8;
43 public alias byte guint8;
44 public alias short gint16;
45 public alias ushort guint16;
46 public alias int gint32;
47 public alias long gint64;
48 public alias uint guint32;
49 public alias ulong guint64;
50 public alias float gfloat;
51 public alias double gdouble;
52 public alias uint gsize;
53 public alias int gssize;
54 public alias void* va_list;
55 public alias dchar unichar;
56 public alias wchar unichar2;
57 //public alias dchar gunichar;
58 //public alias wchar gunichar2;
59 public alias int time_t;
83 const uint G_MAXUINT = 4294967295;
88 # must start with wrap
92 ###########################################################
93 ### GLib Fundamentals #####################################
94 ###########################################################
96 file: glib-Version-Information.html
102 #file: glib-Basic-Types.html
105 #file: glib-Limits-of-Basic-Types.html
108 #file: glib-Standard-Macros.html
113 #file: glib-Type-Conversion-Macros.html
118 #file: glib-Byte-Order-Macros.html
123 #file: glib-Numerical-Definitions.html
128 #file: glib-Miscellaneous-Macros.html
133 file: glib-Atomic-Operations.html
138 ###########################################################
139 ### GLib Core Application Support #########################
140 ###########################################################
142 file: glib-The-Main-Event-Loop.html
147 noprefix: g_main_context_
152 structWrap: GDataset* Dataset
153 import: glib.MainContext
154 structWrap: GMainContext* MainContext
156 structWrap: GSource* Source
157 nocode: g_main_loop_ref
160 * Increases the reference count on a GMainLoop object by one.
166 public MainLoop doref()
168 // GMainLoop* g_main_loop_ref (GMainLoop *loop);
169 return new MainLoop( g_main_loop_ref(gMainLoop) );
176 prefix: g_main_context_
178 import: glib.MainLoop
179 structWrap: GMainLLoop* MainLoop
181 structWrap: GSource* Source
183 structWrap: GCond* Cond
184 import: gthread.Mutex
185 structWrap: GMutex* Mutex
186 import: glib.ThreadPool
187 structWrap: GThreadPoll* ThreadPoll
188 import: glib.MainContext
189 structWrap: GMainContext* MainContext
190 #import: glib.SourceFuncs
191 #structWrap: GSourceFuncs* SourceFuncs
193 #structWrap: GPollFD* PollFD
197 import: glib.MainLoop
198 structWrap: GMainLoop* MainLoop
200 structWrap: GDataset* Dataset
204 structWrap: GSource* Source
208 import: glib.MainLoop
209 structWrap: GMainLoop* MainLoop
211 structWrap: GDataset* Dataset
218 import: glib.MainLoop
219 structWrap: GMainLoop* MainLoop
221 structWrap: GDataset* Dataset
223 structWrap: GDate* Date
226 #import: glib.SourceFuncs
227 #structWrap: GSourceFuncs* SourceFuncs
229 structWrap: GSource* Source
230 import: glib.MainContext
231 structWrap: GMainContext* MainContext
232 #import: glib.SourceCallbackFuncs
233 #structWrap: GSourceCallbackFuncs* SourceCallbackFuncs
235 #structWrap: GPollFD* PollFD
236 #import: glib.TimeVal
237 #structWrap: GTimeVal* TimeVal
241 file: glib-Threads.html
245 #import: gthread.Mutex
246 #structWrap: GMutex* Mutex
248 #structWrap: GSource* Source
249 #import: glib.Dataset
250 #structWrap: GDataset* Dataset
252 #structWrap: GList* ListG
255 #noprefix: g_static_rec_mutex_
256 #noprefix: g_static_rw_lock_
258 #noprefix: g_private_
259 #noprefix: g_static_private_
260 ##import: glib.ThreadFunctions
261 ##structWrap: GThreadFunctions* ThreadFunctions
262 #structWrap: GThread* Thread
263 ##import: glib.Error*
264 ##structWrap: GError** Error*
265 ##import: glib.StaticMutex
266 ##structWrap: GStaticMutex* StaticMutex
275 #struct: GStaticRecMutex
276 #class: StaticRecMutex
277 #prefix: g_static_rec_mutex_
279 #outFile: StaticRecMutex
281 #struct: GStaticRWLock
283 #prefix: g_static_rw_lock_
290 #structWrap: GDate* Date
293 #import: gthread.Mutex
294 #structWrap: GMutex* Mutex
295 ##import: glib.TimeVal
296 ##structWrap: GTimeVal* TimeVal
301 #import: glib.Dataset
302 #structWrap: GDataset* Dataset
307 #struct: GStaticPrivate
308 #class: StaticPrivate
309 #import: glib.Dataset
310 #structWrap: GDataset* Dataset
311 #prefix: g_static_private_
313 #outFile: StaticPrivate
323 file: glib-Thread-Pools.html
328 structWrap: GList* ListG
329 prefix: g_thread_pool_
330 import: glib.MainLoop
334 file: glib-Asynchronous-Queues.html
337 prefix: g_async_queue_
340 import: glib.AsyncQueue
341 structWrap: GAsyncQueue* AsyncQueue
342 #import: glib.TimeVal
343 #structWrap: GTimeVal* TimeVal
346 file: glib-Dynamic-Loading-of-Modules.html
351 structWrap: GModule* Module
356 file: glib-Memory-Allocation.html
359 #import: glib.MemVTable
360 #structWrap: GMemVTable* MemVTable
364 file: glib-IO-Channels.html
367 prefix: g_io_channel_
373 structWrap: GString* StringG
374 structWrap: GSource* Source
375 #import: glib.IOChannel
376 structWrap: GIOChannel* IOChannel
380 file: glib-Error-Reporting.html
389 file: glib-Warnings-and-Assertions.html
395 file: glib-Message-Logging.html
402 ###########################################################
403 ### GLib Utilities ########################################
404 ###########################################################
406 file: glib-String-Utility-Functions.html
410 structWrap: GString* StringG
416 const static char[10] digits = "0123456789"; /// 0..9
418 /*************************************************
419 * Convert C-style 0 terminated string s to char[] string.
422 public static char[] toString(char *s)
424 return s ? s[0 .. strlen(s)] : cast(char[])null;
427 /*********************************
428 * Convert array of chars s[] to a C-style 0 terminated string.
431 public static char* toStringz(char[] s)
439 // // TODO this one fails in some case???
440 // assert(strlen(result) == s.length);
441 // assert(memcmp(result, s, s.length) == 0);
454 // Need to make a copy
455 copy = new char[s.length + 1];
456 copy[0..s.length] = s;
463 public static char** toStringzArray(char[][] args)
469 char** argv = (new char*[args.length]).ptr;
471 foreach (char[] p; args)
473 argv[argc++] = cast(char*)(p~'\0');
480 public static char[][] toStringArray(char** args)
490 while( (arg) != null && i<10)
492 argv ~= toString(arg);
500 public static char[] toString(bool b)
502 return b ? "true" : "false";
505 public static char[] toString(char c)
507 char[] result = new char[2];
510 return result[0 .. 1];
513 public static char[] toString(ubyte ub) { return toString(cast(uint) ub); } /// ditto
514 public static char[] toString(ushort us) { return toString(cast(uint) us); } /// ditto
516 public static char[] toString(uint u)
517 { char[uint.sizeof * 3] buffer = void;
524 // Avoid storage allocation for simple stuff
525 result = digits[u .. u + 1];
533 buffer[buffer.length - ndigits] = c;
535 result = new char[ndigits];
536 result[] = buffer[buffer.length - ndigits .. buffer.length];
541 public static char[] toString(ulong u)
542 { char[ulong.sizeof * 3] buffer;
547 if (u < 0x1_0000_0000)
548 return toString(cast(uint)u);
555 buffer[buffer.length - ndigits] = c;
557 result = new char[ndigits];
558 result[] = buffer[buffer.length - ndigits .. buffer.length];
562 public static char[] toString(byte b) { return toString(cast(int) b); } /// ditto
563 public static char[] toString(short s) { return toString(cast(int) s); } /// ditto
565 public static char[] toString(int i)
566 { char[1 + int.sizeof * 3] buffer;
571 return toString(cast(uint)i);
579 buffer[buffer.length - ndigits] = c;
582 buffer[buffer.length - ndigits] = '-';
583 result = new char[ndigits];
584 result[] = buffer[buffer.length - ndigits .. buffer.length];
593 file: glib-Character-Set-Conversion.html
598 # these fail to compile because of a reference to a struct that size is not known
599 noprefix: g_convert_with_iconv
600 noprefix: g_iconv_open
602 noprefix: g_iconv_close
603 outFile: CharacterSet
605 file: glib-Unicode-Manipulation.html
613 class: Internationalization
616 outFile: Internationalization
618 file: glib-Date-and-Time-Functions.html
622 #import: glib.TimeVal
623 #structWrap: GTimeVal* TimeVal
626 structWrap: GDate* Date
629 file: glib-Random-Numbers.html
634 structWrap: GRand* RandG
637 #file: glib-Hook-Functions.html
640 ##import: glib.HookList
641 ##structWrap: GHookList* HookList
643 #structWrap: GHook* Hook
646 file: glib-Miscellaneous-Utility-Functions.html
649 structWrap: GList* ListG
651 #import: glib.DebugKey
652 #structWrap: GDebugKey* DebugKey
657 file: glib-Lexical-Scanner.html
660 import: glib.HashTable
661 structWrap: GHashTable* HashTable
663 #import: glib.Scanner
664 structWrap: GScanner* ScannerG
665 #import: glib.ScannerConfig
666 #structWrap: GScannerConfig* ScannerConfig
670 file: glib-Automatic-String-Completion.html
672 class: StringCompletion
674 structWrap: GList* ListG
677 outFile: StringCompletion
679 file: glib-Timers.html
684 structWrap: GTimer* Timer
687 file: glib-Spawning-Processes.html
690 import: glib.MainLoop
691 structWrap: GMainLoop* MainLoop
694 #structWrap: GPid* Pid
696 #structWrap: GError** Error*
703 nocode: g_spawn_async_with_pipes
707 version(Tango) alias splitLines splitlines;
710 char[] workingDirectory = ".";
713 GSpawnFlags flags = SpawnFlags.SEARCH_PATH;
714 GSpawnChildSetupFunc childSetup;
718 FILE* standardOutput;
725 // for commandLineSync
730 alias bool delegate(Spawn) ChildWatch;
731 ChildWatch externalWatch;
734 * Creates a Spawn for execution.
736 public this(char[] program, char[][] envp=null)
743 * Creates a Spawn for execution.
745 public this(char[][] program, char[][] envp=null)
752 * Adds a delegate to be notified on the end of the child process.
757 public void addChildWatch(ChildWatch dlg)
763 * Closes all open streams and child process.
769 fclose(standardInput);
774 fclose(standardOutput);
779 fclose(standardError);
790 * Adds a parameter to the execution program
792 public void addParm(char[] parm)
798 * Gets the last error message
800 public char[] getLastError()
804 return Str.toString(error.message);
811 * Executes the prepared process
813 public int execAsyncWithPipes(
814 ChildWatch externalWatch = null,
815 bool delegate(char[]) readOutput = null,
816 bool delegate(char[]) readError = null )
818 int result = g_spawn_async_with_pipes(
819 Str.toStringz(workingDirectory),
820 Str.toStringzArray(argv),
821 Str.toStringzArray(envp),
834 this.externalWatch = externalWatch;
835 g_child_watch_add(childPid, cast(GChildWatchFunc)(&childWatchCallback), cast(void*)this);
836 standardInput = fdopen(stdIn, "w");
837 standardOutput = fdopen(stdOut, "r");
838 standardError = fdopen(stdErr, "r");
840 if ( readOutput !is null )
842 (new ReadFile(standardOutput, readOutput)).start();
844 if ( readError !is null )
846 (new ReadFile(standardError, readError)).start();
853 class ReadFile : Thread
855 bool delegate(char[]) read;
860 this(FILE* file, bool delegate (char[]) read )
868 char[] line = readLine(file);
869 while( line !is null )
872 //writefln("Spawn.ReadFile.run line (%s) ========== >>>%s<<<", lineCount, line);
873 //printf("Spawn.ReadFile.run line (%d) ========== >>>%.*s<<<", lineCount, line);
878 line = readLine(file);
884 private char[] readLine(FILE* stream, int max=4096)
888 if ( externalWatch !is null )
896 char* lineP = fgets(line.ptr, max, stream);
901 int l = strlen(line.ptr);
903 //printf("\nreadLine\n");
904 //foreach ( char c ; line )
912 extern(C) static void childWatchCallback(int pid, int status, Spawn spawn)
914 //writefln("Spawn.childWatchCallback %s %s", pid, status);
915 spawn.exitStatus = status;
916 if ( spawn.externalWatch !is null )
918 spawn.externalWatch(spawn);
924 public bool endOfOutput()
926 if ( standardOutput is null ) return true;
927 return feof(standardOutput) != 0;
930 public bool endOfError()
932 if ( standardError is null ) return true;
933 return feof(standardError) != 0;
936 char[] getOutputString()
938 return Str.toString(strOutput);
941 char[] getErrorString()
943 return Str.toString(strError);
952 // public int commandLineSync()
954 // char[] commandLine;
955 // foreach ( int count, char[] arg; argv)
959 // commandLine ~= ' ';
961 // commandLine ~= arg;
963 // return g_spawn_command_line_sync(
965 // Str.toStringz(commandLine),
973 * Executes a command synchronasly and
974 * optionally calls delegates for sysout, syserr and end of job
977 public int commandLineSync(
978 ChildWatch externalWatch = null,
979 bool delegate(char[]) readOutput = null,
980 bool delegate(char[]) readError = null )
983 foreach ( int count, char[] arg; argv)
991 int status = g_spawn_command_line_sync(
992 Str.toStringz(commandLine),
997 if ( readOutput != null )
999 foreach ( char[] line ; splitlines(Str.toString(strOutput)) )
1004 if ( readError != null )
1006 foreach ( char[] line ; splitlines(Str.toString(strError)) )
1011 if ( externalWatch != null )
1013 externalWatch(this);
1025 file: glib-File-Utilities.html
1030 #import: glib.ErrorG
1031 #import: glib.Error*
1032 #structWrap: GError** Error*
1034 #structWrap: GDir* Dir
1035 #import: glib.MappedFile
1036 #structWrap: GMappedFile* MappedFile
1039 file: glib-Shell-related-Utilities.html
1046 file: glib-Commandline-option-parser.html
1048 struct: GOptionContext
1049 class: OptionContext
1051 prefix: g_option_context_
1052 noprefix: g_option_group_
1053 #import: glib.Error*
1054 #structWrap: GError** Error*
1055 #import: glib.OptionEntry
1056 #structWrap: GOptionEntry* OptionEntry
1057 import: glib.OptionGroup
1058 structWrap: GOptionGroup* OptionGroup
1060 outFile: OptionContext
1062 struct: GOptionGroup
1064 import: glib.Dataset
1065 structWrap: GDataset* Dataset
1066 import: glib.OptionContext
1067 structWrap: GOptionContext* OptionContext
1068 prefix: g_option_group_
1070 #import: glib.OptionEntry
1071 #structWrap: GOptionEntry* OptionEntry
1073 outFile: OptionGroup
1075 file: glib-Glob-style-pattern-matching.html
1076 struct: GPatternSpec
1078 prefix: g_pattern_spec_
1079 prefix: g_pattern_match_
1080 #import: glib.PatternSpec
1081 structWrap: GPatternSpec* Pattern
1085 file: glib-Simple-XML-Subset-Parser.html
1086 struct: GMarkupParseContext
1089 import: glib.Dataset
1090 structWrap: GDataset* Dataset
1091 prefix: g_markup_parse_context_
1092 #import: glib.Error*
1093 #structWrap: GError** Error*
1094 #import: glib.MarkupParser
1095 #structWrap: GMarkupParser* MarkupParser
1099 file: glib-Key-value-file-parser.html
1107 file: glib-Windows-Compatibility-Functions.html
1111 outFile: WindowsUtils
1114 ###########################################################
1115 ### GLib Data Types #######################################
1116 ###########################################################
1118 file: glib-Memory-Slices.html
1121 outFile: MemorySlice
1123 file: glib-Memory-Chunks.html
1126 prefix: g_mem_chunk_
1128 outFile: MemoryChunk
1130 file: glib-Doubly-Linked-Lists.html
1135 structWrap: GList* ListG
1141 int* pt =cast(int*)getStruct();
1142 return cast(void *)(*pt);
1151 file: glib-Singly-Linked-Lists.html
1156 #import: glib.ListSG
1157 structWrap: GSList* ListSG
1160 file: glib-Double-ended-Queues.html
1165 #import: glib.QueueG
1166 structWrap: GQueue* QueueG
1168 structWrap: GList* ListG
1171 file: glib-Trash-Stacks.html
1174 prefix: g_trash_stack_
1175 #import: glib.TrashStack*
1176 #structWrap: GTrashStack** TrashStack*
1179 file: glib-Hash-Tables.html
1182 import: glib.Dataset
1183 prefix: g_hash_table_
1184 #import: glib.HashTable
1185 structWrap: GHashTable* HashTable
1188 file: glib-Strings.html
1192 #import: glib.StringG
1193 structWrap: GString* StringG
1197 file: glib-String-Chunks.html
1198 struct: GStringChunk
1200 prefix: g_string_chunk_
1202 outFile: StringGChunk
1204 file: glib-Arrays.html
1210 structWrap: GArray* ArrayG
1214 file: glib-Pointer-Arrays.html
1218 structWrap: GList* ListG
1219 prefix: g_ptr_array_
1220 #import: glib.PtrArray
1221 structWrap: GPtrArray* PtrArray
1224 file: glib-Byte-Arrays.html
1228 structWrap: GList* ListG
1229 prefix: g_byte_array_
1232 file: glib-Balanced-Binary-Trees.html
1236 import: glib.Dataset
1237 structWrap: GList* List*
1238 structWrap: GDataset* Dataset
1242 file: glib-N-ary-Trees.html
1246 structWrap: GTree* BBTree
1247 structWrap: GNode* Node
1251 file: glib-Quarks.html
1259 file: glib-Keyed-Data-Lists.html
1264 import: glib.Dataset
1265 structWrap: GDataset* Dataset
1268 file: glib-Datasets.html
1274 file: glib-Relations-and-Tuples.html
1277 import: glib.HashTable
1278 structWrap: GHashTable* HashTable
1282 structWrap: GTuples* Tuples
1291 file: glib-Caches.html
1294 import: glib.HashTable
1295 structWrap: GHashTable* HashTable
1299 file: glib-Memory-Allocators.html
1302 prefix: g_allocator_
1306 ###########################################################
1307 ### GLib Tools ############################################
1308 ###########################################################