Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching to references #24

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
#
bin/

.idea/
.vscode/
18 changes: 13 additions & 5 deletions brimfeather/feather_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
cap2 "github.com/trimble-oss/tierceron-hat/cap"
captiplib "github.com/trimble-oss/tierceron-hat/captip/captiplib"
"os"
"sync"
"testing"

cap2 "github.com/trimble-oss/tierceron-hat/cap"
captiplib "github.com/trimble-oss/tierceron-hat/captip/captiplib"
)

func featherInterrupted(featherCtx *cap2.FeatherContext) error {
Expand All @@ -22,10 +23,17 @@ func TestGetSaltyGuardian(t *testing.T) {
go func() {
go cap2.Feather("Som18vhjqa72935h", "1cx7v89as7df89", "127.0.0.1:1832", "ThisIsACode", func(int, string) bool { return true })

cap2.TapFeather("I think", "therefore I am.")
cap2.TapFeather("It is not enough to have a good mind.", "The main thing is to use it well.")
keyvar := new(string)
*keyvar = "therefore I am."
cap2.TapFeather("I think", keyvar)

keyvar2 := new(string)
*keyvar2 = "The main thing is to use it well."
cap2.TapFeather("It is not enough to have a good mind.", keyvar2)

cap2.TapFeather("Ponder", "a feather.")
keyvar3 := new(string)
*keyvar3 = "a feather."
cap2.TapFeather("Ponder", keyvar3)

go cap2.TapServer("127.0.0.1:1534")
serverStart.Done()
Expand Down
12 changes: 6 additions & 6 deletions cap/cap.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ type FeatherContext struct {
Log *log.Logger
}

var penseMemoryMap map[string]string = map[string]string{}
var penseMemoryMap map[string]*string = map[string]*string{}

var penseFeatherCodeMap = cmap.New[string]()
var penseFeatherMemoryMap map[string]string = map[string]string{}
var penseFeatherMemoryMap map[string]*string = map[string]*string{}

var penseFeatherPluckMap = cmap.New[bool]()
var penseFeatherCtlCodeMap = cmap.New[string]()
Expand Down Expand Up @@ -491,12 +491,12 @@ func FeatherWriter(featherCtx *FeatherContext, pense string) ([]byte, error) {
return responseBuf[:n], penseResponseErr
}

func TapFeather(penseIndex, memory string) {
func TapFeather(penseIndex string, memory *string) {
penseMemoryMap[penseIndex] = memory
penseFeatherMemoryMap[penseIndex] = memory
}

func TapMemorize(penseIndex, memory string) {
func TapMemorize(penseIndex string, memory *string) {
penseMemoryMap[penseIndex] = memory
}

Expand All @@ -511,7 +511,7 @@ func (cs *penseServer) Pense(ctx context.Context, penseRequest *PenseRequest) (*

if _, penseCodeOk := tap.PenseCode(penseCode); penseCodeOk {
if pense, penseOk := penseMemoryMap[penseRequest.PenseIndex]; penseOk {
return &PenseReply{Pense: pense}, nil
return &PenseReply{Pense: *pense}, nil
} else {
return &PenseReply{Pense: "Pense undefined"}, nil
}
Expand All @@ -520,7 +520,7 @@ func (cs *penseServer) Pense(ctx context.Context, penseRequest *PenseRequest) (*
if _, penseCodeOk := penseFeatherCodeMap.Get(penseCode); penseCodeOk {
penseFeatherCodeMap.Remove(penseCode)
if pense, penseOk := penseFeatherMemoryMap[penseRequest.PenseIndex]; penseOk {
return &PenseReply{Pense: pense}, nil
return &PenseReply{Pense: *pense}, nil
} else {
return &PenseReply{Pense: "Pense undefined"}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions cap/tap/tap_common.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tap

var penseEyeMap map[string]string = map[string]string{}
var penseEyeMap map[string]*string = map[string]*string{}
var penseCodeMap map[string]string = map[string]string{}

func TapEyeRemember(penseIndex, memory string) {
func TapEyeRemember(penseIndex string, memory *string) {
penseEyeMap[penseIndex] = memory
}

Expand Down
12 changes: 9 additions & 3 deletions crown/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ func main() {
tapMap := map[string]string{brimPath: "2c1d03a2869e2040bbd125661f49d4bca2b9b0751ec92d0119a744edc31932ff"}
go tap.Tap(penseDir, tapMap, "", false)

tap.TapEyeRemember("eye", "rememeber")
cap.TapMemorize("I think", "therefore I am.")
cap.TapMemorize("It is not enough to have a good mind.", "The main thing is to use it well.")
keyvar := new(string)
*keyvar = "rememeber"
tap.TapEyeRemember("eye", keyvar)
keyvar2 := new(string)
*keyvar2 = "therefore I am."
cap.TapMemorize("I think", keyvar2)
keyvar3 := new(string)
*keyvar3 = "The main thing is to use it well."
cap.TapMemorize("It is not enough to have a good mind.", keyvar3)

cap.TapServer("127.0.0.1:1534")
}
18 changes: 14 additions & 4 deletions tiara/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ func main() {
fmt.Println("Starting tiara")
go cap.Feather("Som18vhjqa72935h", "1cx7v89as7df89", "127.0.0.1:1832", "ThisIsACode", func(int, string) bool { return true })

cap.TapFeather("I think", "therefore I am.")
cap.TapFeather("It is not enough to have a good mind.", "The main thing is to use it well.")
keyvar := new(string)
*keyvar = "therefore I am."
cap.TapFeather("I think", keyvar)

cap.TapMemorize("Ponder", "me this.")
cap.TapFeather("Ponder", "a feather.")
keyvar2 := new(string)
*keyvar2 = "The main thing is to use it well."
cap.TapFeather("It is not enough to have a good mind.", keyvar2)

keyvar3 := new(string)
*keyvar3 = "me this."
cap.TapMemorize("Ponder", keyvar3)

keyvar4 := new(string)
*keyvar4 = "a feather."
cap.TapFeather("Ponder", keyvar4)

cap.TapServer("127.0.0.1:1534")
}