Esempio n. 1
0
        //public connector(string[] profiles)
        public connector()
        {
            //read config values
            _profiles            = new string[] { _myConfig._profile1, _myConfig._profile2 };
            _bcheckOnUndock      = _myConfig._checkOnUndock;
            _bcheckOnResume      = _myConfig._checkOnResume;
            _bswitchOnDisconnect = _myConfig._switchOnDisconnect;
            _iSwitchTimeout      = _myConfig._switchTimeout;
            _benableLogging      = _myConfig._enableLogging;
#if DEBUG
            Logger.bEnableLogging = true;
#else
            Logger.bEnableLogging = _benableLogging;
#endif
            //_profiles = profiles;
            evtStopThreads.Reset(); // clear event

            OnConnectedMessage("connector initialized with profiles: ");
            try
            {
                _ssRACapi = new itc_ssapi();
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("RAC not active");
            }

            //list profiles and disable all first, only one should be enabled
            foreach (string s in _profiles)
            {
                OnConnectedMessage("\t" + s);
                _ssRACapi.enableProfile(s, false);
            }
            _ssRACapi.enableProfile(_profiles[0], true); //enable primary profile

            _workThread      = new Thread(new ThreadStart(myWorkerThread));
            _workThread.Name = "myWorkerThread";
            _workThread.Start();

            _connectThread      = new Thread(new ThreadStart(connectWatchThread));
            _connectThread.Name = "connectWatchThread";
            _connectThread.Start();

            _timerThread      = new Thread(new ThreadStart(timerThread));
            _timerThread.Name = "timerThread";
            _timerThread.Start();

            _PowerSourceMessages = new PowerSourceChanges();
            _PowerSourceMessages.powerChangedEvent += new PowerSourceChanges.powerChangeEventHandler(_powerSourceMessages_powerChangedEvent);

            _PowerMessages = new PowerMessages();
            _PowerMessages.powerChangedEvent += new PowerMessages.powerChangeEventHandler(_PowerMessages_powerChangedEvent);
        }
Esempio n. 2
0
        /// <summary>
        /// this function tries to switch to the preferred network
        /// and falls back to second profile if 1st did not connect
        /// </summary>
        void doSwitch()
        {
            if (bInsideSwitch)
            {
                Logger.WriteLine("doSwitch called although already insideSwitch");
                return;
            }
            lock (syncObject)
                bInsideSwitch = true;

            OnConnectedMessage("DoSwitch() start...");
            Logger.WriteLine("DoSwitch() start...");

            int iConnectTry = 0;
            //is first profile active?
            string currentProfile = _ssRACapi.getCurrentProfile().sProfileLabel;
            string desiredSSID    = _ssRACapi.getCurrentProfile().sSSID;

            OnConnectedMessage("current profile=" + currentProfile);
            //is the preferred profile active?
            if (currentProfile == _profiles[0])
            {
                OnConnectedMessage("Current Profile = First profile");
                if (network._getConnected() == false)
                {                                                 //not connected
                    OnConnectedMessage("network not connected. Switching to 2nd profile...");
                    _ssRACapi.enableProfile(_profiles[0], false); //disable first profile
                    _ssRACapi.enableProfile(_profiles[1], true);  //enable second profile
                }
                else
                {
                    OnConnectedMessage("network connected. No profile change.");
                }
            }
            else if (_ssRACapi.getCurrentProfile().sProfileLabel == _profiles[1])
            {
                desiredSSID = _ssRACapi._racProfiles[1].sSSID;
                OnConnectedMessage("Current Profile = Second profile");
                if (network._getConnected() == false)
                {
                    OnConnectedMessage("secondary profile not connected");
                }
                else
                {
                    OnConnectedMessage("secondary profile connected");
                }
                //try first profile, regardless of connect state
                OnConnectedMessage("Trying first Profile. Switching ...");
                _ssRACapi.enableProfile(_profiles[1], false); //disable second profile
                _ssRACapi.enableProfile(_profiles[0], true);  //enable first profile
                desiredSSID = _ssRACapi._racProfiles[0].sSSID;
                iConnectTry = 0;
                //try for 40 seconds or so
                while (!_bStopThread && (iConnectTry < _iSwitchTimeout))
                {
                    Thread.Sleep(1000);
                    iConnectTry++;
                    if (_myConfig._checkConnectIP)
                    {
                        if (network._getConnected() == true)    // do not care about AP association
                        {
                            break;
                        }
                    }
                    else //check AP association but not IP
                    {
                        if (wifi.isAssociated(desiredSSID) == true) // do not care about IP
                        {
                            break;
                        }
                    }
                }
                //another test for being connected
                if (network._getConnected() == false)
                {
                    OnConnectedMessage("First Profile did not connect. Switching to secondary profile...");
                    //switch back
                    _ssRACapi.enableProfile(_profiles[0], false); //disable first profile
                    _ssRACapi.enableProfile(_profiles[1], true);  //enable second profile
                }
                else
                {
                    OnConnectedMessage("primary network connected.");
                }
            }
            else
            {
                OnConnectedMessage("Current profile not in list!");
            }

            lock (syncObject)
                bInsideSwitch = false;
            OnConnectedMessage("DoSwitch() end.");
            Logger.WriteLine("DoSwitch() end.");
        }