github.com/nvi-inc/fsgo@v0.2.1/versions/fs10.0.0-beta1/methods.go (about)

     1  // Copyright 2019 NVI Inc. All rights reserved.
     2  // Use of this source code is governed by a MIT
     3  // license that can be found in the LICENSE file.
     4  
     5  package fs
     6  
     7  import (
     8  	"errors"
     9  	"strings"
    10  
    11  	"github.com/nvi-inc/svipc"
    12  )
    13  
    14  func (f *FieldSystem) Log() string {
    15  	return fsstr(f.Fscom.LLOG[:])
    16  
    17  }
    18  func (f *FieldSystem) Schedule() string {
    19  	return fsstr(f.Fscom.LSKD[:])
    20  }
    21  func (f *FieldSystem) Source() string {
    22  	return fsstr(f.Fscom.Lsorna[:])
    23  }
    24  func (f *FieldSystem) SemLocked(semname string) (locked bool, err error) {
    25  	// FS stores a list of names for semephores in the NSEM group. The list is in
    26  	// list in f.Fscom.Sem.  This function queies the semephones in that group by name.
    27  	key, err := svipc.Ftok(NSEM_PATH, NSEM_ID)
    28  	if err != nil {
    29  		return
    30  	}
    31  
    32  	sid, err := svipc.Semget(key, 0, 0)
    33  	if err != nil {
    34  		return
    35  	}
    36  
    37  	semnum := -1
    38  	semname = strings.TrimSpace(semname)
    39  	for i := 0; i < int(f.Fscom.Sem.Allocated); i++ {
    40  		s := strings.TrimSpace(string(f.Fscom.Sem.Name[i][:]))
    41  		if s == semname {
    42  			semnum = i
    43  			break
    44  		}
    45  	}
    46  	if semnum == -1 {
    47  		err = errors.New("sem not found")
    48  		return
    49  	}
    50  
    51  	ret, err := svipc.Semctl(sid, semnum, svipc.GETVAL)
    52  	if err != nil {
    53  		return
    54  	}
    55  	// FS uses sems in a strange way
    56  	locked = (int(ret) == 0)
    57  	return
    58  }
    59  
    60  func (f *FieldSystem) Semaphores() []string {
    61  	sems := make([]string, 0, f.Fscom.Sem.Allocated)
    62  	for i := 0; i < int(f.Fscom.Sem.Allocated); i++ {
    63  		sems = append(sems, fsstr(f.Fscom.Sem.Name[i][:]))
    64  	}
    65  	return sems
    66  }
    67  
    68  func (f *FieldSystem) Tracking() bool {
    69  	return f.Fscom.Ionsor == 1
    70  }
    71  func (f *FieldSystem) DataValid() bool {
    72  	return f.Fscom.DataValid[0].UserDv == 1
    73  }