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