Exemple #1
0
 public BluetopiaFactory GetFactory(IBluetopiaSecurity optionalSecurityInstance)
 {
     if (_fcty == null)
     {
         _fcty = new BluetopiaFactory(this.MockedApi, optionalSecurityInstance);
     }
     BluetopiaTesting.HackAllowShutdownCall(this.MockedApi);
     return(_fcty);
 }
Exemple #2
0
 internal void CreateMockedSecurityApi()
 {
     _secMock = this.Mockery.NewMock <IBluetopiaSecurity>();
     Expect.Once.On(_secMock).Method("InitStack")
     .WithNoArguments()
     .Will(
         new MyDelegateAction(delegate {
         this.MockedApi.GAP_Set_Pairability_Mode(this.StackId, StackConsts.GAP_Pairability_Mode.PairableMode);
         NativeMethods.GAP_Event_Callback foo = null;
         this.MockedApi.GAP_Register_Remote_Authentication(this.StackId, foo, (uint)0);
     })
         );
     var tmp = this.GetFactory(_secMock);
 }
Exemple #3
0
        internal BluetopiaFactory(IBluetopiaApi api, IBluetopiaSecurity optionalSecurityInstance)
        {
            if (api == null)
            {
                throw new ArgumentNullException("api");
            }
            _api = api;
            //
            _inquiryHandler       = new BluetopiaInquiry(this);
            _inquiryEventCallback = _inquiryHandler.HandleInquiryEvent;
            _HandleNameLookup     = HandleNameLookup;
            //
            //int handle = _api.BSC_Initialize((byte[])InitData.Clone(), 0);
            Utils.MiscUtils.Trace_WriteLine(
                "Calling BSC_Initialize with:" + InitData2.ToString());
            int handle = _api.BSC_Initialize(ref InitData2, 0);
            //TEST--CheckStructBytes(ref InitData2, (byte[])InitData.Clone());
            var ret = (BluetopiaError)handle;

            if (!BluetopiaUtils.IsSuccessZeroIsIllegal(ret))
            {
                KillBtExplorerExe();  // Since one app at a time!
                // _Quickly_ try to init, as BTExplorer.exe restarts automatically!
                handle = _api.BSC_Initialize(ref InitData2, 0);
                ret    = (BluetopiaError)handle;
            }
            if (!BluetopiaUtils.IsSuccessZeroIsIllegal(ret))
            {
                Utils.MiscUtils.Trace_WriteLine("Stonestreet One Bluetopia failed to init: "
                                                + BluetopiaUtils.ErrorToString(ret));
            }
            BluetopiaUtils.CheckAndThrowZeroIsIllegal(ret, "BSC_Initialize");
            _stackId = checked ((uint)handle);
            //
            if (optionalSecurityInstance != null)
            {
                _sec = optionalSecurityInstance;
            }
            else
            {
                _sec = new BluetopiaSecurity(this);
            }
            _sec.InitStack();
            //
            //
            var packetDebug = false;
            var eap         = BluetoothFactoryConfig.GetEntryAssemblyPath();

            if (eap != null)   // null if we're under unit-test or...
            {
                var dir      = Path.GetDirectoryName(eap);
                var filename = Path.Combine(dir, "DoPacketDebug.txt");
                if (File.Exists(filename))
                {
                    packetDebug = true;
                }
            }
            if (packetDebug)
            {
                _pdebug = new BluetopiaPacketDebug(this);
            }
            //
            InitApiVersion();
        }