Browse Source

update npc sdk and version

刘河 5 years ago
parent
commit
01a4bcf13d
2 changed files with 33 additions and 12 deletions
  1. 8 2
      .travis.yml
  2. 25 10
      cmd/npc/sdk.go

+ 8 - 2
.travis.yml

@@ -7,7 +7,9 @@ services:
   - docker
 script:
   - go test -v ./cmd/nps/
-
+os:
+  - linux
+  - windows
 before_deploy:
   - wget https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz
   - tar -xvf upx-3.95-amd64_linux.tar.xz
@@ -162,7 +164,7 @@ before_deploy:
 
   - tar -czvf win_386_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key  conf/server.pem web/views web/static nps.exe
 
-  - export VERSION=0.24.2
+  - export VERSION=0.24.3
   - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
   - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
   - sudo apt-get update
@@ -174,6 +176,9 @@ before_deploy:
   - docker exec -it spksrc /bin/bash -c 'cd /spksrc && make setup && cd /spksrc/spk/npc && make'
   - cp ~/spksrc/packages/npc_noarch-all_$VERSION-1.spk ./npc_$VERSION.spk
 
+  - if [ "$TRAVIS_OS_NAME" = "windows" ]; then go build -buildmode=c-shared -o npc_sdk.dll cmd\npc\sdk.go    ; fi
+  - tar -czvf npc_sdk.tar.gz npc_sdk.dll npc_sdk.h
+
   - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
   - export DOCKER_CLI_EXPERIMENTAL=enabled
   - docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
@@ -220,6 +225,7 @@ deploy:
   - win_amd64_client.tar.gz
   - win_amd64_server.tar.gz
   - npc_$VERSION.spk
+  - nnpc_sdk.tar.gz
   on:
     tags: true
     all_branches: true

+ 25 - 10
cmd/npc/sdk.go

@@ -2,32 +2,47 @@ package main
 
 import "C"
 import (
-	"fmt"
 	"github.com/cnlh/nps/client"
 	"time"
 )
 
-//export PrintBye
-func PrintBye() {
-	fmt.Println("From DLL: Bye!")
-}
-
 var status bool
+var closeBefore bool
+var cl *client.TRPClient
 
-//export Sum
-func StartClientByVerifyKey(a int, b int) bool {
-	c := client.NewRPClient(*serverAddr, *verifyKey, *connType, *proxyUrl, nil)
+//export StartClientByVerifyKey
+func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl string) bool {
+	if cl != nil {
+		closeBefore = true
+		cl.Close()
+	}
+	cl = client.NewRPClient(serverAddr, verifyKey, connType, proxyUrl, nil)
+	closeBefore = false
 	go func() {
 		for {
 			status = true
-			c.Start()
+			cl.Start()
 			status = false
+			if closeBefore {
+				return
+			}
 			time.Sleep(time.Second * 5)
 		}
 	}()
 	return true
 }
 
+//export GetClientStatus
+func GetClientStatus() bool {
+	return status
+}
+
+//export CloseClient
+func CloseClient() {
+	cl.Close()
+	closeBefore = true
+}
+
 func main() {
 	// Need a main function to make CGO compile package as C shared library
 }