You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/08/09 14:28:59 UTC
[plc4x] 01/03: refactor(plc4xbrowser): put ui parts into a ui package
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit e8ab0a7ed589db8cab7bc85f5a00fd3f0d6a453d
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Aug 9 10:55:08 2022 +0200
refactor(plc4xbrowser): put ui parts into a ui package
---
plc4go/tools/plc4xbrowser/common.go | 31 -----------
plc4go/tools/plc4xbrowser/main.go | 62 ++--------------------
plc4go/tools/plc4xbrowser/{ => ui}/actions.go | 4 +-
plc4go/tools/plc4xbrowser/{ => ui}/commands.go | 2 +-
.../tools/plc4xbrowser/{main.go => ui/common.go} | 28 +++++-----
plc4go/tools/plc4xbrowser/{ => ui}/config.go | 4 +-
plc4go/tools/plc4xbrowser/{ => ui}/ui.go | 4 +-
7 files changed, 24 insertions(+), 111 deletions(-)
diff --git a/plc4go/tools/plc4xbrowser/common.go b/plc4go/tools/plc4xbrowser/common.go
deleted file mode 100644
index b42f76a1b..000000000
--- a/plc4go/tools/plc4xbrowser/common.go
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * https://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 main
-
-import (
- "github.com/rs/zerolog"
- "strings"
-)
-
-const protocols = "ads,bacnetip,c-bus,s7"
-
-var protocolList = strings.Split(protocols, ",")
-
-var plc4xBrowserLog = zerolog.Nop()
diff --git a/plc4go/tools/plc4xbrowser/main.go b/plc4go/tools/plc4xbrowser/main.go
index 1f5ebcd1c..0427d9c39 100644
--- a/plc4go/tools/plc4xbrowser/main.go
+++ b/plc4go/tools/plc4xbrowser/main.go
@@ -20,68 +20,16 @@
package main
import (
- "io"
- "sync"
- "time"
-
- plc4go "github.com/apache/plc4x/plc4go/pkg/api"
- plc4goModel "github.com/apache/plc4x/plc4go/pkg/api/model"
-)
-
-var driverManager plc4go.PlcDriverManager
-var driverAdded func(string)
-var connections map[string]plc4go.PlcConnection
-var connectionsChanged func()
-
-var messageReceived func(messageNumber int, receiveTime time.Time, message plc4goModel.PlcMessage)
-var numberOfMessagesReceived int
-var messageOutput io.Writer
-var messageOutputClear func()
-
-var consoleOutput io.Writer
-var consoleOutputClear func()
-
-var commandsExecuted int
-var commandOutput io.Writer
-var commandOutputClear func()
-
-type inputMode int
-
-const (
- normalMode inputMode = iota
- readEditMode
- writeEditMode
- subscribeEditMode
+ "github.com/apache/plc4x/plc4go/tools/plc4xbrowser/ui"
)
-func init() {
- hasShutdown = false
- connections = make(map[string]plc4go.PlcConnection)
-}
-
-var shutdownMutex sync.Mutex
-var hasShutdown bool
-
-func shutdown() {
- shutdownMutex.Lock()
- defer shutdownMutex.Unlock()
- if hasShutdown {
- return
- }
- for _, connection := range connections {
- connection.Close()
- }
- saveConfig()
- hasShutdown = true
-}
-
func main() {
- loadConfig()
- application := setupApplication()
- initSubsystem()
+ ui.LoadConfig()
+ application := ui.SetupApplication()
+ ui.InitSubsystem()
if err := application.Run(); err != nil {
panic(err)
}
- shutdown()
+ ui.Shutdown()
}
diff --git a/plc4go/tools/plc4xbrowser/actions.go b/plc4go/tools/plc4xbrowser/ui/actions.go
similarity index 98%
rename from plc4go/tools/plc4xbrowser/actions.go
rename to plc4go/tools/plc4xbrowser/ui/actions.go
index 6f9f581bb..25fce0a5f 100644
--- a/plc4go/tools/plc4xbrowser/actions.go
+++ b/plc4go/tools/plc4xbrowser/ui/actions.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package main
+package ui
import (
"fmt"
@@ -33,7 +33,7 @@ import (
"github.com/sruehl/tview"
)
-func initSubsystem() {
+func InitSubsystem() {
logLevel := zerolog.InfoLevel
if configuredLevel := config.LogLevel; configuredLevel != "" {
if parsedLevel, err := zerolog.ParseLevel(configuredLevel); err != nil {
diff --git a/plc4go/tools/plc4xbrowser/commands.go b/plc4go/tools/plc4xbrowser/ui/commands.go
similarity index 99%
rename from plc4go/tools/plc4xbrowser/commands.go
rename to plc4go/tools/plc4xbrowser/ui/commands.go
index 44fbe8829..26fb8c191 100644
--- a/plc4go/tools/plc4xbrowser/commands.go
+++ b/plc4go/tools/plc4xbrowser/ui/commands.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package main
+package ui
import (
"fmt"
diff --git a/plc4go/tools/plc4xbrowser/main.go b/plc4go/tools/plc4xbrowser/ui/common.go
similarity index 90%
copy from plc4go/tools/plc4xbrowser/main.go
copy to plc4go/tools/plc4xbrowser/ui/common.go
index 1f5ebcd1c..84e31683b 100644
--- a/plc4go/tools/plc4xbrowser/main.go
+++ b/plc4go/tools/plc4xbrowser/ui/common.go
@@ -17,17 +17,24 @@
* under the License.
*/
-package main
+package ui
import (
+ plc4go "github.com/apache/plc4x/plc4go/pkg/api"
+ plc4goModel "github.com/apache/plc4x/plc4go/pkg/api/model"
+ "github.com/rs/zerolog"
"io"
+ "strings"
"sync"
"time"
-
- plc4go "github.com/apache/plc4x/plc4go/pkg/api"
- plc4goModel "github.com/apache/plc4x/plc4go/pkg/api/model"
)
+const protocols = "ads,bacnetip,c-bus,s7"
+
+var protocolList = strings.Split(protocols, ",")
+
+var plc4xBrowserLog = zerolog.Nop()
+
var driverManager plc4go.PlcDriverManager
var driverAdded func(string)
var connections map[string]plc4go.PlcConnection
@@ -62,7 +69,7 @@ func init() {
var shutdownMutex sync.Mutex
var hasShutdown bool
-func shutdown() {
+func Shutdown() {
shutdownMutex.Lock()
defer shutdownMutex.Unlock()
if hasShutdown {
@@ -74,14 +81,3 @@ func shutdown() {
saveConfig()
hasShutdown = true
}
-
-func main() {
- loadConfig()
- application := setupApplication()
- initSubsystem()
-
- if err := application.Run(); err != nil {
- panic(err)
- }
- shutdown()
-}
diff --git a/plc4go/tools/plc4xbrowser/config.go b/plc4go/tools/plc4xbrowser/ui/config.go
similarity index 99%
rename from plc4go/tools/plc4xbrowser/config.go
rename to plc4go/tools/plc4xbrowser/ui/config.go
index 24da0242c..d10f990ec 100644
--- a/plc4go/tools/plc4xbrowser/config.go
+++ b/plc4go/tools/plc4xbrowser/ui/config.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package main
+package ui
import (
"github.com/pkg/errors"
@@ -60,7 +60,7 @@ func init() {
configFile = path.Join(plc4xBrowserConfigDir, "config.yml")
}
-func loadConfig() {
+func LoadConfig() {
f, err := os.Open(configFile)
if err != nil {
log.Info().Err(err).Msg("No config file found")
diff --git a/plc4go/tools/plc4xbrowser/ui.go b/plc4go/tools/plc4xbrowser/ui/ui.go
similarity index 99%
rename from plc4go/tools/plc4xbrowser/ui.go
rename to plc4go/tools/plc4xbrowser/ui/ui.go
index d4a5f4619..fda7476c0 100644
--- a/plc4go/tools/plc4xbrowser/ui.go
+++ b/plc4go/tools/plc4xbrowser/ui/ui.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package main
+package ui
import (
"fmt"
@@ -30,7 +30,7 @@ import (
"time"
)
-func setupApplication() *tview.Application {
+func SetupApplication() *tview.Application {
application := tview.NewApplication()
newPrimitive := func(text string) tview.Primitive {