X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fagent%2Fproject-st.go;h=fb88b05ba6a3f99fb8cad63b57c4e5081f35a8dc;hb=247bb7c2db5f0d48178398599348249bf886ebbc;hp=d5939e61cf4cce10ea839afd48a558b0e85a47b4;hpb=7c7d90a781082c6bd22d12a5e2451ca61a5198af;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/agent/project-st.go b/lib/agent/project-st.go index d5939e6..fb88b05 100644 --- a/lib/agent/project-st.go +++ b/lib/agent/project-st.go @@ -1,11 +1,29 @@ +/* + * Copyright (C) 2017-2018 "IoT.bzh" + * Author Sebastien Douheret + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package agent import ( + "encoding/json" "fmt" - st "github.com/iotbzh/xds-agent/lib/syncthing" - "github.com/iotbzh/xds-agent/lib/xaapiv1" - "github.com/iotbzh/xds-server/lib/xsapiv1" + st "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/syncthing" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1" ) // IPROJECT interface implementation for syncthing projects @@ -88,9 +106,8 @@ func (p *STProject) Setup(prj xaapiv1.ProjectConfig) (*xaapiv1.ProjectConfig, er // Register events to update folder status // Register to XDS Server events - p.server.EventOn("event:folder-state-change", "", p._cbServerFolderChanged) - if err := p.server.EventRegister("folder-state-change", svrPrj.ID); err != nil { - p.Log.Warningf("XDS Server EventRegister failed: %v", err) + if _, err := p.server.EventOn(xsapiv1.EVTFolderStateChange, "", p._cbServerFolderChanged); err != nil { + p.Log.Errorf("XDS Server EventOn '%s' failed: %v", xsapiv1.EVTFolderStateChange, err) return svrPrj, err } @@ -147,18 +164,32 @@ func (p *STProject) IsInSync() (bool, error) { // callback use to update (XDS Server) folder IsInSync status func (p *STProject) _cbServerFolderChanged(pData interface{}, data interface{}) error { - evt := data.(xsapiv1.EventMsg) + evt := xsapiv1.EventMsg{} + d, err := json.Marshal(data) + if err != nil { + p.Log.Errorf("Cannot marshal XDS Server event folder-change err=%v", err) + return err + } + if err = json.Unmarshal(d, &evt); err != nil { + p.Log.Errorf("Cannot unmarshal XDS Server event folder-change err=%v", err) + return err + } + + fld, err := evt.DecodeFolderConfig() + if err != nil { + p.Log.Errorf("Cannot decode FolderChanged event: %v", data) + } // Only process event that concerns this project/folder ID - if p.folder.ID != evt.Folder.ID { + if p.folder.ID != fld.ID { return nil } - if evt.Folder.IsInSync != p.folder.DataCloudSync.STSvrIsInSync || - evt.Folder.Status != p.folder.DataCloudSync.STSvrStatus { + if fld.IsInSync != p.folder.DataCloudSync.STSvrIsInSync || + fld.Status != p.folder.DataCloudSync.STSvrStatus { - p.folder.DataCloudSync.STSvrIsInSync = evt.Folder.IsInSync - p.folder.DataCloudSync.STSvrStatus = evt.Folder.Status + p.folder.DataCloudSync.STSvrIsInSync = fld.IsInSync + p.folder.DataCloudSync.STSvrStatus = fld.Status if err := p.events.Emit(xaapiv1.EVTProjectChange, p.server.FolderToProject(*p.folder), ""); err != nil { p.Log.Warningf("Cannot notify project change (from server): %v", err)