From 61e8eec55f1f6f9b30278e0d48854e847f5417e0 Mon Sep 17 00:00:00 2001 From: MaMe82 Date: Thu, 18 Oct 2018 14:39:29 +0200 Subject: [PATCH] Allow delayed start of bluetooth sub service --- service/service.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/service/service.go b/service/service.go index 4486d44..d36b05c 100644 --- a/service/service.go +++ b/service/service.go @@ -6,6 +6,7 @@ import ( "github.com/mame82/P4wnP1_go/common_web" pb "github.com/mame82/P4wnP1_go/proto" "github.com/mame82/P4wnP1_go/service/datastore" + "time" ) @@ -146,7 +147,7 @@ func NewService() (svc *Service, err error) { svc.SubSysWifi = NewWifiService(svc) //Depends on NetworkSubSys - svc.SubSysBluetooth = NewBtService(svc) //Depends on NetworkSubSys + svc.SubSysBluetooth = NewBtService(svc, time.Second * 120) //Depends on NetworkSubSys (try to bring up bluetooth for up to 120s in background) svc.SubSysRPC = NewRpcServerService(svc) //Depends on all other @@ -166,8 +167,16 @@ func (s *Service) Start() { // Register TriggerActions RegisterDefaultTriggerActions(s.SubSysTriggerActions) - // ToDo: Manual start of BT NAP, has to be replaced by settings based approach (same as other subsystems) - s.SubSysBluetooth.StartNAP() + // ToDo: 1) Manual start of BT NAP, has to be replaced by settings based approach (same as other subsystems) + // ToDo: 2) create a signal based method s.SubSysBluetooth.WaitTillServiceUp(timeout duration) + go func() { + timeStart := time.Now() + for timeSinceStart := time.Since(timeStart); !s.SubSysBluetooth.IsServiceAvailable() && timeSinceStart < time.Second*120 ;timeSinceStart = time.Since(timeStart) { + time.Sleep(time.Second) + } + s.SubSysBluetooth.StartNAP() + }() + // fire service started Event s.SubSysEvent.Emit(ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_SERVICE_STARTED))