blob: eaeb40164e898f5ca6141a9ee7aefa9393149a5d [file] [log] [blame]
Jason Sams36e612a2009-07-31 16:26:13 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.renderscript;
18
19import android.util.Log;
20
21/**
22 * @hide
23 *
24 **/
25class BaseObj {
26
27 BaseObj(RenderScript rs) {
28 mRS = rs;
29 mID = 0;
Jason Sams1bada8c2009-08-09 17:01:55 -070030 mDestroyed = false;
Jason Sams36e612a2009-07-31 16:26:13 -070031 }
32
33 public int getID() {
34 return mID;
35 }
36
37 int mID;
Jason Sams1bada8c2009-08-09 17:01:55 -070038 boolean mDestroyed;
Jason Sams36e612a2009-07-31 16:26:13 -070039 String mName;
40 RenderScript mRS;
41
42 public void setName(String s) throws IllegalStateException, IllegalArgumentException
43 {
44 if(s.length() < 1) {
45 throw new IllegalArgumentException("setName does not accept a zero length string.");
46 }
47 if(mName != null) {
48 throw new IllegalArgumentException("setName object already has a name.");
49 }
50
51 try {
52 byte[] bytes = s.getBytes("UTF-8");
53 mRS.nAssignName(mID, bytes);
54 mName = s;
55 } catch (java.io.UnsupportedEncodingException e) {
56 throw new RuntimeException(e);
57 }
58 }
59
60 protected void finalize() throws Throwable
61 {
Jason Sams1bada8c2009-08-09 17:01:55 -070062 if (!mDestroyed) {
Jason Sams36e612a2009-07-31 16:26:13 -070063 Log.v(RenderScript.LOG_TAG,
Jason Sams7ce033d2009-08-18 14:14:24 -070064 getClass() + " finalized without having released the RS reference.");
Jason Sams36e612a2009-07-31 16:26:13 -070065 }
66 super.finalize();
67 }
Jason Sams7ce033d2009-08-18 14:14:24 -070068
69 public void destroy() {
70 if(mDestroyed) {
71 throw new IllegalStateException("Object already destroyed.");
72 }
73 mDestroyed = true;
74 mRS.nObjDestroy(mID);
75 }
76
Jason Sams36e612a2009-07-31 16:26:13 -070077}
78