@@ -67,6 +67,61 @@ public IIOException(string fmt, int err)
67
67
}
68
68
}
69
69
70
+ /// <summary>
71
+ /// Represents the log levels for IIO.
72
+ /// </summary>
73
+ public enum IioLogLevel
74
+ {
75
+ NoLog = 1 ,
76
+ Error = 2 ,
77
+ Warning = 3 ,
78
+ Info = 4 ,
79
+ Debug = 5
80
+ }
81
+
82
+ /// <summary>
83
+ /// Represents the parameters for creating an IIO context.
84
+ /// </summary>
85
+ [ StructLayout ( LayoutKind . Sequential ) ]
86
+ public struct IioContextParams
87
+ {
88
+ /// <summary>
89
+ /// Handle to the standard output. If null, defaults to stdout.
90
+ /// </summary>
91
+ public IntPtr Out ;
92
+
93
+ /// <summary>
94
+ /// Handle to the error output. If null, defaults to stderr.
95
+ /// </summary>
96
+ public IntPtr Err ;
97
+
98
+ /// <summary>
99
+ /// Log level to use. Defaults to the log level specified at compilation.
100
+ /// </summary>
101
+ public IioLogLevel LogLevel ;
102
+
103
+ /// <summary>
104
+ /// Log level threshold for sending messages to stderr.
105
+ /// </summary>
106
+ public IioLogLevel StderrLevel ;
107
+
108
+ /// <summary>
109
+ /// Log level threshold for including timestamps in messages.
110
+ /// </summary>
111
+ public IioLogLevel TimestampLevel ;
112
+
113
+ /// <summary>
114
+ /// Timeout for I/O operations in milliseconds. If zero, the default timeout is used.
115
+ /// </summary>
116
+ public uint TimeoutMs ;
117
+
118
+ /// <summary>
119
+ /// Reserved for future fields. Must remain unused.
120
+ /// </summary>
121
+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = 32 ) ]
122
+ public byte [ ] Reserved ;
123
+ }
124
+
70
125
public abstract class IIOObject : IDisposable
71
126
{
72
127
internal IntPtr hdl ;
@@ -121,13 +176,13 @@ public static class IioLib
121
176
122
177
[ DllImport ( IioLib . dllname , CallingConvention = CallingConvention . Cdecl ) ]
123
178
[ return : MarshalAs ( UnmanagedType . I1 ) ]
124
- private static extern bool iio_has_backend ( [ In ( ) ] string backend ) ;
179
+ private static extern bool iio_has_backend ( IntPtr ctx_params , [ In ( ) ] string backend ) ;
125
180
126
181
[ DllImport ( IioLib . dllname , CallingConvention = CallingConvention . Cdecl ) ]
127
- private static extern int iio_get_backends_count ( ) ;
182
+ private static extern int iio_get_builtin_backends_count ( ) ;
128
183
129
184
[ DllImport ( IioLib . dllname , CallingConvention = CallingConvention . Cdecl ) ]
130
- private static extern IntPtr iio_get_backend ( uint index ) ;
185
+ private static extern IntPtr iio_get_builtin_backend ( uint index ) ;
131
186
132
187
/// <summary>Get a description of a negative error code.</summary>
133
188
/// <param name="err">Negative error code.</param>
@@ -150,19 +205,44 @@ public static bool has_backend(string backend)
150
205
if ( backend == null )
151
206
throw new IIOException ( "The backend string should not be null!" ) ;
152
207
153
- return iio_has_backend ( backend ) ;
208
+ return iio_has_backend ( IntPtr . Zero , backend ) ;
209
+ }
210
+
211
+ /// <summary>Checks if the given backend is available or not.</summary>
212
+ /// <param name="ctx_params">Context parameters.</param>
213
+ /// <param name="backend">The backend's name.</param>
214
+ public static bool has_backend ( IioContextParams ctx_params , string backend )
215
+ {
216
+ if ( backend == null )
217
+ throw new IIOException ( "The backend string should not be null!" ) ;
218
+
219
+ // Allocate unmanaged memory for the structure
220
+ IntPtr contextParamsPtr = Marshal . AllocHGlobal ( Marshal . SizeOf < IioContextParams > ( ) ) ;
221
+ try
222
+ {
223
+ // Copy the managed structure to unmanaged memory
224
+ Marshal . StructureToPtr ( ctx_params , contextParamsPtr , false ) ;
225
+
226
+ // Call the native function
227
+ return iio_has_backend ( contextParamsPtr , backend ) ;
228
+ }
229
+ finally
230
+ {
231
+ // Free the unmanaged memory
232
+ Marshal . FreeHGlobal ( contextParamsPtr ) ;
233
+ }
154
234
}
155
235
156
- /// <summary>Gets the total number of available backends.</summary>
157
- public static int get_backends_count ( )
236
+ /// <summary>Gets the total number of available builtin backends.</summary>
237
+ public static int get_builtin_backends_count ( )
158
238
{
159
- return iio_get_backends_count ( ) ;
239
+ return iio_get_builtin_backends_count ( ) ;
160
240
}
161
241
162
- /// <summary>Gets the backend from the given index.</summary>
163
- public static string get_backend ( uint index )
242
+ /// <summary>Gets the builtin backend from the given index.</summary>
243
+ public static string get_builtin_backend ( uint index )
164
244
{
165
- return Marshal . PtrToStringAnsi ( iio_get_backend ( index ) ) ;
245
+ return Marshal . PtrToStringAnsi ( iio_get_builtin_backend ( index ) ) ;
166
246
}
167
247
}
168
248
}
0 commit comments