PPCSystemAPI.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *
00024  */
00025 
00026 package org.openmobileis.embedded.util;
00027 
00028 import org.openmobileis.common.util.exception.OpenMISException;
00029 import org.openmobileis.common.util.log.LogManager;
00030 
00039 public class PPCSystemAPI implements ISystemAPI{
00040 
00041         static  {
00042                 try {
00043                         System.loadLibrary("ppcsystemapi");
00044                 } catch (Throwable exi) {
00045                         exi.printStackTrace();
00046                         LogManager.traceError(0, exi);
00047                 }
00048         }
00049         // Define the root register key in long format for the native method
00050         public static final long HKEY_CLASSES_ROOT = 0x80000000;
00051         public static final long HKEY_CURRENT_USER = 0x80000001;
00052         public static final long HKEY_LOCAL_MACHINE = 0x80000002;
00053 
00059   public native int execProgramAndWait(String path, String args) throws OpenMISException;
00060 
00066   public native int execProgram (String path, String args) throws OpenMISException;
00067   
00072   public native String getSystemUniqueID();
00073   
00074   // Get the type of the registry
00075   private native Long NativeReadPPCRegistryType(long hkey,String regkey,String entity);
00076   // Return value in string format
00077   private native String NativeReadPPCRegistryString(long hkey,String regkey,String entity);
00078   // Return value in a hide "long" format
00079   private native String NativeReadPPCRegistryLong(long hkey,String regkey,String entity);
00080   // Return value in byte format
00081   private native Byte NativeReadPPCRegistryBin(long hkey,String regkey,String entity);
00082   // Return value in array-string format
00083   private native String NativeReadPPCRegistryMultiString(long hkey,String regkey,String entity);
00084 
00085   // Method to get value type
00086   public  Long readPPCRegistryType(long hkey,String regkey,String entity)       {
00087           Long nativetype = NativeReadPPCRegistryType(hkey,regkey,entity);
00088           return nativetype;
00089   }
00090   
00091   public  String readPPCRegistryMultiString(long hkey,String regkey,String entity)      {
00092           String nativetype = NativeReadPPCRegistryMultiString(hkey,regkey,entity);
00093           return nativetype;
00094   }
00095   
00096   
00097   // Method to get value string
00098   public  String readPPCRegistryString(long hkey,String regkey,String entity)   {
00099           String nativetype = NativeReadPPCRegistryString(hkey,regkey,entity);
00100           return nativetype;
00101   }
00102   
00103   // Method to get value long
00104   public  long readPPCRegistryLong(long hkey,String regkey,String entity)       {
00105           String nativetype = NativeReadPPCRegistryLong(hkey,regkey,entity);
00106           char chartemp1 = nativetype.charAt(0);
00107           char chartemp2 = nativetype.charAt(1);
00108           int i1 = + chartemp1;
00109           int i2 = + chartemp2;
00110           long i3 = (i2 & 0xffffffffL)*65536;           // Avoid the signed value
00111           long i4 = i1 + i3;
00112           return i4;
00113   }
00114   
00115   // Method to get value byte
00116   public Byte readPPCRegistryBin(long hkey,String regkey,String entity) {
00117           Byte nativetype = NativeReadPPCRegistryBin(hkey,regkey,entity);
00118           return nativetype;
00119   }
00120    /***
00121    * Main method to get registry key value
00122    * Ex : readPPCRegistryValue("HKEY_LOCAL_MACHINE","Time","TimeZoneInformation")
00123    */
00124   public String readPPCRegistryValue (String register,String regkey,String entity){
00125           String valuestring=null;
00126           long valuelong;
00127           Byte valuebyte;
00128           long hkey = 0;
00129           if(register.startsWith("HKEY_CLASSES")){
00130                   hkey = HKEY_CLASSES_ROOT;
00131           }if(register.startsWith("HKEY_LOCAL")){
00132                   hkey = HKEY_LOCAL_MACHINE;
00133           }if(register.startsWith("HKEY_CURRENT")){
00134                   hkey = HKEY_CURRENT_USER;
00135           };
00136           Long type = readPPCRegistryType(hkey, regkey, entity);
00137           //Depend on the return type of readed regkey
00138           //for "String - REG_SZ"
00139           if((type.intValue()==1)||(type.intValue()==7)){
00140                   valuestring = readPPCRegistryString(hkey, regkey, entity);
00141           }
00142           //for "Long - REG_DWORD"
00143           if(type.intValue()==4){
00144                   valuelong = readPPCRegistryLong(hkey, regkey, entity);
00145                   valuestring =String.valueOf(valuelong);
00146           }
00147           //for "Bin - REG_BINARY"
00148           if(type.intValue()==3){
00149                   int temp=0;
00150                   valuebyte=readPPCRegistryBin(hkey, regkey, entity);
00151                   valuestring = valuebyte.toString();  
00152                   StringBuffer buf;
00153                   buf = new StringBuffer();
00154                   for (int pos = 0; temp<((valuestring.length()/6)/2); pos+=6) 
00155                   {                     
00156                         temp++;  
00157                         String substring = valuestring.substring(pos, pos+2);
00158                         char c = (char) Integer.parseInt(substring, 16);
00159                         buf.append(c);
00160                            
00161                   }             
00162                   valuestring = buf.toString();
00163           }
00164       return valuestring;
00165   }
00166   
00167   
00172   public long currentTimeInMillis() {
00173           return System.currentTimeMillis();
00174   }
00175 }

Generated on Mon Jan 11 21:19:16 2010 for OpenMobileIS by  doxygen 1.5.4