Skip to content

Commit 86168b1

Browse files
committed
Added debug output to lemonade backend
1 parent 7d07487 commit 86168b1

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ endif()
5959

6060
# Project version number
6161
set(PRJ_VERSION_MAJOR 1)
62-
set(PRJ_VERSION_MINOR 1)
62+
set(PRJ_VERSION_MINOR 2)
6363

6464
if (EXISTS "${PROJECT_SOURCE_DIR}/.git" AND IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git")
6565
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/cmake/githash.sh ${GIT_EXECUTABLE}

citrus/clipboard.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package citrus
22

33
import (
4+
"log"
45
"net"
56
"regexp"
67
"strings"
@@ -12,19 +13,24 @@ import (
1213
type Clipboard struct {
1314
connCh chan net.Conn
1415
params ParamsValue
16+
debug bool
1517
}
1618

1719
// NewClipboard initializes Clipboard structure.
18-
func NewClipboard(ch chan net.Conn, params ParamsValue) *Clipboard {
20+
func NewClipboard(ch chan net.Conn, params ParamsValue, debug bool) *Clipboard {
1921
return &Clipboard{
2022
connCh: ch,
2123
params: params,
24+
debug: debug,
2225
}
2326
}
2427

2528
// Copy is implementation of "lemonade" rpc "copy" command.
2629
func (c *Clipboard) Copy(text string, _ *struct{}) error {
2730
<-c.connCh
31+
if c.debug {
32+
log.Printf("lemonade Copy request received len: %d", len(text))
33+
}
2834
// Logger instance needs to be passed here somehow?
2935
return clipboard.WriteAll(convertLineEnding(text, c.params.LE))
3036
}
@@ -33,6 +39,9 @@ func (c *Clipboard) Copy(text string, _ *struct{}) error {
3339
func (c *Clipboard) Paste(_ struct{}, resp *string) error {
3440
<-c.connCh
3541
t, err := clipboard.ReadAll()
42+
if c.debug {
43+
log.Printf("lemonade Paste request received len: %d, error: '%+v'", len(t), err)
44+
}
3645
*resp = t
3746
return err
3847
}

citrus/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ type Citrus struct {
1313
params ParamsValue
1414
ra *Range
1515
listener *net.TCPListener
16+
debug bool
1617
}
1718

1819
// NewCitrus initializes "lemonade" server.
19-
func NewCitrus(params ParamsValue) (*Citrus, error) {
20+
func NewCitrus(params ParamsValue, debug bool) (*Citrus, error) {
2021

2122
res := &Citrus{
2223
connCh: make(chan net.Conn, 1),
2324
params: params,
25+
debug: debug,
2426
}
2527

26-
if err := rpc.Register(NewURI(res.connCh, res.params)); err != nil {
28+
if err := rpc.Register(NewURI(res.connCh, res.params, res.debug)); err != nil {
2729
return nil, fmt.Errorf("unable to register URI rpc: %w", err)
2830
}
29-
if err := rpc.Register(NewClipboard(res.connCh, res.params)); err != nil {
31+
if err := rpc.Register(NewClipboard(res.connCh, res.params, res.debug)); err != nil {
3032
return nil, fmt.Errorf("unable to register Clipboard rpc: %w", err)
3133
}
3234

citrus/uri.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import (
1313
type URI struct {
1414
connCh chan net.Conn
1515
params ParamsValue
16+
debug bool
1617
}
1718

1819
// NewURI initializes URI structure.
19-
func NewURI(ch chan net.Conn, params ParamsValue) *URI {
20+
func NewURI(ch chan net.Conn, params ParamsValue, debug bool) *URI {
2021
return &URI{
2122
connCh: ch,
2223
params: params,
24+
debug: debug,
2325
}
2426
}
2527

@@ -32,10 +34,16 @@ type OpenParam struct {
3234
// Open is implementation of "lemonade" rpc "open" command.
3335
func (u *URI) Open(param *OpenParam, _ *struct{}) error {
3436
conn := <-u.connCh
37+
if u.debug {
38+
log.Printf("lemonade URI parameters received: '%v'", *param)
39+
}
3540
uri := param.URI
3641
if param.TransLoopback {
3742
uri = translateLoopbackIP(param.URI, conn)
3843
}
44+
if u.debug {
45+
log.Printf("lemonade run URI: '%s'", uri)
46+
}
3947
return open.Run(uri)
4048
}
4149

gui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func main() {
320320
var lemonade *citrus.Citrus
321321
if lemon.IsSet() {
322322
log.Printf("Starting lemonade server on '%s'", lemon.String())
323-
if lemonade, err = citrus.NewCitrus(lemon); err != nil {
323+
if lemonade, err = citrus.NewCitrus(lemon, debug); err != nil {
324324
util.ShowOKMessage(util.MsgError, title, err.Error())
325325
os.Exit(1)
326326
} else {

0 commit comments

Comments
 (0)