summaryrefslogtreecommitdiffstats
path: root/core/java/android/speech/recognition/impl/LoggerImpl.java
blob: 9933c56b9be98a454b487b88f9def189ba68ac35 (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
/*---------------------------------------------------------------------------*
 *  LoggerImpl.java                                                          *
 *                                                                           *
 *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
 *                                                                           *
 *  Licensed under the Apache License, Version 2.0 (the 'License');          *
 *  you may not use this file except in compliance with the License.         *
 *                                                                           *
 *  You may obtain a copy of the License at                                  *
 *      http://www.apache.org/licenses/LICENSE-2.0                           *
 *                                                                           *
 *  Unless required by applicable law or agreed to in writing, software      *
 *  distributed under the License is distributed on an 'AS IS' BASIS,        *
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
 *  See the License for the specific language governing permissions and      *
 *  limitations under the License.                                           *
 *                                                                           *
 *---------------------------------------------------------------------------*/

package android.speech.recognition.impl;

import android.speech.recognition.Logger;

/**
 */
public class LoggerImpl extends Logger implements Runnable
{
  private static LoggerImpl instance;
  /**
   * Reference to the native object.
   */
  private long nativeObject;

  /**
   * Creates a new instance of LoggerImpl.
   *
   * @param function the name of the enclosing function
   */
  private LoggerImpl()
  {
    System system = System.getInstance();
    nativeObject = initNativeObject();
    if (nativeObject!=0)
         system.register(this);
  }

  public void run()
  {
    dispose();
  }

  /**
   * Returns the singleton instance.
   *
   * @return the singleton instance
   */
  public static LoggerImpl getInstance()
  {
    synchronized (LoggerImpl.class)
    {
        if (instance == null)
            instance = new LoggerImpl();
        return instance;
    }
  }

  public void setLoggingLevel(LogLevel level)
  {
    synchronized (LoggerImpl.class)
    {
        if (nativeObject == 0)
            throw new IllegalStateException("Object has been disposed");
        setLoggingLevelProxy(nativeObject,level);
    }
  }

  public void setPath(String path)
  {
    synchronized (LoggerImpl.class)
    {
        if (nativeObject == 0)
            throw new IllegalStateException("Object has been disposed");
        setPathProxy(nativeObject,path);
    }
  }

  public void error(String message)
  {
    synchronized (LoggerImpl.class)
    {
        if (nativeObject == 0)
            throw new IllegalStateException("Object has been disposed");
        errorProxy(nativeObject,message);
    }
  }

  public void warn(String message)
  {
    synchronized (LoggerImpl.class)
    {
        if (nativeObject == 0)
          throw new IllegalStateException("Object has been disposed");
        warnProxy(nativeObject,message);
    }
  }

  public  void info(String message)
  {
    synchronized (LoggerImpl.class)
    {
        if (nativeObject == 0)
            throw new IllegalStateException("Object has been disposed");
        infoProxy(nativeObject,message);
    }
  }

  public void trace(String message)
  {
     synchronized (LoggerImpl.class)
     {
        if (nativeObject == 0)
            throw new IllegalStateException("Object has been disposed");
        traceProxy(nativeObject,message);
     }
  }

  /**
   * Releases the native resources associated with the object.
   */
  private void dispose()
  {
    synchronized (LoggerImpl.class)
    {
        if (nativeObject!=0) 
        {
            deleteNativeObject(nativeObject);
            System.getInstance().unregister(this);
        }
        nativeObject = 0;
        instance = null;
    }
  }
 
  @Override
  protected void finalize() throws Throwable
  {
    dispose();
    super.finalize();
  }

  private native long initNativeObject();

  private native void setLoggingLevelProxy(long nativeObject, LogLevel level);

  private native void setPathProxy(long nativeObject, String filename);

  private native void errorProxy(long nativeObject, String message);

  private native void warnProxy(long nativeObject, String message);

  private native void infoProxy(long nativeObject, String message);

  private native void traceProxy(long nativeObject,String message);

  private native void deleteNativeObject(long nativeObject);
}