Skip to content

Commit

Permalink
Add dummy mode to stm executable
Browse files Browse the repository at this point in the history
It uses Dummy implementation of InterfaceCloser originally created by
amistewicz.

New boolean flag "-dummy" is provided.

It should be used when only logging of the commands used is desired.

Change-Id: If5dc582aef3e691282ed616c992c0e96d31dc087
Signed-off-by: Michal Sidor <m.sidor@samsung.com>
  • Loading branch information
Michal Sidor committed Jul 19, 2018
1 parent 7ec3443 commit 1943cb2
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sw/nanopi/cmd/stm/stm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ var (
serviceSocket string
serve bool
remote string
dummy bool
)

func setGlobalFlags() {
flag.StringVar(&userServiceSocket, "user-listen", "/run/stm-user.socket", "path to socket on which user RPC interface will be served")
flag.StringVar(&serviceSocket, "listen", "/run/stm.socket", "path to socket on which user and admin RPC interface will be served")
flag.BoolVar(&serve, "serve", false, "start RPC service")
flag.StringVar(&remote, "remote", "", "path to socket to use as a RPC service instead of local connection")
flag.BoolVar(&dummy, "dummy", false, "log actions instead of performing them")
}

func checkErr(ctx string, err error) {
Expand Down Expand Up @@ -63,8 +65,14 @@ func main() {
log.Fatal("conflicting flags: serve and remote")
}

if (remote != "") && dummy {
log.Fatal("conflicting flags: dummy and remote")
}

var dev stm.InterfaceCloser
if remote != "" {
if dummy {
dev = stm.NewDummy("stm")
} else if remote != "" {
cl, err := rpc.Dial("unix", remote)
checkErr("failed to connect to RPC service: ", err)

Expand Down
112 changes: 112 additions & 0 deletions sw/nanopi/stm/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* 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 stm

import (
"log"
"time"
)

// Dummy is a dummy implementation of Interface.
// It logs to the standard logger from "log" package.
type Dummy struct {
ctx string
}

// NewDummy return a dummy implementation of Interface.
// Each message will be prefixed with context.
func NewDummy(context string) InterfaceCloser {
return &Dummy{ctx: context}
}

// Close prints "Close" to the standard logger.
func (d *Dummy) Close() error {
log.Println(d.ctx, "Close")
return nil
}

// PowerTick prints "PowerTick" and duration argument to the standard logger.
func (d *Dummy) PowerTick(duration time.Duration) error {
log.Println(d.ctx, "PowerTick", duration)
return nil
}

// SetLED prints "SetLED" and arguments to the standard logger.
func (d *Dummy) SetLED(led LED, r, g, b uint8) error {
log.Println(d.ctx, "SetLED", led, r, g, b)
return nil
}

// ClearDisplay prints "ClearDisplay" to the standard logger.
func (d *Dummy) ClearDisplay() error {
log.Println(d.ctx, "ClearDisplay")
return nil
}

// PrintText prints "PrintText" and arguments to the standard logger.
func (d *Dummy) PrintText(x, y uint, color Color, text string) error {
log.Println(d.ctx, "PrintText", x, y, color, text)
return nil
}

// DUT prints "DUT" to the standard logger.
func (d *Dummy) DUT() error {
log.Println(d.ctx, "DUT")
return nil
}

// TS prints "TS" to the standard logger.
func (d *Dummy) TS() error {
log.Println(d.ctx, "TS")
return nil
}

// GetCurrent prints "GetCurrent" to the standard logger and returns 0.
func (d *Dummy) GetCurrent() (int, error) {
log.Println(d.ctx, "GetCurrent")
return 0, nil
}

// StartCurrentRecord prints "StartCurrentRecord" and arguments to the standard logger.
func (d *Dummy) StartCurrentRecord(samples int, interval time.Duration) error {
log.Println(d.ctx, "StartCurrentRecord", samples, interval)
return nil
}

// StopCurrentRecord prints "StopCurrentRecord" to the standard logger.
func (d *Dummy) StopCurrentRecord() error {
log.Println(d.ctx, "StopCurrentRecord")
return nil
}

// GetCurrentRecord prints "GetCurrentRecord" to the standard logger and returns nil.
func (d *Dummy) GetCurrentRecord() ([]int, error) {
log.Println(d.ctx, "GetCurrentRecord")
return nil, nil
}

// HDMI prints "HDMI" and argument to the standard logger.
func (d *Dummy) HDMI(on bool) (err error) {
log.Println(d.ctx, "HDMI", on)
return nil
}

// SetDyper prints "SetDyper" and arguments to the standard logger.
func (d *Dummy) SetDyper(dyper Dyper, on bool) error {
log.Println(d.ctx, "SetDyper", dyper, on)
return nil
}

0 comments on commit 1943cb2

Please sign in to comment.