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.ferry;
010
011/**
012 * Internal Only<br>
013 * <p><br>
014 * C++ wrapper to SLF4J Java Logging frame work.<br>
015 * </p><br>
016 * <p><br>
017 * If not running inside a JVM, then this class<br>
018 * just does a rudimentary printout of log messages<br>
019 * to stderr.<br>
020 * </p><br>
021 * <p><br>
022 * Otherwise, it forwards to Java's SLF4J logging framework.<br>
023 * </p>
024 */
025public class Logger {
026  // JNIHelper.swg: Start generated code
027  // >>>>>>>>>>>>>>>>>>>>>>>>>>>
028
029  private volatile long swigCPtr;
030  /**
031   * Internal Only.
032   */
033  protected boolean swigCMemOwn;
034  @SuppressWarnings("unused")
035  private JNINativeFinalizer mUnusedVariableToAllowImports;
036  
037  /**
038   * Internal Only.  
039   * 
040   * DO NOT USE: Do not allocate this method using new.  Not part of public API.
041   * <p>
042   * Unfortunately this constructor is public because the internal
043   * implementation needs it to be, but do not pass in values to this method
044   * as you may end up crashing the virtual machine.
045   * </p>
046   *
047   * @param cPtr A C pointer to direct memory; did we mention don't call this.
048   * @param cMemoryOwn I'm not even going to tell you.  Stop it.  Go away.
049   *
050   */ 
051  protected Logger(long cPtr, boolean cMemoryOwn) {
052    swigCPtr = cPtr;
053    swigCMemOwn = cMemoryOwn;
054  }
055
056  /**
057   * Internal Only.  Not part of public API.
058   *
059   * Get the raw value of the native object that obj is proxying for.
060   *   
061   * @param obj The java proxy object for a native object.
062   * @return The raw pointer obj is proxying for.
063   */
064  public static long getCPtr(Logger obj) {
065    if (obj == null) return 0;
066    return obj.getMyCPtr();
067  }
068  
069  /**
070   * Internal Only.  Not part of public API.
071   *
072   * Get the raw value of the native object that we're proxying for.
073   *   
074   * @return The raw pointer we're proxying for.
075   */  
076  public long getMyCPtr() {
077    if (swigCPtr == 0) throw new IllegalStateException("underlying native object already deleted");
078    return swigCPtr;
079  }
080
081  /**
082   * Compares two values, returning true if the underlying objects in native code are the same object.
083   *
084   * That means you can have two different Java objects, but when you do a comparison, you'll find out
085   * they are the EXACT same object.
086   *
087   * @return True if the underlying native object is the same.  False otherwise.
088   */
089  public boolean equals(Object obj) {
090    boolean equal = false;
091    if (obj instanceof Logger)
092      equal = (((Logger)obj).swigCPtr == this.swigCPtr);
093    return equal;
094  }
095  
096  /**
097   * Get a hashable value for this object.
098   *
099   * @return the hashable value.
100   */
101  public int hashCode() {
102     return (int)swigCPtr;
103  }
104  
105  /**
106   * Internal Only.  Finalize this object.  Note this should only exists on non RefCounted objects.
107   */
108  protected void finalize()
109  {
110    delete();
111  }
112
113  // <<<<<<<<<<<<<<<<<<<<<<<<<<<
114  // JNIHelper.swg: End generated code
115  /**
116   * Releases any underlying native memory and marks this object
117   * as invalid.
118   * <p>
119   * Normally Ferry manages when to release native memory.
120   * </p>
121   * <p>
122   * In the unlikely event you want to control EXACTLY when a native 
123   * object is released, each AVPKit object has a {@link #delete()}
124   * method that you can use. Once you call {@link #delete()},
125   * you must ENSURE your object is never referenced again from
126   * that Java object -- Ferry tries to help you avoid crashes if you
127   * accidentally use an object after deletion but on this but we
128   * cannot offer 100% protection (specifically if another thread
129   *  is accessing that object EXACTLY when you {@link #delete()} it). 
130   * </p>
131   */
132  
133
134  public synchronized void delete() {
135    if (swigCPtr != 0) {
136      if (swigCMemOwn) {
137        swigCMemOwn = false;
138        FerryJNI.delete_Logger(swigCPtr);
139      }
140      swigCPtr = 0;
141    }
142  }
143
144  /**
145   * Returns a new Logger object for this loggerName.<br>
146   * <br>
147   * @param aLoggerName A name (no spaces allowed) for this logger.<br>
148   * <br>
149   * @return a New logger for logging; caller must delete when done.
150   */
151  public static Logger getLogger(String aLoggerName) {
152    long cPtr = FerryJNI.Logger_getLogger(aLoggerName);
153    return (cPtr == 0) ? null : new Logger(cPtr, false);
154  }
155
156  /**
157   * Get a Logger object, but ask the Logger code to<br>
158   * free it up once the JavaVM shuts down.  Use at your<br>
159   * own risk.<br>
160   * <br>
161   * @param aLoggerName A name (no spaces allowed) for this logger.<br>
162   * <br>
163   * @return A new logger for logging; caller must not call delete<br>
164   *  and must not use the logger once the JavaVM (or main) has exited.
165   */
166  public static Logger getStaticLogger(String aLoggerName) {
167    long cPtr = FerryJNI.Logger_getStaticLogger(aLoggerName);
168    return (cPtr == 0) ? null : new Logger(cPtr, false);
169  }
170
171  /**
172   * Log the message to the logger, using sprintf() format<br>
173   * strings.<br>
174   * <br>
175   * @param filename The filename that is logging, or NULL.<br>
176   * @param lineNo The line number where this log statement is executed from.<br>
177   *  or 0.<br>
178   * @param level Level to log at.<br>
179   * @param format    A format specification string, in sprintf format.<br>
180   * @return if the message was actually logged.
181   */
182  public boolean log(String filename, int lineNo, Logger.Level level, String format) {
183    return FerryJNI.Logger_log(swigCPtr, this, filename, lineNo, level.swigValue(), format);
184  }
185
186  public boolean error(String filename, int lineNo, String format) {
187    return FerryJNI.Logger_error(swigCPtr, this, filename, lineNo, format);
188  }
189
190  public boolean warn(String filename, int lineNo, String format) {
191    return FerryJNI.Logger_warn(swigCPtr, this, filename, lineNo, format);
192  }
193
194  public boolean info(String filename, int lineNo, String format) {
195    return FerryJNI.Logger_info(swigCPtr, this, filename, lineNo, format);
196  }
197
198  public boolean debug(String filename, int lineNo, String format) {
199    return FerryJNI.Logger_debug(swigCPtr, this, filename, lineNo, format);
200  }
201
202  public boolean trace(String filename, int lineNo, String format) {
203    return FerryJNI.Logger_trace(swigCPtr, this, filename, lineNo, format);
204  }
205
206  public boolean isLogging(Logger.Level level) {
207    return FerryJNI.Logger_isLogging(swigCPtr, this, level.swigValue());
208  }
209
210  public void setIsLogging(Logger.Level level, boolean value) {
211    FerryJNI.Logger_setIsLogging(swigCPtr, this, level.swigValue(), value);
212  }
213
214  public static boolean isGlobalLogging(Logger.Level level) {
215    return FerryJNI.Logger_isGlobalLogging(level.swigValue());
216  }
217
218  public static void setGlobalIsLogging(Logger.Level level, boolean value) {
219    FerryJNI.Logger_setGlobalIsLogging(level.swigValue(), value);
220  }
221
222  public String getName() {
223    return FerryJNI.Logger_getName(swigCPtr, this);
224  }
225
226  /**
227   * Different logging levels (noiseness) supported by us.
228   */
229  public enum Level {
230    LEVEL_ERROR(FerryJNI.Logger_LEVEL_ERROR_get()),
231    LEVEL_WARN(FerryJNI.Logger_LEVEL_WARN_get()),
232    LEVEL_INFO(FerryJNI.Logger_LEVEL_INFO_get()),
233    LEVEL_DEBUG(FerryJNI.Logger_LEVEL_DEBUG_get()),
234    LEVEL_TRACE(FerryJNI.Logger_LEVEL_TRACE_get());
235
236    public final int swigValue() {
237      return swigValue;
238    }
239
240    public static Level swigToEnum(int swigValue) {
241      Level[] swigValues = Level.class.getEnumConstants();
242      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
243        return swigValues[swigValue];
244      for (Level swigEnum : swigValues)
245        if (swigEnum.swigValue == swigValue)
246          return swigEnum;
247      throw new IllegalArgumentException("No enum " + Level.class + " with value " + swigValue);
248    }
249
250    @SuppressWarnings("unused")
251    private Level() {
252      this.swigValue = SwigNext.next++;
253    }
254
255    @SuppressWarnings("unused")
256    private Level(int swigValue) {
257      this.swigValue = swigValue;
258      SwigNext.next = swigValue+1;
259    }
260
261    @SuppressWarnings("unused")
262    private Level(Level swigEnum) {
263      this.swigValue = swigEnum.swigValue;
264      SwigNext.next = this.swigValue+1;
265    }
266
267    private final int swigValue;
268
269    private static class SwigNext {
270      private static int next = 0;
271    }
272  }
273
274}