summaryrefslogtreecommitdiff
blob: a3491fd731c4f765d6c90742b42ac99e44205b4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;                           /* IntPtr */
using System.Runtime.InteropServices;   /* DLLImport */

namespace GhostAPI
{
	public struct gsapi_revision_t
	{
		public IntPtr product;
		public IntPtr copyright;
		public int revision;
		public int revisiondate;
	}

	public enum gs_set_param_type
	{ 
		gs_spt_invalid =   -1,
		gs_spt_null =		0,   /* void * is NULL */
		gs_spt_bool =		1,   /* void * is NULL (false) or non-NULL (true) */
		gs_spt_int =		2,   /* void * is a pointer to an int */
		gs_spt_float =		3,   /* void * is a float * */
		gs_spt_name =		4,   /* void * is a char * */
		gs_spt_string =		5,   /* void * is a char * */
		gs_spt_long =		6,   /* void * is a long * */
		gs_spt_i64 =		7,   /* void * is a int64_t * */
		gs_spt_size_t =		8,    /* void * is a size_t * */
		gs_spt_parsed =		9,   /* void * is a pointer to a char * to be parsed */
		gs_spt_more_to_come = 1 << 31
	};

	public enum gsEncoding
	{
		GS_ARG_ENCODING_LOCAL = 0,
		GS_ARG_ENCODING_UTF8 = 1,
		GS_ARG_ENCODING_UTF16LE = 2
	};

	static class gsConstants
	{
		public const int E_QUIT = -101;
		public const int GS_READ_BUFFER = 32768;
		public const int DISPLAY_UNUSED_LAST = (1 << 7);
		public const int DISPLAY_COLORS_RGB = (1 << 2);
		public const int DISPLAY_DEPTH_8 = (1 << 11);
		public const int DISPLAY_LITTLEENDIAN = (1 << 16);
        public const int DISPLAY_BIGENDIAN = (0 << 16);
	}

	class ghostapi
	{
#if MONO
    private const string lib_dll = "libgpdl.so";
#else
#if WIN64
#if !GHOSTPDL
		private const string lib_dll = "gsdll64.dll";
#else
		private const string lib_dll = "gpdldll64.dll";
#endif
#else
#if !GHOSTPDL
		private const string lib_dll = "gsdll32.dll";
#else
		private const string lib_dll = "gpdldll32.dll";
#endif
#endif
#endif
        /* Callback proto for stdio */
        public delegate int gs_stdio_handler(IntPtr caller_handle, IntPtr buffer, int len);

		/* Callback proto for poll function */
		public delegate int gsPollHandler(IntPtr caller_handle);

		/* Callout proto */
		public delegate int gsCallOut(IntPtr callout_handle, IntPtr device_name, int id, int size, IntPtr data);

