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
|
/*
* ErrorCodes.cs
*
* Author(s):
* Ewen Cheslack-Postava <echeslack@gmail.com>
* Larry Ewing <lewing@novell.com>
* Stephane Delcroix <stephane@delcroix.org>
*
* Copyright (c) 2005-2009 Novel, Inc.
*
* This is open source software. See COPYING for details.
*/
using System;
using System.Runtime.InteropServices;
namespace GPhoto2
{
public enum ErrorCode
{
/* IO Errors */
GeneralError = -1,
BadParameters = -2,
NoMemory = -3,
Library = -4,
UnknownPort = -5,
NotSupported = -6,
IO = -7,
FixedLimitExceeded = -8,
Timout = -10,
SupportedSerial = -20,
SupportedUSB = -21,
Init = -31,
Read = -34,
Write = -35,
Update = -37,
SerialSpeed = -41,
USBClearHalt = -51,
USBFind = -52,
USBClaim = -53,
Lock = -60,
Hal = -70,
/* Other Errors*/
CorruptedData = -102,
FileExists = -103,
ModelNotFound = -105,
DirectoryNotFound = -107,
FileNotFound = -108,
DirectoryExists = -109,
CameraBusy = -110,
PathNotAbsolute = -111,
Cancel = -112,
CameraError = -113,
OsFailure = -114,
}
public static class Error
{
public static bool IsError (ErrorCode error_code)
{
return (error_code < 0);
}
public static int CheckError (ErrorCode error)
{
if (IsError (error)) {
string message = "Unknown Error";
if ((int)error <= -100)
message = GetErrorAsString (error);
else if ((int)error <= -1 && (int)error >= -99)
message = GetIOErrorAsString (error);
throw new GPhotoException (error, message);
}
return (int)error;
}
[DllImport ("libgphoto2.so")]
internal static extern IntPtr gp_result_as_string (ErrorCode result);
static string GetErrorAsString (ErrorCode e)
{
IntPtr raw_message = gp_result_as_string(e);
return Marshal.PtrToStringAnsi(raw_message);
}
[DllImport ("libgphoto2_port.so")]
internal static extern IntPtr gp_port_result_as_string (ErrorCode result);
static string GetIOErrorAsString(ErrorCode e)
{
IntPtr raw_message = gp_port_result_as_string(e);
return Marshal.PtrToStringAnsi(raw_message);
}
}
public class GPhotoException : Exception
{
private ErrorCode error;
public GPhotoException(ErrorCode error_code) : base ("Unknown Error.")
{
error = error_code;
}
public GPhotoException (ErrorCode error_code, string message) : base (message)
{
error = error_code;
}
public override string ToString()
{
return ("Error " + error.ToString() + ": " + base.ToString());
}
public ErrorCode Error {
get { return error; }
}
}
}
|