001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (http://www.swig.org).
003 * Version 4.0.2
004 *
005 * Do not make changes to this file unless you know what you are doing--modify
006 * the SWIG interface file instead.
007 * ----------------------------------------------------------------------------- */
008
009package com.avpkit.core;
010import com.avpkit.ferry.*;
011/**
012 * Maps from int return codes to defined Error values.<br>
013 * <p><br>
014 * This class is used to map from AVPKit return codes<br>
015 * (for example on {IContainer#readNextPacket(IPacket)}<br>
016 * into an enum type if the error is known and a text description.<br>
017 * </p><p><br>
018 * WARNING: Do not write code that depends on the integer values<br>
019 * returned from AVPKit; instead use the integer value to create<br>
020 * one of these objects.  That's because integer values returned<br>
021 * from methods can have different meanings on different OS systems<br>
022 * (for example, ERROR_AGAIN is -11 on Linux, but a different<br>
023 * value on MacOS).  This class maps the error to a os-type-safe<br>
024 * value.<br>
025 * </p><p><br>
026 * Also, do not depend on the string messages staying constant.  They<br>
027 * are for debugging purposes only.  And we can't control whether or<br>
028 * not they are localized -- that's up to your OS.  Sorry.<br>
029 * </p>
030 */
031public class IError extends RefCounted {
032  // JNIHelper.swg: Start generated code
033  // >>>>>>>>>>>>>>>>>>>>>>>>>>>
034  /**
035   * This method is only here to use some references and remove
036   * a Eclipse compiler warning.
037   */
038  @SuppressWarnings("unused")
039  private void noop()
040  {
041    IBuffer.make(null, 1);
042  }
043   
044  private volatile long swigCPtr;
045
046  /**
047   * Internal Only.
048   */
049  protected IError(long cPtr, boolean cMemoryOwn) {
050    super(AVPKitJNI.IError_SWIGUpcast(cPtr), cMemoryOwn);
051    swigCPtr = cPtr;
052  }
053  
054  /**
055   * Internal Only.
056   */
057  protected IError(long cPtr, boolean cMemoryOwn,
058      java.util.concurrent.atomic.AtomicLong ref)
059  {
060    super(AVPKitJNI.IError_SWIGUpcast(cPtr),
061     cMemoryOwn, ref);
062    swigCPtr = cPtr;
063  }
064    
065  /**
066   * Internal Only.  Not part of public API.
067   *
068   * Get the raw value of the native object that obj is proxying for.
069   *   
070   * @param obj The java proxy object for a native object.
071   * @return The raw pointer obj is proxying for.
072   */
073  public static long getCPtr(IError obj) {
074    if (obj == null) return 0;
075    return obj.getMyCPtr();
076  }
077
078  /**
079   * Internal Only.  Not part of public API.
080   *
081   * Get the raw value of the native object that we're proxying for.
082   *   
083   * @return The raw pointer we're proxying for.
084   */  
085  public long getMyCPtr() {
086    if (swigCPtr == 0) throw new IllegalStateException("underlying native object already deleted");
087    return swigCPtr;
088  }
089  
090  /**
091   * Create a new IError object that is actually referring to the
092   * exact same underlying native object.
093   *
094   * @return the new Java object.
095   */
096  @Override
097  public IError copyReference() {
098    if (swigCPtr == 0)
099      return null;
100    else
101      return new IError(swigCPtr, swigCMemOwn, getJavaRefCount());
102  }
103
104  /**
105   * Compares two values, returning true if the underlying objects in native code are the same object.
106   *
107   * That means you can have two different Java objects, but when you do a comparison, you'll find out
108   * they are the EXACT same object.
109   *
110   * @return True if the underlying native object is the same.  False otherwise.
111   */
112  public boolean equals(Object obj) {
113    boolean equal = false;
114    if (obj instanceof IError)
115      equal = (((IError)obj).swigCPtr == this.swigCPtr);
116    return equal;
117  }
118  
119  /**
120   * Get a hashable value for this object.
121   *
122   * @return the hashable value.
123   */
124  public int hashCode() {
125     return (int)swigCPtr;
126  }
127  
128  // <<<<<<<<<<<<<<<<<<<<<<<<<<<
129  // JNIHelper.swg: End generated code
130  
131
132  /**
133   * Return a string representation of this error
134   * 
135   * @return the error as a string
136   */
137  public String toString()
138  {
139    return getDescription();
140  }
141
142  /**
143   * Get the OS-independent AVPKit type for this error.<br>
144   * <br>
145   * @return the type.
146   */
147  public IError.Type getType() {
148    return IError.Type.swigToEnum(AVPKitJNI.IError_getType(swigCPtr, this));
149  }
150
151  /**
152   * Get a text description for this error.<br>
153   * <br>
154   * The description returned will be in whatever language<br>
155   * the underlying OS decides to use, and no, we can't<br>
156   * support localization here if the OS hasn't already done it.<br>
157   * <br>
158   * Sorry.<br>
159   * <br>
160   * @return the description.
161   */
162  public String getDescription() {
163    return AVPKitJNI.IError_getDescription(swigCPtr, this);
164  }
165
166  /**
167   * Return the raw integer value that AVPKit returned and<br>
168   * was used to create this IError.<br>
169   * <br>
170   * Note that this value can have different meanings on<br>
171   * different operating systems.  Use {#getType()}<br>
172   * instead for programmatic decisions.<br>
173   * <br>
174   * @return the native error number.
175   */
176  public int getErrorNumber() {
177    return AVPKitJNI.IError_getErrorNumber(swigCPtr, this);
178  }
179
180  /**
181   * Create a new IError object from a return value passed in from AVPKit.<br>
182   * <br>
183   * @param errorNumber The error number as returned from another<br>
184   *   AVPKit call.  ErrorNumber must be &lt; 0.<br>
185   * @return a new IError, or null on error.
186   */
187  public static IError make(int errorNumber) {
188    long cPtr = AVPKitJNI.IError_make__SWIG_0(errorNumber);
189    return (cPtr == 0) ? null : new IError(cPtr, false);
190  }
191
192  /**
193   * Create a new IError object from an IError.Type enum value.<br>
194   * <br>
195   * @param type The type to use for creation.<br>
196   * @return a new IError, or null on error.
197   */
198  public static IError make(IError.Type type) {
199    long cPtr = AVPKitJNI.IError_make__SWIG_1(type.swigValue());
200    return (cPtr == 0) ? null : new IError(cPtr, false);
201  }
202
203  /**
204   * Translate an error number to a type.<br>
205   * @param errorNo The error returned from AVPKit<br>
206   * @return the type
207   */
208  public static IError.Type errorNumberToType(int errorNo) {
209    return IError.Type.swigToEnum(AVPKitJNI.IError_errorNumberToType(errorNo));
210  }
211
212  /**
213   * Translate an a type to an error number.<br>
214   * @param type The type<br>
215   * @return the error number
216   */
217  public static int typeToErrorNumber(IError.Type type) {
218    return AVPKitJNI.IError_typeToErrorNumber(type.swigValue());
219  }
220
221  /**
222   * A set of errors that AVPKit knows about.
223   */
224  public enum Type {
225    ERROR_UNKNOWN,
226    ERROR_IO,
227    ERROR_NUMEXPECTED,
228    ERROR_INVALIDDATA,
229    ERROR_NOMEM,
230    ERROR_NOFMT,
231    ERROR_NOTSUPPORTED,
232    ERROR_NOENT,
233    ERROR_EOF,
234    ERROR_RANGE,
235    ERROR_AGAIN,
236    ERROR_PATCHWELCOME,
237    ERROR_INTERRUPTED;
238
239    public final int swigValue() {
240      return swigValue;
241    }
242
243    public static Type swigToEnum(int swigValue) {
244      Type[] swigValues = Type.class.getEnumConstants();
245      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
246        return swigValues[swigValue];
247      for (Type swigEnum : swigValues)
248        if (swigEnum.swigValue == swigValue)
249          return swigEnum;
250      throw new IllegalArgumentException("No enum " + Type.class + " with value " + swigValue);
251    }
252
253    @SuppressWarnings("unused")
254    private Type() {
255      this.swigValue = SwigNext.next++;
256    }
257
258    @SuppressWarnings("unused")
259    private Type(int swigValue) {
260      this.swigValue = swigValue;
261      SwigNext.next = swigValue+1;
262    }
263
264    @SuppressWarnings("unused")
265    private Type(Type swigEnum) {
266      this.swigValue = swigEnum.swigValue;
267      SwigNext.next = this.swigValue+1;
268    }
269
270    private final int swigValue;
271
272    private static class SwigNext {
273      private static int next = 0;
274    }
275  }
276
277}