		[DllImport(lib_dll, EntryPoint = "gsapi_revision", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_revision(ref gsapi_revision_t vers, int size);

		[DllImport(lib_dll, EntryPoint = "gsapi_new_instance", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_new_instance(out IntPtr pinstance,
			IntPtr caller_handle);

		[DllImport(lib_dll, EntryPoint = "gsapi_delete_instance", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern void gsapi_delete_instance(IntPtr instance);

		[DllImport(lib_dll, EntryPoint = "gsapi_set_stdio_with_handle", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_set_stdio_with_handle(IntPtr instance,
			gs_stdio_handler stdin, gs_stdio_handler stdout, gs_stdio_handler stderr, IntPtr caller_handle);

		[DllImport(lib_dll, EntryPoint = "gsapi_set_stdio", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_set_stdio(IntPtr instance,
			gs_stdio_handler stdin, gs_stdio_handler stdout, gs_stdio_handler stderr);

		[DllImport(lib_dll, EntryPoint = "gsapi_set_poll_with_handle", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_set_poll_with_handle(IntPtr instance, gsPollHandler pollfn,
			IntPtr caller_handle);

		[DllImport(lib_dll, EntryPoint = "gsapi_set_poll", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_set_poll(IntPtr instance, gsPollHandler pollfn);

		[DllImport(lib_dll, EntryPoint = "gsapi_set_display_callback", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_set_display_callback(IntPtr pinstance, IntPtr caller_handle);

		[DllImport(lib_dll, EntryPoint = "gsapi_register_callout", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_register_callout(IntPtr instance, gsCallOut callout,
			IntPtr callout_handle);

		[DllImport(lib_dll, EntryPoint = "gsapi_deregister_callout", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_deregister_callout(IntPtr instance, gsCallOut callout,
			IntPtr callout_handle);

		[DllImport(lib_dll, EntryPoint = "gsapi_set_arg_encoding", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_set_arg_encoding(IntPtr instance,
			int encoding);

		[DllImport(lib_dll, EntryPoint = "gsapi_get_default_device_list", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_get_default_device_list(IntPtr instance,
			ref IntPtr list, ref int listlen);

		[DllImport(lib_dll, EntryPoint = "gsapi_set_default_device_list", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_set_default_device_list(IntPtr instance,
			IntPtr list, ref int listlen);

		[DllImport(lib_dll, EntryPoint = "gsapi_run_string_begin", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_run_string_begin(IntPtr instance,
			int usererr, ref int exitcode);

		[DllImport(lib_dll, EntryPoint = "gsapi_run_string_continue", CharSet = CharSet.Ansi,
		CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_run_string_continue(IntPtr instance,
			IntPtr command, int count, int usererr, ref int exitcode);

		[DllImport(lib_dll, EntryPoint = "gsapi_run_string_end", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_run_string_end(IntPtr instance,
			int usererr, ref int exitcode);

		[DllImport(lib_dll, EntryPoint = "gsapi_run_string_with_length", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_run_string_with_length(IntPtr instance, IntPtr command,
			uint length, int usererr, ref int exitcode);

		[DllImport(lib_dll, EntryPoint = "gsapi_run_string", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_run_string(IntPtr instance, IntPtr command,
			int usererr, ref int exitcode);

		[DllImport(lib_dll, EntryPoint = "gsapi_run_file", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_run_file(IntPtr instance, IntPtr filename,
			int usererr, ref int exitcode);

		[DllImport(lib_dll, EntryPoint = "gsapi_init_with_args", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_init_with_args(IntPtr instance, int argc,
			IntPtr argv);

		[DllImport(lib_dll, EntryPoint = "gsapi_exit", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_exit(IntPtr instance);

		[DllImport(lib_dll, EntryPoint = "gsapi_set_param", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_set_param(IntPtr instance, IntPtr param, IntPtr value,
			gs_set_param_type type);

		[DllImport(lib_dll, EntryPoint = "gsapi_get_param", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_get_param(IntPtr instance, IntPtr param, IntPtr value,
			gs_set_param_type type);

		[DllImport(lib_dll, EntryPoint = "gsapi_enumerate_params", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_enumerate_params(IntPtr instance, out IntPtr inter,
			out IntPtr key, IntPtr type);

		[DllImport(lib_dll, EntryPoint = "gsapi_add_control_path", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_add_control_path(IntPtr instance, int type, IntPtr path);

		[DllImport(lib_dll, EntryPoint = "gsapi_remove_control_path", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_remove_control_path(IntPtr instance, int type, IntPtr path);

		[DllImport(lib_dll, EntryPoint = "gsapi_purge_control_paths", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern void gsapi_purge_control_paths(IntPtr instance, int type);

		[DllImport(lib_dll, EntryPoint = "gsapi_activate_path_control", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern void gsapi_activate_path_control(IntPtr instance, int enable);

		[DllImport(lib_dll, EntryPoint = "gsapi_is_path_control_active", CharSet = CharSet.Ansi,
			CallingConvention = CallingConvention.StdCall)]
		public static extern int gsapi_is_path_control_active(IntPtr instance);



	}
}