javaextensions/iapinfo/javasrc.s60/com/nokia/mid/iapinfo/IAPInfoImpl.java
branchRCL_3
changeset 71 d5e927d5853b
parent 66 2455ef1f5bbc
equal deleted inserted replaced
66:2455ef1f5bbc 71:d5e927d5853b
    33  * Implementation class of the APNInfo interface
    33  * Implementation class of the APNInfo interface
    34  */
    34  */
    35 class IAPInfoImpl extends IAPInfo
    35 class IAPInfoImpl extends IAPInfo
    36 {
    36 {
    37 
    37 
    38     // variable to store the network preferences
    38     private int iSessionHandle;
    39     private IAPTable iIAPTable = null;
       
    40 
       
    41     static
    39     static
    42     {
    40     {
    43         try
    41         try
    44         {
    42         {
    45             Logger.ILOG(Logger.ESOCKET, "loading javaiapinfo");
    43             Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "loading javaiapinfo");
    46             Jvm.loadSystemLibrary("javaiapinfo");
    44             Jvm.loadSystemLibrary("javaiapinfo");
    47             Logger.ILOG(Logger.ESOCKET, "javaiapinfo loaded");
    45             Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "javaiapinfo loaded");
    48         }
    46         }
    49         catch (Exception e)
    47         catch (Exception e)
    50         {
    48         {
    51             Logger.ELOG(Logger.ESOCKET, e.toString());
    49             Logger.ELOG(Logger.ESOCKET, e.toString());
    52         }
    50         }
    55     /**
    53     /**
    56      * Default constructor. Creates a new IAPInfoImpl object.
    54      * Default constructor. Creates a new IAPInfoImpl object.
    57      */
    55      */
    58     public IAPInfoImpl() throws IAPInfoException
    56     public IAPInfoImpl() throws IAPInfoException
    59     {
    57     {
    60         try
    58         iSessionHandle = _createSession();
    61         {
    59         if (iSessionHandle <0)
    62             this.iIAPTable = new IAPTable();
    60             throw new IAPInfoException("Error: symbian os error: "+iSessionHandle);
       
    61 
       
    62     }
       
    63 
       
    64     /**
       
    65      * Please refer IapInfo Spec.
       
    66      */
       
    67     public synchronized AccessPoint[] getAccessPoints() throws IAPInfoException
       
    68     {
       
    69         IAPTable iIAPTable = null;
       
    70         Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "+getAccessPoints()  - this = "+Thread.currentThread().toString() +"hascode= " +Thread.currentThread().hashCode());
       
    71         try
       
    72         {
       
    73             iIAPTable = new IAPTable();
    63         }
    74         }
    64         catch (CommDBException e)
    75         catch (CommDBException e)
    65         {
    76         {
    66             e.printStackTrace();
    77             e.printStackTrace();
    67             throw new IAPInfoException(e.getMessage());
    78             throw new IAPInfoException(e.getMessage());
    68         }
    79         }
    69     }
       
    70 
       
    71     /**
       
    72      * Please refer IapInfo Spec.
       
    73      */
       
    74     public AccessPoint[] getAccessPoints() throws IAPInfoException
       
    75     {
       
    76         AccessPoint[] _ac = null;
    80         AccessPoint[] _ac = null;
    77         try
    81         try
    78         {
    82         {
    79             this.iIAPTable.open();
    83             iIAPTable.open(iSessionHandle);
    80             int _nr_of_access_points = this.iIAPTable.getRecordCount();
    84             int _nr_of_access_points = iIAPTable.getRecordCount();
    81             _ac = new AccessPoint[_nr_of_access_points];
    85             _ac = new AccessPoint[_nr_of_access_points];
    82             for (int i = 0; i < _nr_of_access_points; i++)
    86             for (int i = 0; i < _nr_of_access_points; i++)
    83             {
    87             {
    84                 AccessPoint _c = new AccessPoint(this.iIAPTable.iRecordId,
    88                 AccessPoint _c = new AccessPoint(iIAPTable.iRecordId,
    85                                                  this.iIAPTable.iRecordName, this.iIAPTable.iBearerType,
    89                                                  iIAPTable.iRecordName, iIAPTable.iBearerType,
    86                                                  this.iIAPTable.iServiceType);
    90                                                  iIAPTable.iServiceType);
    87                 _ac[i] = _c;
    91                 _ac[i] = _c;
    88                 if (i != _nr_of_access_points - 1)
    92                 if (i != _nr_of_access_points - 1)
    89                     this.iIAPTable.nextRecord();
    93                     iIAPTable.nextRecord();
    90             }
    94             }
    91             this.iIAPTable.close();
    95             iIAPTable.close();
    92         }
    96         }
    93         catch (CommDBException _exception)
    97         catch (CommDBException _exception)
    94         {
    98         {
    95             this.iIAPTable.close();
    99             iIAPTable.close();
    96             throw new IAPInfoException(_exception.getMessage());
   100             throw new IAPInfoException(_exception.getMessage());
    97         }// end of catch
   101         }// end of catch
    98         return _ac;
   102         return _ac;
    99     }
   103     }
   100 
   104 
   101     /**
   105     /**
   102      * Please refer IapInfo Spec.
   106      * Please refer IapInfo Spec.
   103      */
   107      */
   104     public AccessPoint getAccessPoint(int aID) throws IAPInfoException
   108     public synchronized AccessPoint getAccessPoint(int aID) throws IAPInfoException
   105     {
   109     {
   106         AccessPoint _ac = null;
   110         AccessPoint _ac = null;
   107         try
   111         IAPTable iIAPTable = null;
   108         {
   112         Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "+getAccessPoint() - aID = "+aID +" this = "+Thread.currentThread().toString() +"hascode= " +Thread.currentThread().hashCode());
   109             this.iIAPTable.open();
   113         try
   110             int _ret = this.iIAPTable.findById(aID);
   114         {
       
   115             iIAPTable = new IAPTable();
       
   116         }
       
   117         catch (CommDBException e)
       
   118         {
       
   119             e.printStackTrace();
       
   120             throw new IAPInfoException(e.getMessage());
       
   121         }
       
   122         try
       
   123         {
       
   124             iIAPTable.open(iSessionHandle);
       
   125             int _ret = iIAPTable.findById(aID);
   111             if (_ret != IAPTable.RECORD_NOT_FOUND)
   126             if (_ret != IAPTable.RECORD_NOT_FOUND)
   112             {
   127             {
   113                 _ac = new AccessPoint(this.iIAPTable.iRecordId,
   128                 _ac = new AccessPoint(iIAPTable.iRecordId,
   114                                       this.iIAPTable.iRecordName, this.iIAPTable.iBearerType,
   129                                       iIAPTable.iRecordName, iIAPTable.iBearerType,
   115                                       this.iIAPTable.iServiceType);
   130                                       iIAPTable.iServiceType);
   116             }
   131             }
   117             this.iIAPTable.close();
   132             iIAPTable.close();
   118         }
   133         }
   119         catch (CommDBException _exception)
   134         catch (CommDBException _exception)
   120         {
   135         {
   121             this.iIAPTable.close();
   136             iIAPTable.close();
   122             throw new IAPInfoException(_exception.getMessage());
   137             throw new IAPInfoException(_exception.getMessage());
   123         }// end catch
   138         }// end catch
   124         return _ac;
   139         return _ac;
   125     }
   140     }
   126 
   141 
   127     /**
   142     /**
   128      * Please refer IapInfo Spec.
   143      * Please refer IapInfo Spec.
   129      */
   144      */
   130     public AccessPoint getAccessPoint(String aName) throws IAPInfoException
   145     public synchronized AccessPoint getAccessPoint(String aName) throws IAPInfoException
   131     {
   146     {
       
   147         Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "+getAccessPoint() - aName = "+aName +" this = "+Thread.currentThread().toString() +"hascode= " +Thread.currentThread().hashCode());
       
   148         IAPTable iIAPTable = null;
       
   149         try
       
   150         {
       
   151             iIAPTable = new IAPTable();
       
   152         }
       
   153         catch (CommDBException e)
       
   154         {
       
   155             e.printStackTrace();
       
   156             throw new IAPInfoException(e.getMessage());
       
   157         }
   132         if (aName == null)
   158         if (aName == null)
   133         {
   159         {
   134             throw new IAPInfoException("Parameter is NULL");
   160             throw new IAPInfoException("Parameter is NULL");
   135         }
   161         }
   136         AccessPoint _ac = null;
   162         AccessPoint _ac = null;
   137         try
   163         try
   138         {
   164         {
   139             this.iIAPTable.open();
   165             iIAPTable.open(iSessionHandle);
   140             int _ret = this.iIAPTable.findByName(aName);
   166             Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "+getAccessPoint() - aName = after iaptable.open()");
       
   167             int _ret = iIAPTable.findByName(aName);
   141             if (_ret != IAPTable.RECORD_NOT_FOUND)
   168             if (_ret != IAPTable.RECORD_NOT_FOUND)
   142             {
   169             {
   143                 _ac = new AccessPoint(this.iIAPTable.iRecordId,
   170                 _ac = new AccessPoint(iIAPTable.iRecordId,
   144                                       this.iIAPTable.iRecordName, this.iIAPTable.iBearerType,
   171                                       iIAPTable.iRecordName, iIAPTable.iBearerType,
   145                                       this.iIAPTable.iServiceType);
   172                                       iIAPTable.iServiceType);
   146             }
   173             }
   147             this.iIAPTable.close();
   174             iIAPTable.close();
   148         }
   175         }
   149         catch (CommDBException _exception)
   176         catch (CommDBException _exception)
   150         {
   177         {
   151             this.iIAPTable.close();
   178             iIAPTable.close();
   152             throw new IAPInfoException(_exception.getMessage());
   179             throw new IAPInfoException(_exception.getMessage());
   153         }// end catch
   180         }// end catch
       
   181         Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "-getAccessPoint() - aName = "+aName);
   154         return _ac;
   182         return _ac;
   155     }
   183 //return null;
   156 
   184     }
   157     /**
   185 
   158      * Please refer IapInfo Spec.
   186     /**
   159      */
   187      * Please refer IapInfo Spec.
   160     public AccessPoint getLastUsedAccessPoint() throws IAPInfoException
   188      */
   161     {
   189     public synchronized AccessPoint getLastUsedAccessPoint() throws IAPInfoException
       
   190     {
       
   191         Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "+getLastUsedAccessPoint() " +" this = "+Thread.currentThread().toString() +"hascode= " +Thread.currentThread().hashCode());
       
   192         IAPTable iIAPTable = null;
       
   193         try
       
   194         {
       
   195             iIAPTable = new IAPTable();
       
   196         }
       
   197         catch (CommDBException e)
       
   198         {
       
   199             e.printStackTrace();
       
   200             throw new IAPInfoException(e.getMessage());
       
   201         }
   162         APNControl _control = new APNControl();
   202         APNControl _control = new APNControl();
   163         int _lastIAP = _control.getLastIAP();
   203         int _lastIAP = _control.getLastIAP();
   164         AccessPoint _ac = null;
   204         AccessPoint _ac = null;
   165         int _nr_of_access_points = 0;
   205         int _nr_of_access_points = 0;
   166         try
   206         try
   167         {
   207         {
   168             this.iIAPTable.open();
   208             iIAPTable.open(iSessionHandle);
   169             _nr_of_access_points = this.iIAPTable.getRecordCount();
   209             _nr_of_access_points = iIAPTable.getRecordCount();
   170             for (int i = 0; i < _nr_of_access_points; i++)
   210             for (int i = 0; i < _nr_of_access_points; i++)
   171             {
   211             {
   172                 if (this.iIAPTable.iRecordId == _lastIAP)
   212                 if (iIAPTable.iRecordId == _lastIAP)
   173                 {
   213                 {
   174                     _ac = new AccessPoint(this.iIAPTable.iRecordId,
   214                     _ac = new AccessPoint(iIAPTable.iRecordId,
   175                                           this.iIAPTable.iRecordName,
   215                                           iIAPTable.iRecordName,
   176                                           this.iIAPTable.iBearerType,
   216                                           iIAPTable.iBearerType,
   177                                           this.iIAPTable.iServiceType);
   217                                           iIAPTable.iServiceType);
   178                     break;
   218                     break;
   179                 }// end if
   219                 }// end if
   180                 if (i != _nr_of_access_points - 1)
   220                 if (i != _nr_of_access_points - 1)
   181                 {
   221                 {
   182                     this.iIAPTable.nextRecord();
   222                     iIAPTable.nextRecord();
   183                 }
   223                 }
   184             }// end for
   224             }// end for
   185             this.iIAPTable.close();
   225             iIAPTable.close();
   186         }
   226         }
   187         catch (CommDBException _exception)
   227         catch (CommDBException _exception)
   188         {
   228         {
   189             this.iIAPTable.close();
   229             iIAPTable.close();
   190             throw new IAPInfoException(_exception.getMessage());
   230             throw new IAPInfoException(_exception.getMessage());
   191         }
   231         }
   192         return _ac;
   232         return _ac;
   193     }
   233     }
   194 
   234 
   292     }
   332     }
   293 
   333 
   294     /**
   334     /**
   295      * Please refer IapInfo Spec.
   335      * Please refer IapInfo Spec.
   296      */
   336      */
   297     public AccessPoint[] getConnectionPreferences() throws IAPInfoException
   337     public synchronized AccessPoint[] getConnectionPreferences() throws IAPInfoException
   298     {
   338     {
   299 
   339 
   300         ConnectionPreferencesTable _prefTable = null;
   340         ConnectionPreferencesTable _prefTable = null;
   301         AccessPoint[] _ac = null;
   341         AccessPoint[] _ac = null;
       
   342         IAPTable iIAPTable = null;
       
   343         Logger.LOG(Logger.EJavaIapInfo,Logger.EInfo, "+getConnectionPreferences() " +" this = "+Thread.currentThread().toString() +"hascode= " +Thread.currentThread().hashCode());
       
   344         try
       
   345         {
       
   346             iIAPTable = new IAPTable();
       
   347         }
       
   348         catch (CommDBException e)
       
   349         {
       
   350             e.printStackTrace();
       
   351             throw new IAPInfoException(e.getMessage());
       
   352         }
   302 
   353 
   303         try
   354         try
   304         {
   355         {
   305             _prefTable = new ConnectionPreferencesTable();
   356             _prefTable = new ConnectionPreferencesTable();
   306             _prefTable.open();
   357             _prefTable.open(iSessionHandle);
   307             int recNr = _prefTable.getRecordCount();
   358             int recNr = _prefTable.getRecordCount();
   308 
   359 
   309             HelperObject[] hp = new HelperObject[recNr];
   360             HelperObject[] hp = new HelperObject[recNr];
   310             for (int i = 0; i < recNr; i++)
   361             for (int i = 0; i < recNr; i++)
   311             {
   362             {
   334                     }// end if
   385                     }// end if
   335                 }// end for
   386                 }// end for
   336             }// end while
   387             }// end while
   337 
   388 
   338             // get the AccesssPoints from IAPTable
   389             // get the AccesssPoints from IAPTable
   339             this.iIAPTable.open();
   390             iIAPTable.open(iSessionHandle);
   340 
   391 
   341             Vector apv = new Vector();
   392             Vector apv = new Vector();
   342             for (int i = 0; i < recNr; i++)
   393             for (int i = 0; i < recNr; i++)
   343             {
   394             {
   344                 // int _ret = this.iIAPTable.findById( ids[ i ] );
   395                 // int _ret = iIAPTable.findById( ids[ i ] );
   345                 int _ret = this.iIAPTable.findById(hp[i].Id);
   396                 int _ret = iIAPTable.findById(hp[i].Id);
   346                 if (_ret != IAPTable.RECORD_NOT_FOUND)
   397                 if (_ret != IAPTable.RECORD_NOT_FOUND)
   347                 {
   398                 {
   348 
   399 
   349                     apv.addElement(new AccessPoint(this.iIAPTable.iRecordId,
   400                     apv.addElement(new AccessPoint(iIAPTable.iRecordId,
   350                                                    this.iIAPTable.iRecordName,
   401                                                    iIAPTable.iRecordName,
   351                                                    this.iIAPTable.iBearerType,
   402                                                    iIAPTable.iBearerType,
   352                                                    this.iIAPTable.iServiceType));
   403                                                    iIAPTable.iServiceType));
   353                 }// end if
   404                 }// end if
   354             }// end for
   405             }// end for
   355 
   406 
   356             _ac = new AccessPoint[apv.size()];
   407             _ac = new AccessPoint[apv.size()];
   357             for (int i = 0; i < apv.size(); i++)
   408             for (int i = 0; i < apv.size(); i++)
   358             {
   409             {
   359                 _ac[i] = (AccessPoint) apv.elementAt(i);
   410                 _ac[i] = (AccessPoint) apv.elementAt(i);
   360             }
   411             }
   361 
   412 
   362             this.iIAPTable.close();
   413             iIAPTable.close();
   363             _prefTable.close();
   414             _prefTable.close();
   364 
   415 
   365         }
   416         }
   366         catch (CommDBException e)
   417         catch (CommDBException e)
   367         {
   418         {
   368             _prefTable.close();
   419             _prefTable.close();
   369             this.iIAPTable.close();
   420             iIAPTable.close();
   370             throw new IAPInfoException(e.getMessage());
   421             throw new IAPInfoException(e.getMessage());
   371         }
   422         }
   372         return _ac;
   423         return _ac;
   373     }
   424     }
   374 
   425 
   425     static native String _getDestinationNetworkById(int aID)
   476     static native String _getDestinationNetworkById(int aID)
   426     throws IAPInfoException;
   477     throws IAPInfoException;
   427     static native String _getDestinationNetworkByName(String aName)
   478     static native String _getDestinationNetworkByName(String aName)
   428     throws IAPInfoException;
   479     throws IAPInfoException;
   429 
   480 
       
   481     private native int _createSession();
       
   482 
   430 }
   483 }