sdkcreationmw/sdkruntimes/MIDP/nei/src/com/symbian/tools/j2me/sei/preferences/KDPPreferences.java
changeset 0 b26acd06ea60
child 1 ac50fd48361b
equal deleted inserted replaced
-1:000000000000 0:b26acd06ea60
       
     1 /*
       
     2 * Copyright (c) 2003 - 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 package com.symbian.tools.j2me.sei.preferences;
       
    19 
       
    20 import java.io.*;
       
    21 import java.util.*;
       
    22 import java.net.InetAddress;
       
    23 import java.net.UnknownHostException;
       
    24 import java.util.HashMap;
       
    25 import java.util.Map;
       
    26 import com.symbian.utils.Debug;
       
    27 
       
    28 public class KDPPreferences implements Serializable {
       
    29 
       
    30   public static final String EMULATOR_SESSION_NAME = "S60Emulator";
       
    31   public static final String DEVICE_SESSION_NAME = "S60Device";
       
    32   
       
    33   //
       
    34   // Constant default values
       
    35   // (used in setDefaultValues)
       
    36   //
       
    37 
       
    38 
       
    39   //Dima private static final int DEF_CONNECTION_ATTEMPTS = 60;
       
    40   private static final int DEF_CONNECTION_ATTEMPTS = 1060;
       
    41   private static final boolean DEF_ENABLE_ATTACHING = false;
       
    42   private static final boolean DEF_DEFER_LAUNCH = false;
       
    43   private static final int DEF_KDP_ATTACH_PORT = 1168;
       
    44   private static final boolean DEF_EKA2_EMUL_DISCOVER = true;
       
    45   private static final String SESSION_PREFS_FILE = "sessions.properties";
       
    46 
       
    47 
       
    48   //
       
    49   // Members
       
    50   //
       
    51 
       
    52   /**
       
    53    * Number of attempts to connect to the VM.
       
    54    */
       
    55   private int iAttemptsCounter;
       
    56 
       
    57   /**
       
    58    * Indicates if to enable attaching to the VM when launching a MIDlet.
       
    59    * That means the VM starts in non-suspended mode and the KDP agent will
       
    60    * connect to it.
       
    61    */
       
    62   private boolean iEnableAttachingToVM;
       
    63 
       
    64   /**
       
    65    * Indicates not to launch the VM.
       
    66    * This is used for debugging pushed MIDlets.
       
    67    */
       
    68   private boolean iDeferLaunchingVM;
       
    69 
       
    70   /**
       
    71    * Port to be used for VM when launch in "attaching enabled" mode.
       
    72    * In this case, we choose it not by any SEI command line parameters.
       
    73    */
       
    74   private int iAttachedVMKDPPort;
       
    75 
       
    76   /**
       
    77    * Session names to SessionPreferences table
       
    78    */
       
    79   private HashMap iSessionNames2Preferences;
       
    80 
       
    81   /**
       
    82    * EKA2 reusability indicator.
       
    83    * On EKA2 we can reuse the emulator for future sessions instead of launching
       
    84    * it every time. That should save the use the startup time.
       
    85    */
       
    86   private boolean iEKA2EmulatorDiscovery = DEF_EKA2_EMUL_DISCOVER;
       
    87 
       
    88 
       
    89 
       
    90 
       
    91   //
       
    92   // Life cycle
       
    93   //
       
    94 
       
    95 
       
    96 
       
    97   /**
       
    98    * Default constructor.
       
    99    */
       
   100   public KDPPreferences() {
       
   101     setDefaultValues();
       
   102   }
       
   103 
       
   104 
       
   105   //
       
   106   // Operations
       
   107   //
       
   108 
       
   109 
       
   110   /**
       
   111    * Set default values
       
   112    */
       
   113   protected void setDefaultValues(){
       
   114     iAttemptsCounter = DEF_CONNECTION_ATTEMPTS;
       
   115     iEnableAttachingToVM = DEF_ENABLE_ATTACHING;
       
   116     iDeferLaunchingVM = DEF_DEFER_LAUNCH;
       
   117     iAttachedVMKDPPort = DEF_KDP_ATTACH_PORT;
       
   118     iEKA2EmulatorDiscovery = DEF_EKA2_EMUL_DISCOVER;
       
   119 
       
   120     //init Session preferences
       
   121     initSessionPreferences();
       
   122   }
       
   123 
       
   124 
       
   125   /**
       
   126    * Initialize Session preferences with default values.
       
   127    *
       
   128    * CUSTOMISATION NOTE: This METHOD is intended to be used for customization
       
   129    * TODO: Licensees should use this method to init implemented sessions data
       
   130    */
       
   131   private void initSessionPreferences(){
       
   132     iSessionNames2Preferences = new HashMap();
       
   133     Properties prefs = new Properties();
       
   134     SessionPreferences win32Prefs = new SessionPreferences();
       
   135     SessionPreferences targetPrefs = new SessionPreferences();
       
   136     try
       
   137     {
       
   138       prefs.load(getClass().getResourceAsStream(SESSION_PREFS_FILE));
       
   139       win32Prefs.setHost((String)prefs.get("win32.agent.host"));
       
   140       win32Prefs.setPort(Integer.parseInt((String)prefs.get("win32.agent.port")));
       
   141       win32Prefs.setLocalPort(Integer.parseInt((String)prefs.get("win32.port")));
       
   142       win32Prefs.setOutgoing(
       
   143           Boolean.valueOf( (String) prefs.get("win32.outgoing")).booleanValue());
       
   144       targetPrefs.setHost((String)prefs.get("target.agent.host"));
       
   145       targetPrefs.setPort(Integer.parseInt((String)prefs.get("target.agent.port")));
       
   146       targetPrefs.setLocalPort(Integer.parseInt((String)prefs.get("target.port")));
       
   147       targetPrefs.setOutgoing(
       
   148           Boolean.valueOf( (String) prefs.get("target.outgoing")).booleanValue());
       
   149     }
       
   150     catch(Exception e){
       
   151       Debug.printStackTrace(this, e);
       
   152     }
       
   153     finally{
       
   154       iSessionNames2Preferences.put(EMULATOR_SESSION_NAME, win32Prefs);
       
   155       iSessionNames2Preferences.put(DEVICE_SESSION_NAME, targetPrefs);
       
   156 
       
   157     }
       
   158   }
       
   159 
       
   160   /**
       
   161    * Get max VM connection attempts
       
   162    *
       
   163    * @return max VM connection attempts
       
   164    */
       
   165   public int getConnectionAttempts(){
       
   166     return iAttemptsCounter;
       
   167   }
       
   168 
       
   169 
       
   170   /**
       
   171    * Set max VM connection attempts
       
   172    * Calculate number of connection attempts based on the fact that
       
   173    * Sun's KDP was changed to connect every 1000ms.
       
   174    *
       
   175    * @param aTimeout max connection timeout in seconds.
       
   176    */
       
   177   public void setConnectionTimeout(int aTimeoutSecs){
       
   178     iAttemptsCounter = aTimeoutSecs;
       
   179   }
       
   180 
       
   181   /**
       
   182    * Get max VM connection attempts
       
   183    * Calculate number of connection attempts based on the fact that
       
   184    * Sun's KDP was changed to connect every 1000ms.
       
   185    *
       
   186    * @return max connection timeout in seconds.
       
   187    */
       
   188   public int getConnectionTimeout(){
       
   189     return iAttemptsCounter;
       
   190   }
       
   191 
       
   192   /**
       
   193    * Indicates if VM launching is defered
       
   194    *
       
   195    * @return VM launching defered indicator
       
   196    */
       
   197   public boolean isVMLaunchingDeferred(){
       
   198     return iDeferLaunchingVM;
       
   199   }
       
   200 
       
   201   /**
       
   202    * Indicates if attaching to VM is enabled
       
   203    *
       
   204    * @return attaching to VM indicator
       
   205    */
       
   206   public boolean isAttachingToVMEnabled(){
       
   207     return iEnableAttachingToVM;
       
   208   }
       
   209 
       
   210   /**
       
   211    * Set VM launching defered indicator
       
   212    *
       
   213    * @param aIsDefered new VM launching defered indicator
       
   214    */
       
   215   public void setVMLaunchingDeferred(boolean aIsDeferred){
       
   216     iDeferLaunchingVM = aIsDeferred;
       
   217   }
       
   218 
       
   219   /**
       
   220    * Set enable attaching to VM indicator
       
   221    *
       
   222    * @param aIsAttachingEnabled new enable attaching to VM indicator
       
   223    */
       
   224   public void setAttachingToVMEnabled(boolean aIsAttachingEnabled){
       
   225     iEnableAttachingToVM = aIsAttachingEnabled;
       
   226   }
       
   227 
       
   228   /**
       
   229    * Set VM debug port when attaching is enabled
       
   230    *
       
   231    * @param aPort VM debug port when attaching is enabled
       
   232    */
       
   233   public void setAttachedVMKDPPort(int aPort){
       
   234     iAttachedVMKDPPort = aPort;
       
   235   }
       
   236 
       
   237   /**
       
   238    * Get VM debug port when attaching is enabled
       
   239    *
       
   240    * @return VM debug port when attaching is enabled
       
   241    */
       
   242   public int getAttachedVMKDPPort(){
       
   243     return iAttachedVMKDPPort;
       
   244   }
       
   245 
       
   246   /**
       
   247    * Indicates if should attempt EKA2 emulator discovery method
       
   248    *
       
   249    * @return EKA2 emulator discovery method indicator
       
   250    */
       
   251   public boolean isEKA2EmulatorDiscovery(){
       
   252     return iEKA2EmulatorDiscovery;
       
   253   }
       
   254 
       
   255   /**
       
   256    * Indicate if to attempt EKA2 emulator discovery method
       
   257    *
       
   258    * @param aEKA2EmulatorDiscovery EKA2 emulator discovery method indicator
       
   259    */
       
   260   public void setEKA2EmulatorDiscovery(boolean aEKA2EmulatorDiscovery){
       
   261     iEKA2EmulatorDiscovery = aEKA2EmulatorDiscovery;
       
   262   }
       
   263 
       
   264 
       
   265   /**
       
   266    * Get session preferences
       
   267    * @param aSessionName session name
       
   268    * @return session preferences
       
   269    */
       
   270   public SessionPreferences getSessionPreferences(String aSessionName){
       
   271   	return (SessionPreferences)iSessionNames2Preferences.get(aSessionName);
       
   272   }
       
   273 
       
   274 }