Initial commit
This commit is contained in:
63
.golangci.yaml
Normal file
63
.golangci.yaml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
run:
|
||||||
|
tests: false
|
||||||
|
skip-dirs:
|
||||||
|
- vendor
|
||||||
|
modules-download-mode: readonly
|
||||||
|
allow-parallel-runners: true
|
||||||
|
go: '1.21'
|
||||||
|
output:
|
||||||
|
sort-results: true
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- errcheck
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
- unused
|
||||||
|
- asasalint
|
||||||
|
- asciicheck
|
||||||
|
- bodyclose
|
||||||
|
- containedctx
|
||||||
|
- contextcheck
|
||||||
|
- decorder
|
||||||
|
- durationcheck
|
||||||
|
- errchkjson
|
||||||
|
- errorlint
|
||||||
|
- exhaustive
|
||||||
|
- exhaustruct
|
||||||
|
- exportloopref
|
||||||
|
- ginkgolinter
|
||||||
|
- gci
|
||||||
|
- gocheckcompilerdirectives
|
||||||
|
- gocritic
|
||||||
|
- godot
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- gosec
|
||||||
|
- gosmopolitan
|
||||||
|
- grouper
|
||||||
|
- importas
|
||||||
|
- ireturn
|
||||||
|
- makezero
|
||||||
|
- mirror
|
||||||
|
- nakedret
|
||||||
|
- nilerr
|
||||||
|
- nilnil
|
||||||
|
- nlreturn
|
||||||
|
- noctx
|
||||||
|
- nolintlint
|
||||||
|
- nonamedreturns
|
||||||
|
- predeclared
|
||||||
|
- promlinter
|
||||||
|
- reassign
|
||||||
|
- revive
|
||||||
|
- rowserrcheck
|
||||||
|
- stylecheck
|
||||||
|
- unconvert
|
||||||
|
- wastedassign
|
||||||
|
- whitespace
|
||||||
|
- wsl
|
||||||
|
|
||||||
|
# vim: set ft=yaml noet ai ts=4 sw=4 sts=4:
|
||||||
127
.reniced.yaml.example
Normal file
127
.reniced.yaml.example
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
cmd_delay: 33
|
||||||
|
loop_delay: 5000
|
||||||
|
debug: true
|
||||||
|
|
||||||
|
kill:
|
||||||
|
- sig: stop
|
||||||
|
name:
|
||||||
|
- commvault
|
||||||
|
- distnoted
|
||||||
|
- coreduetd
|
||||||
|
|
||||||
|
prio:
|
||||||
|
- nice: -11
|
||||||
|
name:
|
||||||
|
- coreaudiod
|
||||||
|
- WindowServer
|
||||||
|
- "com.apple.audio.SandboxHelper"
|
||||||
|
- "com.apple.audio.DriverHelper"
|
||||||
|
- audioclocksyncd
|
||||||
|
|
||||||
|
- nice: -5
|
||||||
|
name:
|
||||||
|
- VTDecoderXPCService
|
||||||
|
- "VK Teams"
|
||||||
|
- mDNSResponder
|
||||||
|
- mDNSResponderHelper
|
||||||
|
- AudioComponentRegistrar
|
||||||
|
- CVMServer
|
||||||
|
|
||||||
|
- nice: -3
|
||||||
|
name:
|
||||||
|
- "Karabiner-Elements"
|
||||||
|
- Hammerspoon
|
||||||
|
- MTLCompilerService
|
||||||
|
- "com.apple.appkit.xpc.openAndSavePanelService"
|
||||||
|
|
||||||
|
- nice: 3
|
||||||
|
name:
|
||||||
|
- logd
|
||||||
|
- syslogd
|
||||||
|
- syspolicyd
|
||||||
|
- cron
|
||||||
|
- softwareupdated
|
||||||
|
- "periodic-wrapper"
|
||||||
|
- iconservicesagent
|
||||||
|
- "com.apple.quicklook.ThumbnailsAgent"
|
||||||
|
- appstored
|
||||||
|
|
||||||
|
- nice: 5
|
||||||
|
name:
|
||||||
|
- corebrightnessd
|
||||||
|
- airportd
|
||||||
|
- containermanagerd
|
||||||
|
- searchpartyd
|
||||||
|
- corespeechd
|
||||||
|
- peopled
|
||||||
|
- AssetCacheLocatorService
|
||||||
|
- avatarsd
|
||||||
|
- contactsdonationagent
|
||||||
|
- storedownloadd
|
||||||
|
- "Dock.app"
|
||||||
|
- Dock
|
||||||
|
- Finder
|
||||||
|
- DockHelper
|
||||||
|
|
||||||
|
- nice: 9
|
||||||
|
name:
|
||||||
|
- "Google Chrome"
|
||||||
|
- "Google Chrome Helper"
|
||||||
|
- "EmojiFunction"
|
||||||
|
- "Microsoft Edge Helper"
|
||||||
|
- "Opera Helper"
|
||||||
|
- "UserNotificationCenter"
|
||||||
|
|
||||||
|
- nice: 11
|
||||||
|
name:
|
||||||
|
- siriactionsd
|
||||||
|
- CoreSpotlightService
|
||||||
|
- spotlightknowledged
|
||||||
|
- Spotlight
|
||||||
|
- suggestd
|
||||||
|
- studentd
|
||||||
|
- "com.apple.siri-distributed-evaluation"
|
||||||
|
- "com.apple.CloudPhotosConfiguration"
|
||||||
|
|
||||||
|
- nice: 19
|
||||||
|
name:
|
||||||
|
- coreduetd
|
||||||
|
- endpointsecurityd
|
||||||
|
- analyticsd
|
||||||
|
- backupd
|
||||||
|
- com.apple.CodeSigningHelper
|
||||||
|
- distnoted
|
||||||
|
- "backupd-helper"
|
||||||
|
- JamfDaemon
|
||||||
|
- osqueryd
|
||||||
|
- commvault
|
||||||
|
- diagnosticd
|
||||||
|
- JamfProCommService
|
||||||
|
- XprotectService
|
||||||
|
- XProtectPluginService
|
||||||
|
- "media-indexer"
|
||||||
|
- "com.apple.Safari.SafeBrowsing.Service"
|
||||||
|
- SafariNotificationAgent
|
||||||
|
- AMPArtworkAgent
|
||||||
|
- AMPLibraryAgent
|
||||||
|
- IDSBlastDoorService
|
||||||
|
- photoanalysisd
|
||||||
|
- photolibraryd
|
||||||
|
- "Crash Reports"
|
||||||
|
- mds
|
||||||
|
- mds_stores
|
||||||
|
- mdsync
|
||||||
|
- mdbulkimport
|
||||||
|
- mdworker_shared
|
||||||
|
- osqueryd
|
||||||
|
- opendirectoryd
|
||||||
|
- mediaanalysisd
|
||||||
|
- klnagent
|
||||||
|
- kavd
|
||||||
|
- biomesyncd
|
||||||
|
- siriknowledged
|
||||||
|
- triald
|
||||||
|
- syspolicyd
|
||||||
|
|
||||||
|
|
||||||
|
# vim: set ft=yaml et ai ts=2 sw=2 sts=2:
|
||||||
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright © 2024 Sergei Fedosoff, <eleksir@gmail.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the “Software”), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
22
Makefile
Normal file
22
Makefile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env gmake -f
|
||||||
|
|
||||||
|
BUILDOPTS=-ldflags="-s -w" -a -gcflags=all=-l -trimpath
|
||||||
|
FILELIST=main.go types.go util.go
|
||||||
|
|
||||||
|
BINARY=reniced
|
||||||
|
|
||||||
|
all: clean build
|
||||||
|
|
||||||
|
build:
|
||||||
|
go build ${BUILDOPTS} -o ${BINARY} ${FILELIST}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
go clean
|
||||||
|
|
||||||
|
upgrade:
|
||||||
|
$(RM) -r vendor
|
||||||
|
go get -d -u -t ./...
|
||||||
|
go mod tidy
|
||||||
|
go mod vendor
|
||||||
|
|
||||||
|
# vim: set ft=make noet ai ts=4 sw=4 sts=4:
|
||||||
47
README.md
Normal file
47
README.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# Reniced
|
||||||
|
|
||||||
|
Helper utility intended to run as a service or as background process (say in tmux) that can make system more respositive
|
||||||
|
under certain load.
|
||||||
|
|
||||||
|
## Why it was made
|
||||||
|
|
||||||
|
In general case os can handle load well fairly share resources among processes. But in some cases it make it poorly.
|
||||||
|
As an exanple it can be ill-minded pseudo-security stuff like antiviruses or mediaanalysers that searches forbidden
|
||||||
|
content on your mac (due to gov.polices that apple have to accept). Or it can be backup that crawls in background.
|
||||||
|
|
||||||
|
To help resolve such situation this utility was made. Some malicious processes can be renice to lower nicelevels (say,
|
||||||
|
19) and for some good processes nicelevel can be rised to higher values(-19 if reniced run as superuser or 0 if as
|
||||||
|
normal).
|
||||||
|
|
||||||
|
In some critical cases process can be killed (if you want to know more about it see "man kill" in terminal).
|
||||||
|
|
||||||
|
## How to build, configure, run it
|
||||||
|
|
||||||
|
You will need Go lang 1.21 or newer, gnu make, terminal and possibly internets to build this utility.
|
||||||
|
|
||||||
|
To build reniced just type in src dir
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
this will produce binary named "reniced".
|
||||||
|
|
||||||
|
Copy to your home directory .reniced.yaml.example as .reniced.yaml and edit it to suit your needs. After you done, you
|
||||||
|
can run utility as:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./reniced
|
||||||
|
```
|
||||||
|
|
||||||
|
if you have no access to superuser or
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ./reniced
|
||||||
|
```
|
||||||
|
|
||||||
|
if you can sudo. Thats it.
|
||||||
|
|
||||||
|
## Special "thanks"
|
||||||
|
|
||||||
|
To security assholes that disrupt workflows and make this world worse.
|
||||||
19
go.mod
Normal file
19
go.mod
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
module reniced
|
||||||
|
|
||||||
|
go 1.21.4
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/shirou/gopsutil/v3 v3.24.2
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a // indirect
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
|
||||||
|
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
||||||
|
github.com/tklauser/go-sysconf v0.3.13 // indirect
|
||||||
|
github.com/tklauser/numcpus v0.7.0 // indirect
|
||||||
|
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||||
|
golang.org/x/sys v0.18.0 // indirect
|
||||||
|
)
|
||||||
53
go.sum
Normal file
53
go.sum
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
|
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||||
|
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||||
|
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a h1:3Bm7EwfUQUvhNeKIkUct/gl9eod1TcXuj8stxvi/GoI=
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||||
|
github.com/shirou/gopsutil/v3 v3.24.2 h1:kcR0erMbLg5/3LcInpw0X/rrPSqq4CDPyI6A6ZRC18Y=
|
||||||
|
github.com/shirou/gopsutil/v3 v3.24.2/go.mod h1:tSg/594BcA+8UdQU2XcW803GWYgdtauFFPgJCJKZlVk=
|
||||||
|
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
|
||||||
|
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
|
||||||
|
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
|
||||||
|
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08lq3r4=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0=
|
||||||
|
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
|
||||||
|
github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4=
|
||||||
|
github.com/tklauser/numcpus v0.7.0/go.mod h1:bb6dMVcj8A42tSE7i32fsIUCbQNllK5iDguyOZRUzAY=
|
||||||
|
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||||
|
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||||
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||||
|
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
181
main.go
Normal file
181
main.go
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
proc "github.com/shirou/gopsutil/v3/process"
|
||||||
|
)
|
||||||
|
|
||||||
|
// main основная функция программы.
|
||||||
|
func main() {
|
||||||
|
if os.Getenv("HOME") == "" {
|
||||||
|
log.Fatalln("Unable to get HOME environment variable value")
|
||||||
|
}
|
||||||
|
|
||||||
|
cnf, err := readConf(os.Getenv("HOME") + "/.reniced.yaml")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("unable to parse config: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Основной цикл.
|
||||||
|
for {
|
||||||
|
processList, err := proc.Processes()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Unable to get process list: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Не самый эффективный, зато работающий способ - простой перебор массивов.
|
||||||
|
for _, p := range processList {
|
||||||
|
if processName, err := p.Name(); err == nil {
|
||||||
|
for _, k := range cnf.Kill {
|
||||||
|
for _, killProcessName := range k.Name {
|
||||||
|
if processName == killProcessName {
|
||||||
|
switch k.Sig {
|
||||||
|
case "kill":
|
||||||
|
_ = p.SendSignal(syscall.SIGKILL)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "stop":
|
||||||
|
if s, err := p.Status(); err == nil && s[0] != "stop" {
|
||||||
|
_ = p.SendSignal(syscall.SIGSTOP)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if err == nil && s[0] == "stop" && cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s) and it is already stopped",
|
||||||
|
processName,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "term":
|
||||||
|
_ = p.SendSignal(syscall.SIGTERM)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "int":
|
||||||
|
_ = p.SendSignal(syscall.SIGINT)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "quit":
|
||||||
|
_ = p.SendSignal(syscall.SIGQUIT)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "abrt":
|
||||||
|
_ = p.SendSignal(syscall.SIGABRT)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "hup":
|
||||||
|
_ = p.SendSignal(syscall.SIGHUP)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "usr1":
|
||||||
|
_ = p.SendSignal(syscall.SIGUSR1)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "usr2":
|
||||||
|
_ = p.SendSignal(syscall.SIGUSR2)
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||||
|
processName,
|
||||||
|
strings.ToUpper(k.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Для каждого процесса извлекаем его текущий nicelevel.
|
||||||
|
if currentNiceLevel, err := p.Nice(); err == nil {
|
||||||
|
// Вынимаем список приоритетов.
|
||||||
|
for _, n := range cnf.Prio {
|
||||||
|
// Для каждого приоритета, проходимся по списку имён процессов.
|
||||||
|
for _, name := range n.Name {
|
||||||
|
// Достаём имя текущего процесса.
|
||||||
|
if processName, err = p.Name(); err == nil {
|
||||||
|
// Если имя процесса совпадает с одним из списка в конфиге, то пробуем менять ему nice.
|
||||||
|
if processName == name {
|
||||||
|
if currentNiceLevel != n.Nice {
|
||||||
|
_ = syscall.Setpriority(syscall.PRIO_PROCESS, int(p.Pid), int(n.Nice))
|
||||||
|
|
||||||
|
if cnf.Debug {
|
||||||
|
log.Printf(
|
||||||
|
"Set niceness for %s(%d) to %d (was %d)",
|
||||||
|
name,
|
||||||
|
p.Pid,
|
||||||
|
n.Nice,
|
||||||
|
currentNiceLevel,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if cnf.Debug {
|
||||||
|
log.Printf("Nicelevel for %d already set to %d", p.Pid, n.Nice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(cnf.CmdDelay))
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(cnf.LoopDelay))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||||
31
types.go
Normal file
31
types.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
// LoopDelay in milliseconds - whole set of action delay period.
|
||||||
|
LoopDelay int `yaml:"loop_delay"`
|
||||||
|
|
||||||
|
// CmdDelay in milliseconds - delay between each change application.
|
||||||
|
CmdDelay int `yaml:"cmd_delay"`
|
||||||
|
|
||||||
|
// Whether to print debug info on stdout.
|
||||||
|
Debug bool `yaml:"debug,omitempty"`
|
||||||
|
|
||||||
|
// В гошке yaml не позволяет сделать удобный парсер для конструкций, аналогичных json-овскому
|
||||||
|
// {kill:{"stop":["proc1","proc2"], "term":["proc3","proc4"]}}
|
||||||
|
// Поэтому мы просто возьмём массив и каждому элементу добавим тип сигнала.
|
||||||
|
Kill Kill `yaml:"kill,omitempty"`
|
||||||
|
|
||||||
|
Prio Prio `yaml:"prio,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Prio []struct {
|
||||||
|
Nice int32 `yaml:"nice,omitempty"`
|
||||||
|
Name []string `yaml:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Kill []struct {
|
||||||
|
Sig string `yaml:"sig,omitempty"`
|
||||||
|
Name []string `yaml:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||||
117
util.go
Normal file
117
util.go
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
// readConf парсит даденный конфиг в глобальную структуру, с которой работает программа.
|
||||||
|
func readConf(path string) (Config, error) {
|
||||||
|
var cfg Config
|
||||||
|
|
||||||
|
fileInfo, err := os.Stat(path)
|
||||||
|
|
||||||
|
// Предполагаем, что файла либо нет, либо мы не можем его прочитать, второе надо бы логгировать, но пока забьём.
|
||||||
|
if err != nil {
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Конфиг-файл длинноват для конфига, попробуем следующего кандидата.
|
||||||
|
if fileInfo.Size() > 65535 {
|
||||||
|
err := fmt.Errorf("Config file %s is too long for config, skipping", path)
|
||||||
|
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
buf, err := os.ReadFile(path)
|
||||||
|
|
||||||
|
// Не удалось прочитать.
|
||||||
|
if err != nil {
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = yaml.Unmarshal(buf, &cfg); err != nil {
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.CmdDelay == 0 {
|
||||||
|
log.Println("cmd_delay can not be 0, setting to 200 milliseconds")
|
||||||
|
|
||||||
|
cfg.CmdDelay = 200
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.LoopDelay == 0 {
|
||||||
|
log.Println("loop_delay can not be 0, setting to 2000 milliseconds")
|
||||||
|
|
||||||
|
cfg.LoopDelay = 2000
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Debug {
|
||||||
|
log.Println("debug set to true")
|
||||||
|
} else {
|
||||||
|
log.Println("debug set to false")
|
||||||
|
}
|
||||||
|
|
||||||
|
newPrio := make(Prio, 0)
|
||||||
|
|
||||||
|
// Обычный юзер не может задрать nice больше 0, только руту такое можно.
|
||||||
|
var maxNice int32
|
||||||
|
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
maxNice = -20
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range cfg.Prio {
|
||||||
|
switch {
|
||||||
|
case len(v.Name) != 0 && (v.Nice < 20 && v.Nice > maxNice):
|
||||||
|
newPrio = append(newPrio, v)
|
||||||
|
|
||||||
|
if cfg.Debug {
|
||||||
|
for _, procName := range v.Name {
|
||||||
|
log.Printf("Add %s to list of nicelevel %d processes.", procName, v.Nice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case len(v.Name) == 0:
|
||||||
|
log.Println("Skipping empty entry in prio config block")
|
||||||
|
case v.Nice > 20 || v.Nice < maxNice:
|
||||||
|
log.Printf("Niceness value out of range %d < nice < 20 in prio config block", maxNice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.Prio = newPrio
|
||||||
|
|
||||||
|
newKill := make(Kill, 0)
|
||||||
|
|
||||||
|
for _, v := range cfg.Kill {
|
||||||
|
if len(v.Name) != 0 {
|
||||||
|
switch v.Sig {
|
||||||
|
case "kill", "stop", "term", "int", "quit", "abrt", "hup", "usr1", "usr2":
|
||||||
|
newKill = append(newKill, v)
|
||||||
|
|
||||||
|
if cfg.Debug {
|
||||||
|
for _, procName := range v.Name {
|
||||||
|
log.Printf(
|
||||||
|
"Add %s to list of processes that should be killed with SIG%s signal.",
|
||||||
|
procName,
|
||||||
|
strings.ToUpper(v.Sig),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Println("Skipping unsupported signal entry in kill config block")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Println("Skipping empty entry in kill config block")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.Kill = newKill
|
||||||
|
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||||
8
vendor/github.com/go-ole/go-ole/.travis.yml
generated
vendored
Normal file
8
vendor/github.com/go-ole/go-ole/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
language: go
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.9.x
|
||||||
|
- 1.10.x
|
||||||
|
- 1.11.x
|
||||||
|
- tip
|
||||||
49
vendor/github.com/go-ole/go-ole/ChangeLog.md
generated
vendored
Normal file
49
vendor/github.com/go-ole/go-ole/ChangeLog.md
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# Version 1.x.x
|
||||||
|
|
||||||
|
* **Add more test cases and reference new test COM server project.** (Placeholder for future additions)
|
||||||
|
|
||||||
|
# Version 1.2.0-alphaX
|
||||||
|
|
||||||
|
**Minimum supported version is now Go 1.4. Go 1.1 support is deprecated, but should still build.**
|
||||||
|
|
||||||
|
* Added CI configuration for Travis-CI and AppVeyor.
|
||||||
|
* Added test InterfaceID and ClassID for the COM Test Server project.
|
||||||
|
* Added more inline documentation (#83).
|
||||||
|
* Added IEnumVARIANT implementation (#88).
|
||||||
|
* Added IEnumVARIANT test cases (#99, #100, #101).
|
||||||
|
* Added support for retrieving `time.Time` from VARIANT (#92).
|
||||||
|
* Added test case for IUnknown (#64).
|
||||||
|
* Added test case for IDispatch (#64).
|
||||||
|
* Added test cases for scalar variants (#64, #76).
|
||||||
|
|
||||||
|
# Version 1.1.1
|
||||||
|
|
||||||
|
* Fixes for Linux build.
|
||||||
|
* Fixes for Windows build.
|
||||||
|
|
||||||
|
# Version 1.1.0
|
||||||
|
|
||||||
|
The change to provide building on all platforms is a new feature. The increase in minor version reflects that and allows those who wish to stay on 1.0.x to continue to do so. Support for 1.0.x will be limited to bug fixes.
|
||||||
|
|
||||||
|
* Move GUID out of variables.go into its own file to make new documentation available.
|
||||||
|
* Move OleError out of ole.go into its own file to make new documentation available.
|
||||||
|
* Add documentation to utility functions.
|
||||||
|
* Add documentation to variant receiver functions.
|
||||||
|
* Add documentation to ole structures.
|
||||||
|
* Make variant available to other systems outside of Windows.
|
||||||
|
* Make OLE structures available to other systems outside of Windows.
|
||||||
|
|
||||||
|
## New Features
|
||||||
|
|
||||||
|
* Library should now be built on all platforms supported by Go. Library will NOOP on any platform that is not Windows.
|
||||||
|
* More functions are now documented and available on godoc.org.
|
||||||
|
|
||||||
|
# Version 1.0.1
|
||||||
|
|
||||||
|
1. Fix package references from repository location change.
|
||||||
|
|
||||||
|
# Version 1.0.0
|
||||||
|
|
||||||
|
This version is stable enough for use. The COM API is still incomplete, but provides enough functionality for accessing COM servers using IDispatch interface.
|
||||||
|
|
||||||
|
There is no changelog for this version. Check commits for history.
|
||||||
21
vendor/github.com/go-ole/go-ole/LICENSE
generated
vendored
Normal file
21
vendor/github.com/go-ole/go-ole/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright © 2013-2017 Yasuhiro Matsumoto, <mattn.jp@gmail.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the “Software”), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
46
vendor/github.com/go-ole/go-ole/README.md
generated
vendored
Normal file
46
vendor/github.com/go-ole/go-ole/README.md
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Go OLE
|
||||||
|
|
||||||
|
[](https://ci.appveyor.com/project/jacobsantos/go-ole-jgs28)
|
||||||
|
[](https://travis-ci.org/go-ole/go-ole)
|
||||||
|
[](https://godoc.org/github.com/go-ole/go-ole)
|
||||||
|
|
||||||
|
Go bindings for Windows COM using shared libraries instead of cgo.
|
||||||
|
|
||||||
|
By Yasuhiro Matsumoto.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
To experiment with go-ole, you can just compile and run the example program:
|
||||||
|
|
||||||
|
```
|
||||||
|
go get github.com/go-ole/go-ole
|
||||||
|
cd /path/to/go-ole/
|
||||||
|
go test
|
||||||
|
|
||||||
|
cd /path/to/go-ole/example/excel
|
||||||
|
go run excel.go
|
||||||
|
```
|
||||||
|
|
||||||
|
## Continuous Integration
|
||||||
|
|
||||||
|
Continuous integration configuration has been added for both Travis-CI and AppVeyor. You will have to add these to your own account for your fork in order for it to run.
|
||||||
|
|
||||||
|
**Travis-CI**
|
||||||
|
|
||||||
|
Travis-CI was added to check builds on Linux to ensure that `go get` works when cross building. Currently, Travis-CI is not used to test cross-building, but this may be changed in the future. It is also not currently possible to test the library on Linux, since COM API is specific to Windows and it is not currently possible to run a COM server on Linux or even connect to a remote COM server.
|
||||||
|
|
||||||
|
**AppVeyor**
|
||||||
|
|
||||||
|
AppVeyor is used to build on Windows using the (in-development) test COM server. It is currently only used to test the build and ensure that the code works on Windows. It will be used to register a COM server and then run the test cases based on the test COM server.
|
||||||
|
|
||||||
|
The tests currently do run and do pass and this should be maintained with commits.
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
Go OLE uses [semantic versioning](http://semver.org) for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch.
|
||||||
|
|
||||||
|
This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed.
|
||||||
|
|
||||||
|
## LICENSE
|
||||||
|
|
||||||
|
Under the MIT License: http://mattn.mit-license.org/2013
|
||||||
13
vendor/github.com/go-ole/go-ole/SECURITY.md
generated
vendored
Normal file
13
vendor/github.com/go-ole/go-ole/SECURITY.md
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
Security updates are applied only to the latest release.
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released.
|
||||||
|
|
||||||
|
Please disclose it at [security advisory](https://github.com/go-ole/go-ole/security/advisories/new).
|
||||||
|
|
||||||
|
This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure.
|
||||||
68
vendor/github.com/go-ole/go-ole/appveyor.yml
generated
vendored
Normal file
68
vendor/github.com/go-ole/go-ole/appveyor.yml
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# Notes:
|
||||||
|
# - Minimal appveyor.yml file is an empty file. All sections are optional.
|
||||||
|
# - Indent each level of configuration with 2 spaces. Do not use tabs!
|
||||||
|
# - All section names are case-sensitive.
|
||||||
|
# - Section names should be unique on each level.
|
||||||
|
|
||||||
|
version: "1.3.0.{build}-alpha-{branch}"
|
||||||
|
|
||||||
|
os: Visual Studio 2019
|
||||||
|
|
||||||
|
build: off
|
||||||
|
|
||||||
|
skip_tags: true
|
||||||
|
|
||||||
|
clone_folder: c:\gopath\src\github.com\go-ole\go-ole
|
||||||
|
|
||||||
|
environment:
|
||||||
|
GOPATH: c:\gopath
|
||||||
|
GOROOT: c:\go
|
||||||
|
DOWNLOADPLATFORM: "x64"
|
||||||
|
|
||||||
|
before_test:
|
||||||
|
# - Download COM Server
|
||||||
|
- ps: Start-FileDownload "https://github.com/go-ole/test-com-server/releases/download/v1.0.2/test-com-server-${env:DOWNLOADPLATFORM}.zip"
|
||||||
|
- 7z e test-com-server-%DOWNLOADPLATFORM%.zip -oc:\gopath\src\github.com\go-ole\go-ole > NUL
|
||||||
|
- c:\gopath\src\github.com\go-ole\go-ole\build\register-assembly.bat
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- go test -v -cover ./...
|
||||||
|
# go vet has false positives on unsafe.Pointer with windows/sys. Disabling since it is recommended to use go test instead.
|
||||||
|
# - go vet ./...
|
||||||
|
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- v1.2
|
||||||
|
- v1.1
|
||||||
|
- v1.0
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- environment:
|
||||||
|
GOROOT: C:\go-x86
|
||||||
|
DOWNLOADPLATFORM: "x86"
|
||||||
|
- environment:
|
||||||
|
GOROOT: C:\go118
|
||||||
|
DOWNLOADPLATFORM: "x64"
|
||||||
|
- environment:
|
||||||
|
GOROOT: C:\go118-x86
|
||||||
|
DOWNLOADPLATFORM: "x86"
|
||||||
|
|
||||||
|
install:
|
||||||
|
- go version
|
||||||
|
- go env
|
||||||
|
- go get -u golang.org/x/tools/cmd/cover
|
||||||
|
- go get -u golang.org/x/tools/cmd/godoc
|
||||||
|
- go get -u golang.org/x/tools/cmd/stringer
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- cd c:\gopath\src\github.com\go-ole\go-ole
|
||||||
|
- go get -v -t ./...
|
||||||
|
- go build
|
||||||
|
|
||||||
|
# disable automatic tests
|
||||||
|
test: on
|
||||||
|
|
||||||
|
# disable deployment
|
||||||
|
deploy: off
|
||||||
386
vendor/github.com/go-ole/go-ole/com.go
generated
vendored
Normal file
386
vendor/github.com/go-ole/go-ole/com.go
generated
vendored
Normal file
@@ -0,0 +1,386 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unicode/utf16"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
procCoInitialize = modole32.NewProc("CoInitialize")
|
||||||
|
procCoInitializeEx = modole32.NewProc("CoInitializeEx")
|
||||||
|
procCoInitializeSecurity = modole32.NewProc("CoInitializeSecurity")
|
||||||
|
procCoUninitialize = modole32.NewProc("CoUninitialize")
|
||||||
|
procCoCreateInstance = modole32.NewProc("CoCreateInstance")
|
||||||
|
procCoTaskMemFree = modole32.NewProc("CoTaskMemFree")
|
||||||
|
procCLSIDFromProgID = modole32.NewProc("CLSIDFromProgID")
|
||||||
|
procCLSIDFromString = modole32.NewProc("CLSIDFromString")
|
||||||
|
procStringFromCLSID = modole32.NewProc("StringFromCLSID")
|
||||||
|
procStringFromIID = modole32.NewProc("StringFromIID")
|
||||||
|
procIIDFromString = modole32.NewProc("IIDFromString")
|
||||||
|
procCoGetObject = modole32.NewProc("CoGetObject")
|
||||||
|
procGetUserDefaultLCID = modkernel32.NewProc("GetUserDefaultLCID")
|
||||||
|
procCopyMemory = modkernel32.NewProc("RtlMoveMemory")
|
||||||
|
procVariantInit = modoleaut32.NewProc("VariantInit")
|
||||||
|
procVariantClear = modoleaut32.NewProc("VariantClear")
|
||||||
|
procVariantTimeToSystemTime = modoleaut32.NewProc("VariantTimeToSystemTime")
|
||||||
|
procSysAllocString = modoleaut32.NewProc("SysAllocString")
|
||||||
|
procSysAllocStringLen = modoleaut32.NewProc("SysAllocStringLen")
|
||||||
|
procSysFreeString = modoleaut32.NewProc("SysFreeString")
|
||||||
|
procSysStringLen = modoleaut32.NewProc("SysStringLen")
|
||||||
|
procCreateDispTypeInfo = modoleaut32.NewProc("CreateDispTypeInfo")
|
||||||
|
procCreateStdDispatch = modoleaut32.NewProc("CreateStdDispatch")
|
||||||
|
procGetActiveObject = modoleaut32.NewProc("GetActiveObject")
|
||||||
|
|
||||||
|
procGetMessageW = moduser32.NewProc("GetMessageW")
|
||||||
|
procDispatchMessageW = moduser32.NewProc("DispatchMessageW")
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is to enable calling COM Security initialization multiple times
|
||||||
|
var bSecurityInit bool = false
|
||||||
|
|
||||||
|
// coInitialize initializes COM library on current thread.
|
||||||
|
//
|
||||||
|
// MSDN documentation suggests that this function should not be called. Call
|
||||||
|
// CoInitializeEx() instead. The reason has to do with threading and this
|
||||||
|
// function is only for single-threaded apartments.
|
||||||
|
//
|
||||||
|
// That said, most users of the library have gotten away with just this
|
||||||
|
// function. If you are experiencing threading issues, then use
|
||||||
|
// CoInitializeEx().
|
||||||
|
func coInitialize() (err error) {
|
||||||
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms678543(v=vs.85).aspx
|
||||||
|
// Suggests that no value should be passed to CoInitialized.
|
||||||
|
// Could just be Call() since the parameter is optional. <-- Needs testing to be sure.
|
||||||
|
hr, _, _ := procCoInitialize.Call(uintptr(0))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// coInitializeEx initializes COM library with concurrency model.
|
||||||
|
func coInitializeEx(coinit uint32) (err error) {
|
||||||
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx
|
||||||
|
// Suggests that the first parameter is not only optional but should always be NULL.
|
||||||
|
hr, _, _ := procCoInitializeEx.Call(uintptr(0), uintptr(coinit))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// coInitializeSecurity: Registers security and sets the default security values
|
||||||
|
// for the process.
|
||||||
|
func coInitializeSecurity(cAuthSvc int32,
|
||||||
|
dwAuthnLevel uint32,
|
||||||
|
dwImpLevel uint32,
|
||||||
|
dwCapabilities uint32) (err error) {
|
||||||
|
// Check COM Security initialization has done previously
|
||||||
|
if !bSecurityInit {
|
||||||
|
// https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializesecurity
|
||||||
|
hr, _, _ := procCoInitializeSecurity.Call(
|
||||||
|
uintptr(0), // Allow *all* VSS writers to communicate back!
|
||||||
|
uintptr(cAuthSvc), // Default COM authentication service
|
||||||
|
uintptr(0), // Default COM authorization service
|
||||||
|
uintptr(0), // Reserved parameter
|
||||||
|
uintptr(dwAuthnLevel), // Strongest COM authentication level
|
||||||
|
uintptr(dwImpLevel), // Minimal impersonation abilities
|
||||||
|
uintptr(0), // Default COM authentication settings
|
||||||
|
uintptr(dwCapabilities), // Cloaking
|
||||||
|
uintptr(0)) // eserved parameter
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
} else {
|
||||||
|
// COM Security initialization done make global flag true.
|
||||||
|
bSecurityInit = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoInitialize initializes COM library on current thread.
|
||||||
|
//
|
||||||
|
// MSDN documentation suggests that this function should not be called. Call
|
||||||
|
// CoInitializeEx() instead. The reason has to do with threading and this
|
||||||
|
// function is only for single-threaded apartments.
|
||||||
|
//
|
||||||
|
// That said, most users of the library have gotten away with just this
|
||||||
|
// function. If you are experiencing threading issues, then use
|
||||||
|
// CoInitializeEx().
|
||||||
|
func CoInitialize(p uintptr) (err error) {
|
||||||
|
// p is ignored and won't be used.
|
||||||
|
// Avoid any variable not used errors.
|
||||||
|
p = uintptr(0)
|
||||||
|
return coInitialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoInitializeEx initializes COM library with concurrency model.
|
||||||
|
func CoInitializeEx(p uintptr, coinit uint32) (err error) {
|
||||||
|
// Avoid any variable not used errors.
|
||||||
|
p = uintptr(0)
|
||||||
|
return coInitializeEx(coinit)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoUninitialize uninitializes COM Library.
|
||||||
|
func CoUninitialize() {
|
||||||
|
procCoUninitialize.Call()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoInitializeSecurity: Registers security and sets the default security values
|
||||||
|
// for the process.
|
||||||
|
func CoInitializeSecurity(cAuthSvc int32,
|
||||||
|
dwAuthnLevel uint32,
|
||||||
|
dwImpLevel uint32,
|
||||||
|
dwCapabilities uint32) (err error) {
|
||||||
|
return coInitializeSecurity(cAuthSvc, dwAuthnLevel, dwImpLevel, dwCapabilities)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoTaskMemFree frees memory pointer.
|
||||||
|
func CoTaskMemFree(memptr uintptr) {
|
||||||
|
procCoTaskMemFree.Call(memptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.
|
||||||
|
//
|
||||||
|
// The Programmatic Identifier must be registered, because it will be looked up
|
||||||
|
// in the Windows Registry. The registry entry has the following keys: CLSID,
|
||||||
|
// Insertable, Protocol and Shell
|
||||||
|
// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).
|
||||||
|
//
|
||||||
|
// programID identifies the class id with less precision and is not guaranteed
|
||||||
|
// to be unique. These are usually found in the registry under
|
||||||
|
// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of
|
||||||
|
// "Program.Component.Version" with version being optional.
|
||||||
|
//
|
||||||
|
// CLSIDFromProgID in Windows API.
|
||||||
|
func CLSIDFromProgID(progId string) (clsid *GUID, err error) {
|
||||||
|
var guid GUID
|
||||||
|
lpszProgID := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
|
||||||
|
hr, _, _ := procCLSIDFromProgID.Call(lpszProgID, uintptr(unsafe.Pointer(&guid)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
clsid = &guid
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CLSIDFromString retrieves Class ID from string representation.
|
||||||
|
//
|
||||||
|
// This is technically the string version of the GUID and will convert the
|
||||||
|
// string to object.
|
||||||
|
//
|
||||||
|
// CLSIDFromString in Windows API.
|
||||||
|
func CLSIDFromString(str string) (clsid *GUID, err error) {
|
||||||
|
var guid GUID
|
||||||
|
lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
|
||||||
|
hr, _, _ := procCLSIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
clsid = &guid
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringFromCLSID returns GUID formated string from GUID object.
|
||||||
|
func StringFromCLSID(clsid *GUID) (str string, err error) {
|
||||||
|
var p *uint16
|
||||||
|
hr, _, _ := procStringFromCLSID.Call(uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(&p)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
str = LpOleStrToString(p)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IIDFromString returns GUID from program ID.
|
||||||
|
func IIDFromString(progId string) (clsid *GUID, err error) {
|
||||||
|
var guid GUID
|
||||||
|
lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
|
||||||
|
hr, _, _ := procIIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
clsid = &guid
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringFromIID returns GUID formatted string from GUID object.
|
||||||
|
func StringFromIID(iid *GUID) (str string, err error) {
|
||||||
|
var p *uint16
|
||||||
|
hr, _, _ := procStringFromIID.Call(uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(&p)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
str = LpOleStrToString(p)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateInstance of single uninitialized object with GUID.
|
||||||
|
func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
|
||||||
|
if iid == nil {
|
||||||
|
iid = IID_IUnknown
|
||||||
|
}
|
||||||
|
hr, _, _ := procCoCreateInstance.Call(
|
||||||
|
uintptr(unsafe.Pointer(clsid)),
|
||||||
|
0,
|
||||||
|
CLSCTX_SERVER,
|
||||||
|
uintptr(unsafe.Pointer(iid)),
|
||||||
|
uintptr(unsafe.Pointer(&unk)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetActiveObject retrieves pointer to active object.
|
||||||
|
func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
|
||||||
|
if iid == nil {
|
||||||
|
iid = IID_IUnknown
|
||||||
|
}
|
||||||
|
hr, _, _ := procGetActiveObject.Call(
|
||||||
|
uintptr(unsafe.Pointer(clsid)),
|
||||||
|
uintptr(unsafe.Pointer(iid)),
|
||||||
|
uintptr(unsafe.Pointer(&unk)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type BindOpts struct {
|
||||||
|
CbStruct uint32
|
||||||
|
GrfFlags uint32
|
||||||
|
GrfMode uint32
|
||||||
|
TickCountDeadline uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetObject retrieves pointer to active object.
|
||||||
|
func GetObject(programID string, bindOpts *BindOpts, iid *GUID) (unk *IUnknown, err error) {
|
||||||
|
if bindOpts != nil {
|
||||||
|
bindOpts.CbStruct = uint32(unsafe.Sizeof(BindOpts{}))
|
||||||
|
}
|
||||||
|
if iid == nil {
|
||||||
|
iid = IID_IUnknown
|
||||||
|
}
|
||||||
|
hr, _, _ := procCoGetObject.Call(
|
||||||
|
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(programID))),
|
||||||
|
uintptr(unsafe.Pointer(bindOpts)),
|
||||||
|
uintptr(unsafe.Pointer(iid)),
|
||||||
|
uintptr(unsafe.Pointer(&unk)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// VariantInit initializes variant.
|
||||||
|
func VariantInit(v *VARIANT) (err error) {
|
||||||
|
hr, _, _ := procVariantInit.Call(uintptr(unsafe.Pointer(v)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// VariantClear clears value in Variant settings to VT_EMPTY.
|
||||||
|
func VariantClear(v *VARIANT) (err error) {
|
||||||
|
hr, _, _ := procVariantClear.Call(uintptr(unsafe.Pointer(v)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SysAllocString allocates memory for string and copies string into memory.
|
||||||
|
func SysAllocString(v string) (ss *int16) {
|
||||||
|
pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v))))
|
||||||
|
ss = (*int16)(unsafe.Pointer(pss))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SysAllocStringLen copies up to length of given string returning pointer.
|
||||||
|
func SysAllocStringLen(v string) (ss *int16) {
|
||||||
|
utf16 := utf16.Encode([]rune(v + "\x00"))
|
||||||
|
ptr := &utf16[0]
|
||||||
|
|
||||||
|
pss, _, _ := procSysAllocStringLen.Call(uintptr(unsafe.Pointer(ptr)), uintptr(len(utf16)-1))
|
||||||
|
ss = (*int16)(unsafe.Pointer(pss))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SysFreeString frees string system memory. This must be called with SysAllocString.
|
||||||
|
func SysFreeString(v *int16) (err error) {
|
||||||
|
hr, _, _ := procSysFreeString.Call(uintptr(unsafe.Pointer(v)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SysStringLen is the length of the system allocated string.
|
||||||
|
func SysStringLen(v *int16) uint32 {
|
||||||
|
l, _, _ := procSysStringLen.Call(uintptr(unsafe.Pointer(v)))
|
||||||
|
return uint32(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateStdDispatch provides default IDispatch implementation for IUnknown.
|
||||||
|
//
|
||||||
|
// This handles default IDispatch implementation for objects. It haves a few
|
||||||
|
// limitations with only supporting one language. It will also only return
|
||||||
|
// default exception codes.
|
||||||
|
func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (disp *IDispatch, err error) {
|
||||||
|
hr, _, _ := procCreateStdDispatch.Call(
|
||||||
|
uintptr(unsafe.Pointer(unk)),
|
||||||
|
v,
|
||||||
|
uintptr(unsafe.Pointer(ptinfo)),
|
||||||
|
uintptr(unsafe.Pointer(&disp)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
|
||||||
|
//
|
||||||
|
// This will not handle the full implementation of the interface.
|
||||||
|
func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) {
|
||||||
|
hr, _, _ := procCreateDispTypeInfo.Call(
|
||||||
|
uintptr(unsafe.Pointer(idata)),
|
||||||
|
uintptr(GetUserDefaultLCID()),
|
||||||
|
uintptr(unsafe.Pointer(&pptinfo)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// copyMemory moves location of a block of memory.
|
||||||
|
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {
|
||||||
|
procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserDefaultLCID retrieves current user default locale.
|
||||||
|
func GetUserDefaultLCID() (lcid uint32) {
|
||||||
|
ret, _, _ := procGetUserDefaultLCID.Call()
|
||||||
|
lcid = uint32(ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMessage in message queue from runtime.
|
||||||
|
//
|
||||||
|
// This function appears to block. PeekMessage does not block.
|
||||||
|
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) {
|
||||||
|
r0, _, err := procGetMessageW.Call(uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax))
|
||||||
|
ret = int32(r0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// DispatchMessage to window procedure.
|
||||||
|
func DispatchMessage(msg *Msg) (ret int32) {
|
||||||
|
r0, _, _ := procDispatchMessageW.Call(uintptr(unsafe.Pointer(msg)))
|
||||||
|
ret = int32(r0)
|
||||||
|
return
|
||||||
|
}
|
||||||
174
vendor/github.com/go-ole/go-ole/com_func.go
generated
vendored
Normal file
174
vendor/github.com/go-ole/go-ole/com_func.go
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// coInitialize initializes COM library on current thread.
|
||||||
|
//
|
||||||
|
// MSDN documentation suggests that this function should not be called. Call
|
||||||
|
// CoInitializeEx() instead. The reason has to do with threading and this
|
||||||
|
// function is only for single-threaded apartments.
|
||||||
|
//
|
||||||
|
// That said, most users of the library have gotten away with just this
|
||||||
|
// function. If you are experiencing threading issues, then use
|
||||||
|
// CoInitializeEx().
|
||||||
|
func coInitialize() error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// coInitializeEx initializes COM library with concurrency model.
|
||||||
|
func coInitializeEx(coinit uint32) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoInitialize initializes COM library on current thread.
|
||||||
|
//
|
||||||
|
// MSDN documentation suggests that this function should not be called. Call
|
||||||
|
// CoInitializeEx() instead. The reason has to do with threading and this
|
||||||
|
// function is only for single-threaded apartments.
|
||||||
|
//
|
||||||
|
// That said, most users of the library have gotten away with just this
|
||||||
|
// function. If you are experiencing threading issues, then use
|
||||||
|
// CoInitializeEx().
|
||||||
|
func CoInitialize(p uintptr) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoInitializeEx initializes COM library with concurrency model.
|
||||||
|
func CoInitializeEx(p uintptr, coinit uint32) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoUninitialize uninitializes COM Library.
|
||||||
|
func CoUninitialize() {}
|
||||||
|
|
||||||
|
// CoTaskMemFree frees memory pointer.
|
||||||
|
func CoTaskMemFree(memptr uintptr) {}
|
||||||
|
|
||||||
|
// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.
|
||||||
|
//
|
||||||
|
// The Programmatic Identifier must be registered, because it will be looked up
|
||||||
|
// in the Windows Registry. The registry entry has the following keys: CLSID,
|
||||||
|
// Insertable, Protocol and Shell
|
||||||
|
// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).
|
||||||
|
//
|
||||||
|
// programID identifies the class id with less precision and is not guaranteed
|
||||||
|
// to be unique. These are usually found in the registry under
|
||||||
|
// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of
|
||||||
|
// "Program.Component.Version" with version being optional.
|
||||||
|
//
|
||||||
|
// CLSIDFromProgID in Windows API.
|
||||||
|
func CLSIDFromProgID(progId string) (*GUID, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CLSIDFromString retrieves Class ID from string representation.
|
||||||
|
//
|
||||||
|
// This is technically the string version of the GUID and will convert the
|
||||||
|
// string to object.
|
||||||
|
//
|
||||||
|
// CLSIDFromString in Windows API.
|
||||||
|
func CLSIDFromString(str string) (*GUID, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringFromCLSID returns GUID formated string from GUID object.
|
||||||
|
func StringFromCLSID(clsid *GUID) (string, error) {
|
||||||
|
return "", NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IIDFromString returns GUID from program ID.
|
||||||
|
func IIDFromString(progId string) (*GUID, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringFromIID returns GUID formatted string from GUID object.
|
||||||
|
func StringFromIID(iid *GUID) (string, error) {
|
||||||
|
return "", NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateInstance of single uninitialized object with GUID.
|
||||||
|
func CreateInstance(clsid *GUID, iid *GUID) (*IUnknown, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetActiveObject retrieves pointer to active object.
|
||||||
|
func GetActiveObject(clsid *GUID, iid *GUID) (*IUnknown, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// VariantInit initializes variant.
|
||||||
|
func VariantInit(v *VARIANT) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// VariantClear clears value in Variant settings to VT_EMPTY.
|
||||||
|
func VariantClear(v *VARIANT) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SysAllocString allocates memory for string and copies string into memory.
|
||||||
|
func SysAllocString(v string) *int16 {
|
||||||
|
u := int16(0)
|
||||||
|
return &u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SysAllocStringLen copies up to length of given string returning pointer.
|
||||||
|
func SysAllocStringLen(v string) *int16 {
|
||||||
|
u := int16(0)
|
||||||
|
return &u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SysFreeString frees string system memory. This must be called with SysAllocString.
|
||||||
|
func SysFreeString(v *int16) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SysStringLen is the length of the system allocated string.
|
||||||
|
func SysStringLen(v *int16) uint32 {
|
||||||
|
return uint32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateStdDispatch provides default IDispatch implementation for IUnknown.
|
||||||
|
//
|
||||||
|
// This handles default IDispatch implementation for objects. It haves a few
|
||||||
|
// limitations with only supporting one language. It will also only return
|
||||||
|
// default exception codes.
|
||||||
|
func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (*IDispatch, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
|
||||||
|
//
|
||||||
|
// This will not handle the full implementation of the interface.
|
||||||
|
func CreateDispTypeInfo(idata *INTERFACEDATA) (*IUnknown, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// copyMemory moves location of a block of memory.
|
||||||
|
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {}
|
||||||
|
|
||||||
|
// GetUserDefaultLCID retrieves current user default locale.
|
||||||
|
func GetUserDefaultLCID() uint32 {
|
||||||
|
return uint32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMessage in message queue from runtime.
|
||||||
|
//
|
||||||
|
// This function appears to block. PeekMessage does not block.
|
||||||
|
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (int32, error) {
|
||||||
|
return int32(0), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DispatchMessage to window procedure.
|
||||||
|
func DispatchMessage(msg *Msg) int32 {
|
||||||
|
return int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetVariantDate(value uint64) (time.Time, error) {
|
||||||
|
return time.Now(), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
192
vendor/github.com/go-ole/go-ole/connect.go
generated
vendored
Normal file
192
vendor/github.com/go-ole/go-ole/connect.go
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
// Connection contains IUnknown for fluent interface interaction.
|
||||||
|
//
|
||||||
|
// Deprecated. Use oleutil package instead.
|
||||||
|
type Connection struct {
|
||||||
|
Object *IUnknown // Access COM
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize COM.
|
||||||
|
func (*Connection) Initialize() (err error) {
|
||||||
|
return coInitialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uninitialize COM.
|
||||||
|
func (*Connection) Uninitialize() {
|
||||||
|
CoUninitialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create IUnknown object based first on ProgId and then from String.
|
||||||
|
func (c *Connection) Create(progId string) (err error) {
|
||||||
|
var clsid *GUID
|
||||||
|
clsid, err = CLSIDFromProgID(progId)
|
||||||
|
if err != nil {
|
||||||
|
clsid, err = CLSIDFromString(progId)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unknown, err := CreateInstance(clsid, IID_IUnknown)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Object = unknown
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release IUnknown object.
|
||||||
|
func (c *Connection) Release() {
|
||||||
|
c.Object.Release()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load COM object from list of programIDs or strings.
|
||||||
|
func (c *Connection) Load(names ...string) (errors []error) {
|
||||||
|
var tempErrors []error = make([]error, len(names))
|
||||||
|
var numErrors int = 0
|
||||||
|
for _, name := range names {
|
||||||
|
err := c.Create(name)
|
||||||
|
if err != nil {
|
||||||
|
tempErrors = append(tempErrors, err)
|
||||||
|
numErrors += 1
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
copy(errors, tempErrors[0:numErrors])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dispatch returns Dispatch object.
|
||||||
|
func (c *Connection) Dispatch() (object *Dispatch, err error) {
|
||||||
|
dispatch, err := c.Object.QueryInterface(IID_IDispatch)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
object = &Dispatch{dispatch}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dispatch stores IDispatch object.
|
||||||
|
type Dispatch struct {
|
||||||
|
Object *IDispatch // Dispatch object.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call method on IDispatch with parameters.
|
||||||
|
func (d *Dispatch) Call(method string, params ...interface{}) (result *VARIANT, err error) {
|
||||||
|
id, err := d.GetId(method)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err = d.Invoke(id, DISPATCH_METHOD, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustCall method on IDispatch with parameters.
|
||||||
|
func (d *Dispatch) MustCall(method string, params ...interface{}) (result *VARIANT) {
|
||||||
|
id, err := d.GetId(method)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err = d.Invoke(id, DISPATCH_METHOD, params)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get property on IDispatch with parameters.
|
||||||
|
func (d *Dispatch) Get(name string, params ...interface{}) (result *VARIANT, err error) {
|
||||||
|
id, err := d.GetId(name)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustGet property on IDispatch with parameters.
|
||||||
|
func (d *Dispatch) MustGet(name string, params ...interface{}) (result *VARIANT) {
|
||||||
|
id, err := d.GetId(name)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set property on IDispatch with parameters.
|
||||||
|
func (d *Dispatch) Set(name string, params ...interface{}) (result *VARIANT, err error) {
|
||||||
|
id, err := d.GetId(name)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustSet property on IDispatch with parameters.
|
||||||
|
func (d *Dispatch) MustSet(name string, params ...interface{}) (result *VARIANT) {
|
||||||
|
id, err := d.GetId(name)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetId retrieves ID of name on IDispatch.
|
||||||
|
func (d *Dispatch) GetId(name string) (id int32, err error) {
|
||||||
|
var dispid []int32
|
||||||
|
dispid, err = d.Object.GetIDsOfName([]string{name})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id = dispid[0]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIds retrieves all IDs of names on IDispatch.
|
||||||
|
func (d *Dispatch) GetIds(names ...string) (dispid []int32, err error) {
|
||||||
|
dispid, err = d.Object.GetIDsOfName(names)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoke IDispatch on DisplayID of dispatch type with parameters.
|
||||||
|
//
|
||||||
|
// There have been problems where if send cascading params..., it would error
|
||||||
|
// out because the parameters would be empty.
|
||||||
|
func (d *Dispatch) Invoke(id int32, dispatch int16, params []interface{}) (result *VARIANT, err error) {
|
||||||
|
if len(params) < 1 {
|
||||||
|
result, err = d.Object.Invoke(id, dispatch)
|
||||||
|
} else {
|
||||||
|
result, err = d.Object.Invoke(id, dispatch, params...)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release IDispatch object.
|
||||||
|
func (d *Dispatch) Release() {
|
||||||
|
d.Object.Release()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect initializes COM and attempts to load IUnknown based on given names.
|
||||||
|
func Connect(names ...string) (connection *Connection) {
|
||||||
|
connection.Initialize()
|
||||||
|
connection.Load(names...)
|
||||||
|
return
|
||||||
|
}
|
||||||
153
vendor/github.com/go-ole/go-ole/constants.go
generated
vendored
Normal file
153
vendor/github.com/go-ole/go-ole/constants.go
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
const (
|
||||||
|
CLSCTX_INPROC_SERVER = 1
|
||||||
|
CLSCTX_INPROC_HANDLER = 2
|
||||||
|
CLSCTX_LOCAL_SERVER = 4
|
||||||
|
CLSCTX_INPROC_SERVER16 = 8
|
||||||
|
CLSCTX_REMOTE_SERVER = 16
|
||||||
|
CLSCTX_ALL = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER
|
||||||
|
CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER
|
||||||
|
CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
COINIT_APARTMENTTHREADED = 0x2
|
||||||
|
COINIT_MULTITHREADED = 0x0
|
||||||
|
COINIT_DISABLE_OLE1DDE = 0x4
|
||||||
|
COINIT_SPEED_OVER_MEMORY = 0x8
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DISPATCH_METHOD = 1
|
||||||
|
DISPATCH_PROPERTYGET = 2
|
||||||
|
DISPATCH_PROPERTYPUT = 4
|
||||||
|
DISPATCH_PROPERTYPUTREF = 8
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
S_OK = 0x00000000
|
||||||
|
E_UNEXPECTED = 0x8000FFFF
|
||||||
|
E_NOTIMPL = 0x80004001
|
||||||
|
E_OUTOFMEMORY = 0x8007000E
|
||||||
|
E_INVALIDARG = 0x80070057
|
||||||
|
E_NOINTERFACE = 0x80004002
|
||||||
|
E_POINTER = 0x80004003
|
||||||
|
E_HANDLE = 0x80070006
|
||||||
|
E_ABORT = 0x80004004
|
||||||
|
E_FAIL = 0x80004005
|
||||||
|
E_ACCESSDENIED = 0x80070005
|
||||||
|
E_PENDING = 0x8000000A
|
||||||
|
|
||||||
|
CO_E_CLASSSTRING = 0x800401F3
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CC_FASTCALL = iota
|
||||||
|
CC_CDECL
|
||||||
|
CC_MSCPASCAL
|
||||||
|
CC_PASCAL = CC_MSCPASCAL
|
||||||
|
CC_MACPASCAL
|
||||||
|
CC_STDCALL
|
||||||
|
CC_FPFASTCALL
|
||||||
|
CC_SYSCALL
|
||||||
|
CC_MPWCDECL
|
||||||
|
CC_MPWPASCAL
|
||||||
|
CC_MAX = CC_MPWPASCAL
|
||||||
|
)
|
||||||
|
|
||||||
|
type VT uint16
|
||||||
|
|
||||||
|
const (
|
||||||
|
VT_EMPTY VT = 0x0
|
||||||
|
VT_NULL VT = 0x1
|
||||||
|
VT_I2 VT = 0x2
|
||||||
|
VT_I4 VT = 0x3
|
||||||
|
VT_R4 VT = 0x4
|
||||||
|
VT_R8 VT = 0x5
|
||||||
|
VT_CY VT = 0x6
|
||||||
|
VT_DATE VT = 0x7
|
||||||
|
VT_BSTR VT = 0x8
|
||||||
|
VT_DISPATCH VT = 0x9
|
||||||
|
VT_ERROR VT = 0xa
|
||||||
|
VT_BOOL VT = 0xb
|
||||||
|
VT_VARIANT VT = 0xc
|
||||||
|
VT_UNKNOWN VT = 0xd
|
||||||
|
VT_DECIMAL VT = 0xe
|
||||||
|
VT_I1 VT = 0x10
|
||||||
|
VT_UI1 VT = 0x11
|
||||||
|
VT_UI2 VT = 0x12
|
||||||
|
VT_UI4 VT = 0x13
|
||||||
|
VT_I8 VT = 0x14
|
||||||
|
VT_UI8 VT = 0x15
|
||||||
|
VT_INT VT = 0x16
|
||||||
|
VT_UINT VT = 0x17
|
||||||
|
VT_VOID VT = 0x18
|
||||||
|
VT_HRESULT VT = 0x19
|
||||||
|
VT_PTR VT = 0x1a
|
||||||
|
VT_SAFEARRAY VT = 0x1b
|
||||||
|
VT_CARRAY VT = 0x1c
|
||||||
|
VT_USERDEFINED VT = 0x1d
|
||||||
|
VT_LPSTR VT = 0x1e
|
||||||
|
VT_LPWSTR VT = 0x1f
|
||||||
|
VT_RECORD VT = 0x24
|
||||||
|
VT_INT_PTR VT = 0x25
|
||||||
|
VT_UINT_PTR VT = 0x26
|
||||||
|
VT_FILETIME VT = 0x40
|
||||||
|
VT_BLOB VT = 0x41
|
||||||
|
VT_STREAM VT = 0x42
|
||||||
|
VT_STORAGE VT = 0x43
|
||||||
|
VT_STREAMED_OBJECT VT = 0x44
|
||||||
|
VT_STORED_OBJECT VT = 0x45
|
||||||
|
VT_BLOB_OBJECT VT = 0x46
|
||||||
|
VT_CF VT = 0x47
|
||||||
|
VT_CLSID VT = 0x48
|
||||||
|
VT_BSTR_BLOB VT = 0xfff
|
||||||
|
VT_VECTOR VT = 0x1000
|
||||||
|
VT_ARRAY VT = 0x2000
|
||||||
|
VT_BYREF VT = 0x4000
|
||||||
|
VT_RESERVED VT = 0x8000
|
||||||
|
VT_ILLEGAL VT = 0xffff
|
||||||
|
VT_ILLEGALMASKED VT = 0xfff
|
||||||
|
VT_TYPEMASK VT = 0xfff
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DISPID_UNKNOWN = -1
|
||||||
|
DISPID_VALUE = 0
|
||||||
|
DISPID_PROPERTYPUT = -3
|
||||||
|
DISPID_NEWENUM = -4
|
||||||
|
DISPID_EVALUATE = -5
|
||||||
|
DISPID_CONSTRUCTOR = -6
|
||||||
|
DISPID_DESTRUCTOR = -7
|
||||||
|
DISPID_COLLECT = -8
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TKIND_ENUM = 1
|
||||||
|
TKIND_RECORD = 2
|
||||||
|
TKIND_MODULE = 3
|
||||||
|
TKIND_INTERFACE = 4
|
||||||
|
TKIND_DISPATCH = 5
|
||||||
|
TKIND_COCLASS = 6
|
||||||
|
TKIND_ALIAS = 7
|
||||||
|
TKIND_UNION = 8
|
||||||
|
TKIND_MAX = 9
|
||||||
|
)
|
||||||
|
|
||||||
|
// Safe Array Feature Flags
|
||||||
|
|
||||||
|
const (
|
||||||
|
FADF_AUTO = 0x0001
|
||||||
|
FADF_STATIC = 0x0002
|
||||||
|
FADF_EMBEDDED = 0x0004
|
||||||
|
FADF_FIXEDSIZE = 0x0010
|
||||||
|
FADF_RECORD = 0x0020
|
||||||
|
FADF_HAVEIID = 0x0040
|
||||||
|
FADF_HAVEVARTYPE = 0x0080
|
||||||
|
FADF_BSTR = 0x0100
|
||||||
|
FADF_UNKNOWN = 0x0200
|
||||||
|
FADF_DISPATCH = 0x0400
|
||||||
|
FADF_VARIANT = 0x0800
|
||||||
|
FADF_RESERVED = 0xF008
|
||||||
|
)
|
||||||
51
vendor/github.com/go-ole/go-ole/error.go
generated
vendored
Normal file
51
vendor/github.com/go-ole/go-ole/error.go
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
// OleError stores COM errors.
|
||||||
|
type OleError struct {
|
||||||
|
hr uintptr
|
||||||
|
description string
|
||||||
|
subError error
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewError creates new error with HResult.
|
||||||
|
func NewError(hr uintptr) *OleError {
|
||||||
|
return &OleError{hr: hr}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewErrorWithDescription creates new COM error with HResult and description.
|
||||||
|
func NewErrorWithDescription(hr uintptr, description string) *OleError {
|
||||||
|
return &OleError{hr: hr, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewErrorWithSubError creates new COM error with parent error.
|
||||||
|
func NewErrorWithSubError(hr uintptr, description string, err error) *OleError {
|
||||||
|
return &OleError{hr: hr, description: description, subError: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Code is the HResult.
|
||||||
|
func (v *OleError) Code() uintptr {
|
||||||
|
return uintptr(v.hr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// String description, either manually set or format message with error code.
|
||||||
|
func (v *OleError) String() string {
|
||||||
|
if v.description != "" {
|
||||||
|
return errstr(int(v.hr)) + " (" + v.description + ")"
|
||||||
|
}
|
||||||
|
return errstr(int(v.hr))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements error interface.
|
||||||
|
func (v *OleError) Error() string {
|
||||||
|
return v.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description retrieves error summary, if there is one.
|
||||||
|
func (v *OleError) Description() string {
|
||||||
|
return v.description
|
||||||
|
}
|
||||||
|
|
||||||
|
// SubError returns parent error, if there is one.
|
||||||
|
func (v *OleError) SubError() error {
|
||||||
|
return v.subError
|
||||||
|
}
|
||||||
8
vendor/github.com/go-ole/go-ole/error_func.go
generated
vendored
Normal file
8
vendor/github.com/go-ole/go-ole/error_func.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
// errstr converts error code to string.
|
||||||
|
func errstr(errno int) string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
24
vendor/github.com/go-ole/go-ole/error_windows.go
generated
vendored
Normal file
24
vendor/github.com/go-ole/go-ole/error_windows.go
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"syscall"
|
||||||
|
"unicode/utf16"
|
||||||
|
)
|
||||||
|
|
||||||
|
// errstr converts error code to string.
|
||||||
|
func errstr(errno int) string {
|
||||||
|
// ask windows for the remaining errors
|
||||||
|
var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
|
||||||
|
b := make([]uint16, 300)
|
||||||
|
n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err)
|
||||||
|
}
|
||||||
|
// trim terminating \r and \n
|
||||||
|
for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
|
||||||
|
}
|
||||||
|
return string(utf16.Decode(b[:n]))
|
||||||
|
}
|
||||||
284
vendor/github.com/go-ole/go-ole/guid.go
generated
vendored
Normal file
284
vendor/github.com/go-ole/go-ole/guid.go
generated
vendored
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
var (
|
||||||
|
// IID_NULL is null Interface ID, used when no other Interface ID is known.
|
||||||
|
IID_NULL = NewGUID("{00000000-0000-0000-0000-000000000000}")
|
||||||
|
|
||||||
|
// IID_IUnknown is for IUnknown interfaces.
|
||||||
|
IID_IUnknown = NewGUID("{00000000-0000-0000-C000-000000000046}")
|
||||||
|
|
||||||
|
// IID_IDispatch is for IDispatch interfaces.
|
||||||
|
IID_IDispatch = NewGUID("{00020400-0000-0000-C000-000000000046}")
|
||||||
|
|
||||||
|
// IID_IEnumVariant is for IEnumVariant interfaces
|
||||||
|
IID_IEnumVariant = NewGUID("{00020404-0000-0000-C000-000000000046}")
|
||||||
|
|
||||||
|
// IID_IConnectionPointContainer is for IConnectionPointContainer interfaces.
|
||||||
|
IID_IConnectionPointContainer = NewGUID("{B196B284-BAB4-101A-B69C-00AA00341D07}")
|
||||||
|
|
||||||
|
// IID_IConnectionPoint is for IConnectionPoint interfaces.
|
||||||
|
IID_IConnectionPoint = NewGUID("{B196B286-BAB4-101A-B69C-00AA00341D07}")
|
||||||
|
|
||||||
|
// IID_IInspectable is for IInspectable interfaces.
|
||||||
|
IID_IInspectable = NewGUID("{AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90}")
|
||||||
|
|
||||||
|
// IID_IProvideClassInfo is for IProvideClassInfo interfaces.
|
||||||
|
IID_IProvideClassInfo = NewGUID("{B196B283-BAB4-101A-B69C-00AA00341D07}")
|
||||||
|
)
|
||||||
|
|
||||||
|
// These are for testing and not part of any library.
|
||||||
|
var (
|
||||||
|
// IID_ICOMTestString is for ICOMTestString interfaces.
|
||||||
|
//
|
||||||
|
// {E0133EB4-C36F-469A-9D3D-C66B84BE19ED}
|
||||||
|
IID_ICOMTestString = NewGUID("{E0133EB4-C36F-469A-9D3D-C66B84BE19ED}")
|
||||||
|
|
||||||
|
// IID_ICOMTestInt8 is for ICOMTestInt8 interfaces.
|
||||||
|
//
|
||||||
|
// {BEB06610-EB84-4155-AF58-E2BFF53680B4}
|
||||||
|
IID_ICOMTestInt8 = NewGUID("{BEB06610-EB84-4155-AF58-E2BFF53680B4}")
|
||||||
|
|
||||||
|
// IID_ICOMTestInt16 is for ICOMTestInt16 interfaces.
|
||||||
|
//
|
||||||
|
// {DAA3F9FA-761E-4976-A860-8364CE55F6FC}
|
||||||
|
IID_ICOMTestInt16 = NewGUID("{DAA3F9FA-761E-4976-A860-8364CE55F6FC}")
|
||||||
|
|
||||||
|
// IID_ICOMTestInt32 is for ICOMTestInt32 interfaces.
|
||||||
|
//
|
||||||
|
// {E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0}
|
||||||
|
IID_ICOMTestInt32 = NewGUID("{E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0}")
|
||||||
|
|
||||||
|
// IID_ICOMTestInt64 is for ICOMTestInt64 interfaces.
|
||||||
|
//
|
||||||
|
// {8D437CBC-B3ED-485C-BC32-C336432A1623}
|
||||||
|
IID_ICOMTestInt64 = NewGUID("{8D437CBC-B3ED-485C-BC32-C336432A1623}")
|
||||||
|
|
||||||
|
// IID_ICOMTestFloat is for ICOMTestFloat interfaces.
|
||||||
|
//
|
||||||
|
// {BF1ED004-EA02-456A-AA55-2AC8AC6B054C}
|
||||||
|
IID_ICOMTestFloat = NewGUID("{BF1ED004-EA02-456A-AA55-2AC8AC6B054C}")
|
||||||
|
|
||||||
|
// IID_ICOMTestDouble is for ICOMTestDouble interfaces.
|
||||||
|
//
|
||||||
|
// {BF908A81-8687-4E93-999F-D86FAB284BA0}
|
||||||
|
IID_ICOMTestDouble = NewGUID("{BF908A81-8687-4E93-999F-D86FAB284BA0}")
|
||||||
|
|
||||||
|
// IID_ICOMTestBoolean is for ICOMTestBoolean interfaces.
|
||||||
|
//
|
||||||
|
// {D530E7A6-4EE8-40D1-8931-3D63B8605010}
|
||||||
|
IID_ICOMTestBoolean = NewGUID("{D530E7A6-4EE8-40D1-8931-3D63B8605010}")
|
||||||
|
|
||||||
|
// IID_ICOMEchoTestObject is for ICOMEchoTestObject interfaces.
|
||||||
|
//
|
||||||
|
// {6485B1EF-D780-4834-A4FE-1EBB51746CA3}
|
||||||
|
IID_ICOMEchoTestObject = NewGUID("{6485B1EF-D780-4834-A4FE-1EBB51746CA3}")
|
||||||
|
|
||||||
|
// IID_ICOMTestTypes is for ICOMTestTypes interfaces.
|
||||||
|
//
|
||||||
|
// {CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0}
|
||||||
|
IID_ICOMTestTypes = NewGUID("{CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0}")
|
||||||
|
|
||||||
|
// CLSID_COMEchoTestObject is for COMEchoTestObject class.
|
||||||
|
//
|
||||||
|
// {3C24506A-AE9E-4D50-9157-EF317281F1B0}
|
||||||
|
CLSID_COMEchoTestObject = NewGUID("{3C24506A-AE9E-4D50-9157-EF317281F1B0}")
|
||||||
|
|
||||||
|
// CLSID_COMTestScalarClass is for COMTestScalarClass class.
|
||||||
|
//
|
||||||
|
// {865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}
|
||||||
|
CLSID_COMTestScalarClass = NewGUID("{865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}")
|
||||||
|
)
|
||||||
|
|
||||||
|
const hextable = "0123456789ABCDEF"
|
||||||
|
const emptyGUID = "{00000000-0000-0000-0000-000000000000}"
|
||||||
|
|
||||||
|
// GUID is Windows API specific GUID type.
|
||||||
|
//
|
||||||
|
// This exists to match Windows GUID type for direct passing for COM.
|
||||||
|
// Format is in xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx.
|
||||||
|
type GUID struct {
|
||||||
|
Data1 uint32
|
||||||
|
Data2 uint16
|
||||||
|
Data3 uint16
|
||||||
|
Data4 [8]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGUID converts the given string into a globally unique identifier that is
|
||||||
|
// compliant with the Windows API.
|
||||||
|
//
|
||||||
|
// The supplied string may be in any of these formats:
|
||||||
|
//
|
||||||
|
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
|
// XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
||||||
|
// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
||||||
|
//
|
||||||
|
// The conversion of the supplied string is not case-sensitive.
|
||||||
|
func NewGUID(guid string) *GUID {
|
||||||
|
d := []byte(guid)
|
||||||
|
var d1, d2, d3, d4a, d4b []byte
|
||||||
|
|
||||||
|
switch len(d) {
|
||||||
|
case 38:
|
||||||
|
if d[0] != '{' || d[37] != '}' {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
d = d[1:37]
|
||||||
|
fallthrough
|
||||||
|
case 36:
|
||||||
|
if d[8] != '-' || d[13] != '-' || d[18] != '-' || d[23] != '-' {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
d1 = d[0:8]
|
||||||
|
d2 = d[9:13]
|
||||||
|
d3 = d[14:18]
|
||||||
|
d4a = d[19:23]
|
||||||
|
d4b = d[24:36]
|
||||||
|
case 32:
|
||||||
|
d1 = d[0:8]
|
||||||
|
d2 = d[8:12]
|
||||||
|
d3 = d[12:16]
|
||||||
|
d4a = d[16:20]
|
||||||
|
d4b = d[20:32]
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var g GUID
|
||||||
|
var ok1, ok2, ok3, ok4 bool
|
||||||
|
g.Data1, ok1 = decodeHexUint32(d1)
|
||||||
|
g.Data2, ok2 = decodeHexUint16(d2)
|
||||||
|
g.Data3, ok3 = decodeHexUint16(d3)
|
||||||
|
g.Data4, ok4 = decodeHexByte64(d4a, d4b)
|
||||||
|
if ok1 && ok2 && ok3 && ok4 {
|
||||||
|
return &g
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeHexUint32(src []byte) (value uint32, ok bool) {
|
||||||
|
var b1, b2, b3, b4 byte
|
||||||
|
var ok1, ok2, ok3, ok4 bool
|
||||||
|
b1, ok1 = decodeHexByte(src[0], src[1])
|
||||||
|
b2, ok2 = decodeHexByte(src[2], src[3])
|
||||||
|
b3, ok3 = decodeHexByte(src[4], src[5])
|
||||||
|
b4, ok4 = decodeHexByte(src[6], src[7])
|
||||||
|
value = (uint32(b1) << 24) | (uint32(b2) << 16) | (uint32(b3) << 8) | uint32(b4)
|
||||||
|
ok = ok1 && ok2 && ok3 && ok4
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeHexUint16(src []byte) (value uint16, ok bool) {
|
||||||
|
var b1, b2 byte
|
||||||
|
var ok1, ok2 bool
|
||||||
|
b1, ok1 = decodeHexByte(src[0], src[1])
|
||||||
|
b2, ok2 = decodeHexByte(src[2], src[3])
|
||||||
|
value = (uint16(b1) << 8) | uint16(b2)
|
||||||
|
ok = ok1 && ok2
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeHexByte64(s1 []byte, s2 []byte) (value [8]byte, ok bool) {
|
||||||
|
var ok1, ok2, ok3, ok4, ok5, ok6, ok7, ok8 bool
|
||||||
|
value[0], ok1 = decodeHexByte(s1[0], s1[1])
|
||||||
|
value[1], ok2 = decodeHexByte(s1[2], s1[3])
|
||||||
|
value[2], ok3 = decodeHexByte(s2[0], s2[1])
|
||||||
|
value[3], ok4 = decodeHexByte(s2[2], s2[3])
|
||||||
|
value[4], ok5 = decodeHexByte(s2[4], s2[5])
|
||||||
|
value[5], ok6 = decodeHexByte(s2[6], s2[7])
|
||||||
|
value[6], ok7 = decodeHexByte(s2[8], s2[9])
|
||||||
|
value[7], ok8 = decodeHexByte(s2[10], s2[11])
|
||||||
|
ok = ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && ok7 && ok8
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeHexByte(c1, c2 byte) (value byte, ok bool) {
|
||||||
|
var n1, n2 byte
|
||||||
|
var ok1, ok2 bool
|
||||||
|
n1, ok1 = decodeHexChar(c1)
|
||||||
|
n2, ok2 = decodeHexChar(c2)
|
||||||
|
value = (n1 << 4) | n2
|
||||||
|
ok = ok1 && ok2
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeHexChar(c byte) (byte, bool) {
|
||||||
|
switch {
|
||||||
|
case '0' <= c && c <= '9':
|
||||||
|
return c - '0', true
|
||||||
|
case 'a' <= c && c <= 'f':
|
||||||
|
return c - 'a' + 10, true
|
||||||
|
case 'A' <= c && c <= 'F':
|
||||||
|
return c - 'A' + 10, true
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// String converts the GUID to string form. It will adhere to this pattern:
|
||||||
|
//
|
||||||
|
// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
||||||
|
//
|
||||||
|
// If the GUID is nil, the string representation of an empty GUID is returned:
|
||||||
|
//
|
||||||
|
// {00000000-0000-0000-0000-000000000000}
|
||||||
|
func (guid *GUID) String() string {
|
||||||
|
if guid == nil {
|
||||||
|
return emptyGUID
|
||||||
|
}
|
||||||
|
|
||||||
|
var c [38]byte
|
||||||
|
c[0] = '{'
|
||||||
|
putUint32Hex(c[1:9], guid.Data1)
|
||||||
|
c[9] = '-'
|
||||||
|
putUint16Hex(c[10:14], guid.Data2)
|
||||||
|
c[14] = '-'
|
||||||
|
putUint16Hex(c[15:19], guid.Data3)
|
||||||
|
c[19] = '-'
|
||||||
|
putByteHex(c[20:24], guid.Data4[0:2])
|
||||||
|
c[24] = '-'
|
||||||
|
putByteHex(c[25:37], guid.Data4[2:8])
|
||||||
|
c[37] = '}'
|
||||||
|
return string(c[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func putUint32Hex(b []byte, v uint32) {
|
||||||
|
b[0] = hextable[byte(v>>24)>>4]
|
||||||
|
b[1] = hextable[byte(v>>24)&0x0f]
|
||||||
|
b[2] = hextable[byte(v>>16)>>4]
|
||||||
|
b[3] = hextable[byte(v>>16)&0x0f]
|
||||||
|
b[4] = hextable[byte(v>>8)>>4]
|
||||||
|
b[5] = hextable[byte(v>>8)&0x0f]
|
||||||
|
b[6] = hextable[byte(v)>>4]
|
||||||
|
b[7] = hextable[byte(v)&0x0f]
|
||||||
|
}
|
||||||
|
|
||||||
|
func putUint16Hex(b []byte, v uint16) {
|
||||||
|
b[0] = hextable[byte(v>>8)>>4]
|
||||||
|
b[1] = hextable[byte(v>>8)&0x0f]
|
||||||
|
b[2] = hextable[byte(v)>>4]
|
||||||
|
b[3] = hextable[byte(v)&0x0f]
|
||||||
|
}
|
||||||
|
|
||||||
|
func putByteHex(dst, src []byte) {
|
||||||
|
for i := 0; i < len(src); i++ {
|
||||||
|
dst[i*2] = hextable[src[i]>>4]
|
||||||
|
dst[i*2+1] = hextable[src[i]&0x0f]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEqualGUID compares two GUID.
|
||||||
|
//
|
||||||
|
// Not constant time comparison.
|
||||||
|
func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool {
|
||||||
|
return guid1.Data1 == guid2.Data1 &&
|
||||||
|
guid1.Data2 == guid2.Data2 &&
|
||||||
|
guid1.Data3 == guid2.Data3 &&
|
||||||
|
guid1.Data4[0] == guid2.Data4[0] &&
|
||||||
|
guid1.Data4[1] == guid2.Data4[1] &&
|
||||||
|
guid1.Data4[2] == guid2.Data4[2] &&
|
||||||
|
guid1.Data4[3] == guid2.Data4[3] &&
|
||||||
|
guid1.Data4[4] == guid2.Data4[4] &&
|
||||||
|
guid1.Data4[5] == guid2.Data4[5] &&
|
||||||
|
guid1.Data4[6] == guid2.Data4[6] &&
|
||||||
|
guid1.Data4[7] == guid2.Data4[7]
|
||||||
|
}
|
||||||
20
vendor/github.com/go-ole/go-ole/iconnectionpoint.go
generated
vendored
Normal file
20
vendor/github.com/go-ole/go-ole/iconnectionpoint.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type IConnectionPoint struct {
|
||||||
|
IUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type IConnectionPointVtbl struct {
|
||||||
|
IUnknownVtbl
|
||||||
|
GetConnectionInterface uintptr
|
||||||
|
GetConnectionPointContainer uintptr
|
||||||
|
Advise uintptr
|
||||||
|
Unadvise uintptr
|
||||||
|
EnumConnections uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) VTable() *IConnectionPointVtbl {
|
||||||
|
return (*IConnectionPointVtbl)(unsafe.Pointer(v.RawVTable))
|
||||||
|
}
|
||||||
21
vendor/github.com/go-ole/go-ole/iconnectionpoint_func.go
generated
vendored
Normal file
21
vendor/github.com/go-ole/go-ole/iconnectionpoint_func.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 {
|
||||||
|
return int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) Advise(unknown *IUnknown) (uint32, error) {
|
||||||
|
return uint32(0), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) Unadvise(cookie uint32) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) (err error) {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
43
vendor/github.com/go-ole/go-ole/iconnectionpoint_windows.go
generated
vendored
Normal file
43
vendor/github.com/go-ole/go-ole/iconnectionpoint_windows.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 {
|
||||||
|
// XXX: This doesn't look like it does what it's supposed to
|
||||||
|
return release((*IUnknown)(unsafe.Pointer(v)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) Advise(unknown *IUnknown) (cookie uint32, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
v.VTable().Advise,
|
||||||
|
3,
|
||||||
|
uintptr(unsafe.Pointer(v)),
|
||||||
|
uintptr(unsafe.Pointer(unknown)),
|
||||||
|
uintptr(unsafe.Pointer(&cookie)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) Unadvise(cookie uint32) (err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
v.VTable().Unadvise,
|
||||||
|
2,
|
||||||
|
uintptr(unsafe.Pointer(v)),
|
||||||
|
uintptr(cookie),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
17
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer.go
generated
vendored
Normal file
17
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer.go
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type IConnectionPointContainer struct {
|
||||||
|
IUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type IConnectionPointContainerVtbl struct {
|
||||||
|
IUnknownVtbl
|
||||||
|
EnumConnectionPoints uintptr
|
||||||
|
FindConnectionPoint uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPointContainer) VTable() *IConnectionPointContainerVtbl {
|
||||||
|
return (*IConnectionPointContainerVtbl)(unsafe.Pointer(v.RawVTable))
|
||||||
|
}
|
||||||
11
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go
generated
vendored
Normal file
11
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
25
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go
generated
vendored
Normal file
25
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) (err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
v.VTable().FindConnectionPoint,
|
||||||
|
3,
|
||||||
|
uintptr(unsafe.Pointer(v)),
|
||||||
|
uintptr(unsafe.Pointer(iid)),
|
||||||
|
uintptr(unsafe.Pointer(point)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
94
vendor/github.com/go-ole/go-ole/idispatch.go
generated
vendored
Normal file
94
vendor/github.com/go-ole/go-ole/idispatch.go
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type IDispatch struct {
|
||||||
|
IUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type IDispatchVtbl struct {
|
||||||
|
IUnknownVtbl
|
||||||
|
GetTypeInfoCount uintptr
|
||||||
|
GetTypeInfo uintptr
|
||||||
|
GetIDsOfNames uintptr
|
||||||
|
Invoke uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IDispatch) VTable() *IDispatchVtbl {
|
||||||
|
return (*IDispatchVtbl)(unsafe.Pointer(v.RawVTable))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IDispatch) GetIDsOfName(names []string) (dispid []int32, err error) {
|
||||||
|
dispid, err = getIDsOfName(v, names)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IDispatch) Invoke(dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) {
|
||||||
|
result, err = invoke(v, dispid, dispatch, params...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IDispatch) GetTypeInfoCount() (c uint32, err error) {
|
||||||
|
c, err = getTypeInfoCount(v)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IDispatch) GetTypeInfo() (tinfo *ITypeInfo, err error) {
|
||||||
|
tinfo, err = getTypeInfo(v)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSingleIDOfName is a helper that returns single display ID for IDispatch name.
|
||||||
|
//
|
||||||
|
// This replaces the common pattern of attempting to get a single name from the list of available
|
||||||
|
// IDs. It gives the first ID, if it is available.
|
||||||
|
func (v *IDispatch) GetSingleIDOfName(name string) (displayID int32, err error) {
|
||||||
|
var displayIDs []int32
|
||||||
|
displayIDs, err = v.GetIDsOfName([]string{name})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
displayID = displayIDs[0]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// InvokeWithOptionalArgs accepts arguments as an array, works like Invoke.
|
||||||
|
//
|
||||||
|
// Accepts name and will attempt to retrieve Display ID to pass to Invoke.
|
||||||
|
//
|
||||||
|
// Passing params as an array is a workaround that could be fixed in later versions of Go that
|
||||||
|
// prevent passing empty params. During testing it was discovered that this is an acceptable way of
|
||||||
|
// getting around not being able to pass params normally.
|
||||||
|
func (v *IDispatch) InvokeWithOptionalArgs(name string, dispatch int16, params []interface{}) (result *VARIANT, err error) {
|
||||||
|
displayID, err := v.GetSingleIDOfName(name)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(params) < 1 {
|
||||||
|
result, err = v.Invoke(displayID, dispatch)
|
||||||
|
} else {
|
||||||
|
result, err = v.Invoke(displayID, dispatch, params...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CallMethod invokes named function with arguments on object.
|
||||||
|
func (v *IDispatch) CallMethod(name string, params ...interface{}) (*VARIANT, error) {
|
||||||
|
return v.InvokeWithOptionalArgs(name, DISPATCH_METHOD, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetProperty retrieves the property with the name with the ability to pass arguments.
|
||||||
|
//
|
||||||
|
// Most of the time you will not need to pass arguments as most objects do not allow for this
|
||||||
|
// feature. Or at least, should not allow for this feature. Some servers don't follow best practices
|
||||||
|
// and this is provided for those edge cases.
|
||||||
|
func (v *IDispatch) GetProperty(name string, params ...interface{}) (*VARIANT, error) {
|
||||||
|
return v.InvokeWithOptionalArgs(name, DISPATCH_PROPERTYGET, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutProperty attempts to mutate a property in the object.
|
||||||
|
func (v *IDispatch) PutProperty(name string, params ...interface{}) (*VARIANT, error) {
|
||||||
|
return v.InvokeWithOptionalArgs(name, DISPATCH_PROPERTYPUT, params)
|
||||||
|
}
|
||||||
19
vendor/github.com/go-ole/go-ole/idispatch_func.go
generated
vendored
Normal file
19
vendor/github.com/go-ole/go-ole/idispatch_func.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
func getIDsOfName(disp *IDispatch, names []string) ([]int32, error) {
|
||||||
|
return []int32{}, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTypeInfoCount(disp *IDispatch) (uint32, error) {
|
||||||
|
return uint32(0), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTypeInfo(disp *IDispatch) (*ITypeInfo, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (*VARIANT, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
203
vendor/github.com/go-ole/go-ole/idispatch_windows.go
generated
vendored
Normal file
203
vendor/github.com/go-ole/go-ole/idispatch_windows.go
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/big"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getIDsOfName(disp *IDispatch, names []string) (dispid []int32, err error) {
|
||||||
|
wnames := make([]*uint16, len(names))
|
||||||
|
for i := 0; i < len(names); i++ {
|
||||||
|
wnames[i] = syscall.StringToUTF16Ptr(names[i])
|
||||||
|
}
|
||||||
|
dispid = make([]int32, len(names))
|
||||||
|
namelen := uint32(len(names))
|
||||||
|
hr, _, _ := syscall.Syscall6(
|
||||||
|
disp.VTable().GetIDsOfNames,
|
||||||
|
6,
|
||||||
|
uintptr(unsafe.Pointer(disp)),
|
||||||
|
uintptr(unsafe.Pointer(IID_NULL)),
|
||||||
|
uintptr(unsafe.Pointer(&wnames[0])),
|
||||||
|
uintptr(namelen),
|
||||||
|
uintptr(GetUserDefaultLCID()),
|
||||||
|
uintptr(unsafe.Pointer(&dispid[0])))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTypeInfoCount(disp *IDispatch) (c uint32, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
disp.VTable().GetTypeInfoCount,
|
||||||
|
2,
|
||||||
|
uintptr(unsafe.Pointer(disp)),
|
||||||
|
uintptr(unsafe.Pointer(&c)),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTypeInfo(disp *IDispatch) (tinfo *ITypeInfo, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
disp.VTable().GetTypeInfo,
|
||||||
|
3,
|
||||||
|
uintptr(unsafe.Pointer(disp)),
|
||||||
|
uintptr(GetUserDefaultLCID()),
|
||||||
|
uintptr(unsafe.Pointer(&tinfo)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) {
|
||||||
|
var dispparams DISPPARAMS
|
||||||
|
|
||||||
|
if dispatch&DISPATCH_PROPERTYPUT != 0 {
|
||||||
|
dispnames := [1]int32{DISPID_PROPERTYPUT}
|
||||||
|
dispparams.rgdispidNamedArgs = uintptr(unsafe.Pointer(&dispnames[0]))
|
||||||
|
dispparams.cNamedArgs = 1
|
||||||
|
} else if dispatch&DISPATCH_PROPERTYPUTREF != 0 {
|
||||||
|
dispnames := [1]int32{DISPID_PROPERTYPUT}
|
||||||
|
dispparams.rgdispidNamedArgs = uintptr(unsafe.Pointer(&dispnames[0]))
|
||||||
|
dispparams.cNamedArgs = 1
|
||||||
|
}
|
||||||
|
var vargs []VARIANT
|
||||||
|
if len(params) > 0 {
|
||||||
|
vargs = make([]VARIANT, len(params))
|
||||||
|
for i, v := range params {
|
||||||
|
//n := len(params)-i-1
|
||||||
|
n := len(params) - i - 1
|
||||||
|
VariantInit(&vargs[n])
|
||||||
|
switch vv := v.(type) {
|
||||||
|
case bool:
|
||||||
|
if vv {
|
||||||
|
vargs[n] = NewVariant(VT_BOOL, 0xffff)
|
||||||
|
} else {
|
||||||
|
vargs[n] = NewVariant(VT_BOOL, 0)
|
||||||
|
}
|
||||||
|
case *bool:
|
||||||
|
vargs[n] = NewVariant(VT_BOOL|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*bool)))))
|
||||||
|
case uint8:
|
||||||
|
vargs[n] = NewVariant(VT_I1, int64(v.(uint8)))
|
||||||
|
case *uint8:
|
||||||
|
vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint8)))))
|
||||||
|
case int8:
|
||||||
|
vargs[n] = NewVariant(VT_I1, int64(v.(int8)))
|
||||||
|
case *int8:
|
||||||
|
vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int8)))))
|
||||||
|
case int16:
|
||||||
|
vargs[n] = NewVariant(VT_I2, int64(v.(int16)))
|
||||||
|
case *int16:
|
||||||
|
vargs[n] = NewVariant(VT_I2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int16)))))
|
||||||
|
case uint16:
|
||||||
|
vargs[n] = NewVariant(VT_UI2, int64(v.(uint16)))
|
||||||
|
case *uint16:
|
||||||
|
vargs[n] = NewVariant(VT_UI2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint16)))))
|
||||||
|
case int32:
|
||||||
|
vargs[n] = NewVariant(VT_I4, int64(v.(int32)))
|
||||||
|
case *int32:
|
||||||
|
vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int32)))))
|
||||||
|
case uint32:
|
||||||
|
vargs[n] = NewVariant(VT_UI4, int64(v.(uint32)))
|
||||||
|
case *uint32:
|
||||||
|
vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint32)))))
|
||||||
|
case int64:
|
||||||
|
vargs[n] = NewVariant(VT_I8, int64(v.(int64)))
|
||||||
|
case *int64:
|
||||||
|
vargs[n] = NewVariant(VT_I8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int64)))))
|
||||||
|
case uint64:
|
||||||
|
vargs[n] = NewVariant(VT_UI8, int64(uintptr(v.(uint64))))
|
||||||
|
case *uint64:
|
||||||
|
vargs[n] = NewVariant(VT_UI8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint64)))))
|
||||||
|
case int:
|
||||||
|
vargs[n] = NewVariant(VT_I4, int64(v.(int)))
|
||||||
|
case *int:
|
||||||
|
vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int)))))
|
||||||
|
case uint:
|
||||||
|
vargs[n] = NewVariant(VT_UI4, int64(v.(uint)))
|
||||||
|
case *uint:
|
||||||
|
vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint)))))
|
||||||
|
case float32:
|
||||||
|
vargs[n] = NewVariant(VT_R4, *(*int64)(unsafe.Pointer(&vv)))
|
||||||
|
case *float32:
|
||||||
|
vargs[n] = NewVariant(VT_R4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float32)))))
|
||||||
|
case float64:
|
||||||
|
vargs[n] = NewVariant(VT_R8, *(*int64)(unsafe.Pointer(&vv)))
|
||||||
|
case *float64:
|
||||||
|
vargs[n] = NewVariant(VT_R8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float64)))))
|
||||||
|
case *big.Int:
|
||||||
|
vargs[n] = NewVariant(VT_DECIMAL, v.(*big.Int).Int64())
|
||||||
|
case string:
|
||||||
|
vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(v.(string))))))
|
||||||
|
case *string:
|
||||||
|
vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*string)))))
|
||||||
|
case time.Time:
|
||||||
|
s := vv.Format("2006-01-02 15:04:05")
|
||||||
|
vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(s)))))
|
||||||
|
case *time.Time:
|
||||||
|
s := vv.Format("2006-01-02 15:04:05")
|
||||||
|
vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(&s))))
|
||||||
|
case *IDispatch:
|
||||||
|
vargs[n] = NewVariant(VT_DISPATCH, int64(uintptr(unsafe.Pointer(v.(*IDispatch)))))
|
||||||
|
case **IDispatch:
|
||||||
|
vargs[n] = NewVariant(VT_DISPATCH|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(**IDispatch)))))
|
||||||
|
case nil:
|
||||||
|
vargs[n] = NewVariant(VT_NULL, 0)
|
||||||
|
case *VARIANT:
|
||||||
|
vargs[n] = NewVariant(VT_VARIANT|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*VARIANT)))))
|
||||||
|
case []byte:
|
||||||
|
safeByteArray := safeArrayFromByteSlice(v.([]byte))
|
||||||
|
vargs[n] = NewVariant(VT_ARRAY|VT_UI1, int64(uintptr(unsafe.Pointer(safeByteArray))))
|
||||||
|
defer VariantClear(&vargs[n])
|
||||||
|
case []string:
|
||||||
|
safeByteArray := safeArrayFromStringSlice(v.([]string))
|
||||||
|
vargs[n] = NewVariant(VT_ARRAY|VT_BSTR, int64(uintptr(unsafe.Pointer(safeByteArray))))
|
||||||
|
defer VariantClear(&vargs[n])
|
||||||
|
default:
|
||||||
|
panic("unknown type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dispparams.rgvarg = uintptr(unsafe.Pointer(&vargs[0]))
|
||||||
|
dispparams.cArgs = uint32(len(params))
|
||||||
|
}
|
||||||
|
|
||||||
|
result = new(VARIANT)
|
||||||
|
var excepInfo EXCEPINFO
|
||||||
|
VariantInit(result)
|
||||||
|
hr, _, _ := syscall.Syscall9(
|
||||||
|
disp.VTable().Invoke,
|
||||||
|
9,
|
||||||
|
uintptr(unsafe.Pointer(disp)),
|
||||||
|
uintptr(dispid),
|
||||||
|
uintptr(unsafe.Pointer(IID_NULL)),
|
||||||
|
uintptr(GetUserDefaultLCID()),
|
||||||
|
uintptr(dispatch),
|
||||||
|
uintptr(unsafe.Pointer(&dispparams)),
|
||||||
|
uintptr(unsafe.Pointer(result)),
|
||||||
|
uintptr(unsafe.Pointer(&excepInfo)),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
excepInfo.renderStrings()
|
||||||
|
excepInfo.Clear()
|
||||||
|
err = NewErrorWithSubError(hr, excepInfo.description, excepInfo)
|
||||||
|
}
|
||||||
|
for i, varg := range vargs {
|
||||||
|
n := len(params) - i - 1
|
||||||
|
if varg.VT == VT_BSTR && varg.Val != 0 {
|
||||||
|
SysFreeString(((*int16)(unsafe.Pointer(uintptr(varg.Val)))))
|
||||||
|
}
|
||||||
|
if varg.VT == (VT_BSTR|VT_BYREF) && varg.Val != 0 {
|
||||||
|
*(params[n].(*string)) = LpOleStrToString(*(**uint16)(unsafe.Pointer(uintptr(varg.Val))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
19
vendor/github.com/go-ole/go-ole/ienumvariant.go
generated
vendored
Normal file
19
vendor/github.com/go-ole/go-ole/ienumvariant.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type IEnumVARIANT struct {
|
||||||
|
IUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type IEnumVARIANTVtbl struct {
|
||||||
|
IUnknownVtbl
|
||||||
|
Next uintptr
|
||||||
|
Skip uintptr
|
||||||
|
Reset uintptr
|
||||||
|
Clone uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IEnumVARIANT) VTable() *IEnumVARIANTVtbl {
|
||||||
|
return (*IEnumVARIANTVtbl)(unsafe.Pointer(v.RawVTable))
|
||||||
|
}
|
||||||
19
vendor/github.com/go-ole/go-ole/ienumvariant_func.go
generated
vendored
Normal file
19
vendor/github.com/go-ole/go-ole/ienumvariant_func.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
func (enum *IEnumVARIANT) Clone() (*IEnumVARIANT, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (enum *IEnumVARIANT) Reset() error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (enum *IEnumVARIANT) Skip(celt uint) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (enum *IEnumVARIANT) Next(celt uint) (VARIANT, uint, error) {
|
||||||
|
return NewVariant(VT_NULL, int64(0)), 0, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
63
vendor/github.com/go-ole/go-ole/ienumvariant_windows.go
generated
vendored
Normal file
63
vendor/github.com/go-ole/go-ole/ienumvariant_windows.go
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (enum *IEnumVARIANT) Clone() (cloned *IEnumVARIANT, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
enum.VTable().Clone,
|
||||||
|
2,
|
||||||
|
uintptr(unsafe.Pointer(enum)),
|
||||||
|
uintptr(unsafe.Pointer(&cloned)),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (enum *IEnumVARIANT) Reset() (err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
enum.VTable().Reset,
|
||||||
|
1,
|
||||||
|
uintptr(unsafe.Pointer(enum)),
|
||||||
|
0,
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (enum *IEnumVARIANT) Skip(celt uint) (err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
enum.VTable().Skip,
|
||||||
|
2,
|
||||||
|
uintptr(unsafe.Pointer(enum)),
|
||||||
|
uintptr(celt),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (enum *IEnumVARIANT) Next(celt uint) (array VARIANT, length uint, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall6(
|
||||||
|
enum.VTable().Next,
|
||||||
|
4,
|
||||||
|
uintptr(unsafe.Pointer(enum)),
|
||||||
|
uintptr(celt),
|
||||||
|
uintptr(unsafe.Pointer(&array)),
|
||||||
|
uintptr(unsafe.Pointer(&length)),
|
||||||
|
0,
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
18
vendor/github.com/go-ole/go-ole/iinspectable.go
generated
vendored
Normal file
18
vendor/github.com/go-ole/go-ole/iinspectable.go
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type IInspectable struct {
|
||||||
|
IUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type IInspectableVtbl struct {
|
||||||
|
IUnknownVtbl
|
||||||
|
GetIIds uintptr
|
||||||
|
GetRuntimeClassName uintptr
|
||||||
|
GetTrustLevel uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IInspectable) VTable() *IInspectableVtbl {
|
||||||
|
return (*IInspectableVtbl)(unsafe.Pointer(v.RawVTable))
|
||||||
|
}
|
||||||
15
vendor/github.com/go-ole/go-ole/iinspectable_func.go
generated
vendored
Normal file
15
vendor/github.com/go-ole/go-ole/iinspectable_func.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
func (v *IInspectable) GetIids() ([]*GUID, error) {
|
||||||
|
return []*GUID{}, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IInspectable) GetRuntimeClassName() (string, error) {
|
||||||
|
return "", NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IInspectable) GetTrustLevel() (uint32, error) {
|
||||||
|
return uint32(0), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
72
vendor/github.com/go-ole/go-ole/iinspectable_windows.go
generated
vendored
Normal file
72
vendor/github.com/go-ole/go-ole/iinspectable_windows.go
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"reflect"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (v *IInspectable) GetIids() (iids []*GUID, err error) {
|
||||||
|
var count uint32
|
||||||
|
var array uintptr
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
v.VTable().GetIIds,
|
||||||
|
3,
|
||||||
|
uintptr(unsafe.Pointer(v)),
|
||||||
|
uintptr(unsafe.Pointer(&count)),
|
||||||
|
uintptr(unsafe.Pointer(&array)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer CoTaskMemFree(array)
|
||||||
|
|
||||||
|
iids = make([]*GUID, count)
|
||||||
|
byteCount := count * uint32(unsafe.Sizeof(GUID{}))
|
||||||
|
slicehdr := reflect.SliceHeader{Data: array, Len: int(byteCount), Cap: int(byteCount)}
|
||||||
|
byteSlice := *(*[]byte)(unsafe.Pointer(&slicehdr))
|
||||||
|
reader := bytes.NewReader(byteSlice)
|
||||||
|
for i := range iids {
|
||||||
|
guid := GUID{}
|
||||||
|
err = binary.Read(reader, binary.LittleEndian, &guid)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
iids[i] = &guid
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IInspectable) GetRuntimeClassName() (s string, err error) {
|
||||||
|
var hstring HString
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
v.VTable().GetRuntimeClassName,
|
||||||
|
2,
|
||||||
|
uintptr(unsafe.Pointer(v)),
|
||||||
|
uintptr(unsafe.Pointer(&hstring)),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s = hstring.String()
|
||||||
|
DeleteHString(hstring)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IInspectable) GetTrustLevel() (level uint32, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
v.VTable().GetTrustLevel,
|
||||||
|
2,
|
||||||
|
uintptr(unsafe.Pointer(v)),
|
||||||
|
uintptr(unsafe.Pointer(&level)),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
21
vendor/github.com/go-ole/go-ole/iprovideclassinfo.go
generated
vendored
Normal file
21
vendor/github.com/go-ole/go-ole/iprovideclassinfo.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type IProvideClassInfo struct {
|
||||||
|
IUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type IProvideClassInfoVtbl struct {
|
||||||
|
IUnknownVtbl
|
||||||
|
GetClassInfo uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IProvideClassInfo) VTable() *IProvideClassInfoVtbl {
|
||||||
|
return (*IProvideClassInfoVtbl)(unsafe.Pointer(v.RawVTable))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IProvideClassInfo) GetClassInfo() (cinfo *ITypeInfo, err error) {
|
||||||
|
cinfo, err = getClassInfo(v)
|
||||||
|
return
|
||||||
|
}
|
||||||
7
vendor/github.com/go-ole/go-ole/iprovideclassinfo_func.go
generated
vendored
Normal file
7
vendor/github.com/go-ole/go-ole/iprovideclassinfo_func.go
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
21
vendor/github.com/go-ole/go-ole/iprovideclassinfo_windows.go
generated
vendored
Normal file
21
vendor/github.com/go-ole/go-ole/iprovideclassinfo_windows.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
disp.VTable().GetClassInfo,
|
||||||
|
2,
|
||||||
|
uintptr(unsafe.Pointer(disp)),
|
||||||
|
uintptr(unsafe.Pointer(&tinfo)),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
34
vendor/github.com/go-ole/go-ole/itypeinfo.go
generated
vendored
Normal file
34
vendor/github.com/go-ole/go-ole/itypeinfo.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type ITypeInfo struct {
|
||||||
|
IUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type ITypeInfoVtbl struct {
|
||||||
|
IUnknownVtbl
|
||||||
|
GetTypeAttr uintptr
|
||||||
|
GetTypeComp uintptr
|
||||||
|
GetFuncDesc uintptr
|
||||||
|
GetVarDesc uintptr
|
||||||
|
GetNames uintptr
|
||||||
|
GetRefTypeOfImplType uintptr
|
||||||
|
GetImplTypeFlags uintptr
|
||||||
|
GetIDsOfNames uintptr
|
||||||
|
Invoke uintptr
|
||||||
|
GetDocumentation uintptr
|
||||||
|
GetDllEntry uintptr
|
||||||
|
GetRefTypeInfo uintptr
|
||||||
|
AddressOfMember uintptr
|
||||||
|
CreateInstance uintptr
|
||||||
|
GetMops uintptr
|
||||||
|
GetContainingTypeLib uintptr
|
||||||
|
ReleaseTypeAttr uintptr
|
||||||
|
ReleaseFuncDesc uintptr
|
||||||
|
ReleaseVarDesc uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *ITypeInfo) VTable() *ITypeInfoVtbl {
|
||||||
|
return (*ITypeInfoVtbl)(unsafe.Pointer(v.RawVTable))
|
||||||
|
}
|
||||||
7
vendor/github.com/go-ole/go-ole/itypeinfo_func.go
generated
vendored
Normal file
7
vendor/github.com/go-ole/go-ole/itypeinfo_func.go
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
func (v *ITypeInfo) GetTypeAttr() (*TYPEATTR, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
21
vendor/github.com/go-ole/go-ole/itypeinfo_windows.go
generated
vendored
Normal file
21
vendor/github.com/go-ole/go-ole/itypeinfo_windows.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (v *ITypeInfo) GetTypeAttr() (tattr *TYPEATTR, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
uintptr(v.VTable().GetTypeAttr),
|
||||||
|
2,
|
||||||
|
uintptr(unsafe.Pointer(v)),
|
||||||
|
uintptr(unsafe.Pointer(&tattr)),
|
||||||
|
0)
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
57
vendor/github.com/go-ole/go-ole/iunknown.go
generated
vendored
Normal file
57
vendor/github.com/go-ole/go-ole/iunknown.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type IUnknown struct {
|
||||||
|
RawVTable *interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type IUnknownVtbl struct {
|
||||||
|
QueryInterface uintptr
|
||||||
|
AddRef uintptr
|
||||||
|
Release uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnknownLike interface {
|
||||||
|
QueryInterface(iid *GUID) (disp *IDispatch, err error)
|
||||||
|
AddRef() int32
|
||||||
|
Release() int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IUnknown) VTable() *IUnknownVtbl {
|
||||||
|
return (*IUnknownVtbl)(unsafe.Pointer(v.RawVTable))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IUnknown) PutQueryInterface(interfaceID *GUID, obj interface{}) error {
|
||||||
|
return reflectQueryInterface(v, v.VTable().QueryInterface, interfaceID, obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IUnknown) IDispatch(interfaceID *GUID) (dispatch *IDispatch, err error) {
|
||||||
|
err = v.PutQueryInterface(interfaceID, &dispatch)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IUnknown) IEnumVARIANT(interfaceID *GUID) (enum *IEnumVARIANT, err error) {
|
||||||
|
err = v.PutQueryInterface(interfaceID, &enum)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IUnknown) QueryInterface(iid *GUID) (*IDispatch, error) {
|
||||||
|
return queryInterface(v, iid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IUnknown) MustQueryInterface(iid *GUID) (disp *IDispatch) {
|
||||||
|
unk, err := queryInterface(v, iid)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return unk
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IUnknown) AddRef() int32 {
|
||||||
|
return addRef(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IUnknown) Release() int32 {
|
||||||
|
return release(v)
|
||||||
|
}
|
||||||
19
vendor/github.com/go-ole/go-ole/iunknown_func.go
generated
vendored
Normal file
19
vendor/github.com/go-ole/go-ole/iunknown_func.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addRef(unk *IUnknown) int32 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func release(unk *IUnknown) int32 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
58
vendor/github.com/go-ole/go-ole/iunknown_windows.go
generated
vendored
Normal file
58
vendor/github.com/go-ole/go-ole/iunknown_windows.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
|
||||||
|
selfValue := reflect.ValueOf(self).Elem()
|
||||||
|
objValue := reflect.ValueOf(obj).Elem()
|
||||||
|
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
method,
|
||||||
|
3,
|
||||||
|
selfValue.UnsafeAddr(),
|
||||||
|
uintptr(unsafe.Pointer(interfaceID)),
|
||||||
|
objValue.Addr().Pointer())
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
|
||||||
|
hr, _, _ := syscall.Syscall(
|
||||||
|
unk.VTable().QueryInterface,
|
||||||
|
3,
|
||||||
|
uintptr(unsafe.Pointer(unk)),
|
||||||
|
uintptr(unsafe.Pointer(iid)),
|
||||||
|
uintptr(unsafe.Pointer(&disp)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func addRef(unk *IUnknown) int32 {
|
||||||
|
ret, _, _ := syscall.Syscall(
|
||||||
|
unk.VTable().AddRef,
|
||||||
|
1,
|
||||||
|
uintptr(unsafe.Pointer(unk)),
|
||||||
|
0,
|
||||||
|
0)
|
||||||
|
return int32(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
func release(unk *IUnknown) int32 {
|
||||||
|
ret, _, _ := syscall.Syscall(
|
||||||
|
unk.VTable().Release,
|
||||||
|
1,
|
||||||
|
uintptr(unsafe.Pointer(unk)),
|
||||||
|
0,
|
||||||
|
0)
|
||||||
|
return int32(ret)
|
||||||
|
}
|
||||||
190
vendor/github.com/go-ole/go-ole/ole.go
generated
vendored
Normal file
190
vendor/github.com/go-ole/go-ole/ole.go
generated
vendored
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DISPPARAMS are the arguments that passed to methods or property.
|
||||||
|
type DISPPARAMS struct {
|
||||||
|
rgvarg uintptr
|
||||||
|
rgdispidNamedArgs uintptr
|
||||||
|
cArgs uint32
|
||||||
|
cNamedArgs uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXCEPINFO defines exception info.
|
||||||
|
type EXCEPINFO struct {
|
||||||
|
wCode uint16
|
||||||
|
wReserved uint16
|
||||||
|
bstrSource *uint16
|
||||||
|
bstrDescription *uint16
|
||||||
|
bstrHelpFile *uint16
|
||||||
|
dwHelpContext uint32
|
||||||
|
pvReserved uintptr
|
||||||
|
pfnDeferredFillIn uintptr
|
||||||
|
scode uint32
|
||||||
|
|
||||||
|
// Go-specific part. Don't move upper cos it'll break structure layout for native code.
|
||||||
|
rendered bool
|
||||||
|
source string
|
||||||
|
description string
|
||||||
|
helpFile string
|
||||||
|
}
|
||||||
|
|
||||||
|
// renderStrings translates BSTR strings to Go ones so `.Error` and `.String`
|
||||||
|
// could be safely called after `.Clear`. We need this when we can't rely on
|
||||||
|
// a caller to call `.Clear`.
|
||||||
|
func (e *EXCEPINFO) renderStrings() {
|
||||||
|
e.rendered = true
|
||||||
|
if e.bstrSource == nil {
|
||||||
|
e.source = "<nil>"
|
||||||
|
} else {
|
||||||
|
e.source = BstrToString(e.bstrSource)
|
||||||
|
}
|
||||||
|
if e.bstrDescription == nil {
|
||||||
|
e.description = "<nil>"
|
||||||
|
} else {
|
||||||
|
e.description = BstrToString(e.bstrDescription)
|
||||||
|
}
|
||||||
|
if e.bstrHelpFile == nil {
|
||||||
|
e.helpFile = "<nil>"
|
||||||
|
} else {
|
||||||
|
e.helpFile = BstrToString(e.bstrHelpFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear frees BSTR strings inside an EXCEPINFO and set it to NULL.
|
||||||
|
func (e *EXCEPINFO) Clear() {
|
||||||
|
freeBSTR := func(s *uint16) {
|
||||||
|
// SysFreeString don't return errors and is safe for call's on NULL.
|
||||||
|
// https://docs.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-sysfreestring
|
||||||
|
_ = SysFreeString((*int16)(unsafe.Pointer(s)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.bstrSource != nil {
|
||||||
|
freeBSTR(e.bstrSource)
|
||||||
|
e.bstrSource = nil
|
||||||
|
}
|
||||||
|
if e.bstrDescription != nil {
|
||||||
|
freeBSTR(e.bstrDescription)
|
||||||
|
e.bstrDescription = nil
|
||||||
|
}
|
||||||
|
if e.bstrHelpFile != nil {
|
||||||
|
freeBSTR(e.bstrHelpFile)
|
||||||
|
e.bstrHelpFile = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WCode return wCode in EXCEPINFO.
|
||||||
|
func (e EXCEPINFO) WCode() uint16 {
|
||||||
|
return e.wCode
|
||||||
|
}
|
||||||
|
|
||||||
|
// SCODE return scode in EXCEPINFO.
|
||||||
|
func (e EXCEPINFO) SCODE() uint32 {
|
||||||
|
return e.scode
|
||||||
|
}
|
||||||
|
|
||||||
|
// String convert EXCEPINFO to string.
|
||||||
|
func (e EXCEPINFO) String() string {
|
||||||
|
if !e.rendered {
|
||||||
|
e.renderStrings()
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
|
||||||
|
e.wCode, e.source, e.description, e.helpFile, e.dwHelpContext, e.scode,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements error interface and returns error string.
|
||||||
|
func (e EXCEPINFO) Error() string {
|
||||||
|
if !e.rendered {
|
||||||
|
e.renderStrings()
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.description != "<nil>" {
|
||||||
|
return strings.TrimSpace(e.description)
|
||||||
|
}
|
||||||
|
|
||||||
|
code := e.scode
|
||||||
|
if e.wCode != 0 {
|
||||||
|
code = uint32(e.wCode)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%v: %#x", e.source, code)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PARAMDATA defines parameter data type.
|
||||||
|
type PARAMDATA struct {
|
||||||
|
Name *int16
|
||||||
|
Vt uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
// METHODDATA defines method info.
|
||||||
|
type METHODDATA struct {
|
||||||
|
Name *uint16
|
||||||
|
Data *PARAMDATA
|
||||||
|
Dispid int32
|
||||||
|
Meth uint32
|
||||||
|
CC int32
|
||||||
|
CArgs uint32
|
||||||
|
Flags uint16
|
||||||
|
VtReturn uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// INTERFACEDATA defines interface info.
|
||||||
|
type INTERFACEDATA struct {
|
||||||
|
MethodData *METHODDATA
|
||||||
|
CMembers uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// Point is 2D vector type.
|
||||||
|
type Point struct {
|
||||||
|
X int32
|
||||||
|
Y int32
|
||||||
|
}
|
||||||
|
|
||||||
|
// Msg is message between processes.
|
||||||
|
type Msg struct {
|
||||||
|
Hwnd uint32
|
||||||
|
Message uint32
|
||||||
|
Wparam int32
|
||||||
|
Lparam int32
|
||||||
|
Time uint32
|
||||||
|
Pt Point
|
||||||
|
}
|
||||||
|
|
||||||
|
// TYPEDESC defines data type.
|
||||||
|
type TYPEDESC struct {
|
||||||
|
Hreftype uint32
|
||||||
|
VT uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLDESC defines IDL info.
|
||||||
|
type IDLDESC struct {
|
||||||
|
DwReserved uint32
|
||||||
|
WIDLFlags uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
// TYPEATTR defines type info.
|
||||||
|
type TYPEATTR struct {
|
||||||
|
Guid GUID
|
||||||
|
Lcid uint32
|
||||||
|
dwReserved uint32
|
||||||
|
MemidConstructor int32
|
||||||
|
MemidDestructor int32
|
||||||
|
LpstrSchema *uint16
|
||||||
|
CbSizeInstance uint32
|
||||||
|
Typekind int32
|
||||||
|
CFuncs uint16
|
||||||
|
CVars uint16
|
||||||
|
CImplTypes uint16
|
||||||
|
CbSizeVft uint16
|
||||||
|
CbAlignment uint16
|
||||||
|
WTypeFlags uint16
|
||||||
|
WMajorVerNum uint16
|
||||||
|
WMinorVerNum uint16
|
||||||
|
TdescAlias TYPEDESC
|
||||||
|
IdldescType IDLDESC
|
||||||
|
}
|
||||||
100
vendor/github.com/go-ole/go-ole/oleutil/connection.go
generated
vendored
Normal file
100
vendor/github.com/go-ole/go-ole/oleutil/connection.go
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package oleutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
ole "github.com/go-ole/go-ole"
|
||||||
|
)
|
||||||
|
|
||||||
|
type stdDispatch struct {
|
||||||
|
lpVtbl *stdDispatchVtbl
|
||||||
|
ref int32
|
||||||
|
iid *ole.GUID
|
||||||
|
iface interface{}
|
||||||
|
funcMap map[string]int32
|
||||||
|
}
|
||||||
|
|
||||||
|
type stdDispatchVtbl struct {
|
||||||
|
pQueryInterface uintptr
|
||||||
|
pAddRef uintptr
|
||||||
|
pRelease uintptr
|
||||||
|
pGetTypeInfoCount uintptr
|
||||||
|
pGetTypeInfo uintptr
|
||||||
|
pGetIDsOfNames uintptr
|
||||||
|
pInvoke uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func dispQueryInterface(this *ole.IUnknown, iid *ole.GUID, punk **ole.IUnknown) uint32 {
|
||||||
|
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||||
|
*punk = nil
|
||||||
|
if ole.IsEqualGUID(iid, ole.IID_IUnknown) ||
|
||||||
|
ole.IsEqualGUID(iid, ole.IID_IDispatch) {
|
||||||
|
dispAddRef(this)
|
||||||
|
*punk = this
|
||||||
|
return ole.S_OK
|
||||||
|
}
|
||||||
|
if ole.IsEqualGUID(iid, pthis.iid) {
|
||||||
|
dispAddRef(this)
|
||||||
|
*punk = this
|
||||||
|
return ole.S_OK
|
||||||
|
}
|
||||||
|
return ole.E_NOINTERFACE
|
||||||
|
}
|
||||||
|
|
||||||
|
func dispAddRef(this *ole.IUnknown) int32 {
|
||||||
|
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||||
|
pthis.ref++
|
||||||
|
return pthis.ref
|
||||||
|
}
|
||||||
|
|
||||||
|
func dispRelease(this *ole.IUnknown) int32 {
|
||||||
|
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||||
|
pthis.ref--
|
||||||
|
return pthis.ref
|
||||||
|
}
|
||||||
|
|
||||||
|
func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr {
|
||||||
|
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||||
|
names := make([]string, len(wnames))
|
||||||
|
for i := 0; i < len(names); i++ {
|
||||||
|
names[i] = ole.LpOleStrToString(wnames[i])
|
||||||
|
}
|
||||||
|
for n := 0; n < namelen; n++ {
|
||||||
|
if id, ok := pthis.funcMap[names[n]]; ok {
|
||||||
|
pdisp[n] = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ole.S_OK
|
||||||
|
}
|
||||||
|
|
||||||
|
func dispGetTypeInfoCount(pcount *int) uintptr {
|
||||||
|
if pcount != nil {
|
||||||
|
*pcount = 0
|
||||||
|
}
|
||||||
|
return ole.S_OK
|
||||||
|
}
|
||||||
|
|
||||||
|
func dispGetTypeInfo(ptypeif *uintptr) uintptr {
|
||||||
|
return ole.E_NOTIMPL
|
||||||
|
}
|
||||||
|
|
||||||
|
func dispInvoke(this *ole.IDispatch, dispid int32, riid *ole.GUID, lcid int, flags int16, dispparams *ole.DISPPARAMS, result *ole.VARIANT, pexcepinfo *ole.EXCEPINFO, nerr *uint) uintptr {
|
||||||
|
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||||
|
found := ""
|
||||||
|
for name, id := range pthis.funcMap {
|
||||||
|
if id == dispid {
|
||||||
|
found = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if found != "" {
|
||||||
|
rv := reflect.ValueOf(pthis.iface).Elem()
|
||||||
|
rm := rv.MethodByName(found)
|
||||||
|
rr := rm.Call([]reflect.Value{})
|
||||||
|
println(len(rr))
|
||||||
|
return ole.S_OK
|
||||||
|
}
|
||||||
|
return ole.E_NOTIMPL
|
||||||
|
}
|
||||||
10
vendor/github.com/go-ole/go-ole/oleutil/connection_func.go
generated
vendored
Normal file
10
vendor/github.com/go-ole/go-ole/oleutil/connection_func.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package oleutil
|
||||||
|
|
||||||
|
import ole "github.com/go-ole/go-ole"
|
||||||
|
|
||||||
|
// ConnectObject creates a connection point between two services for communication.
|
||||||
|
func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (uint32, error) {
|
||||||
|
return 0, ole.NewError(ole.E_NOTIMPL)
|
||||||
|
}
|
||||||
58
vendor/github.com/go-ole/go-ole/oleutil/connection_windows.go
generated
vendored
Normal file
58
vendor/github.com/go-ole/go-ole/oleutil/connection_windows.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package oleutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
ole "github.com/go-ole/go-ole"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConnectObject creates a connection point between two services for communication.
|
||||||
|
func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (cookie uint32, err error) {
|
||||||
|
unknown, err := disp.QueryInterface(ole.IID_IConnectionPointContainer)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
container := (*ole.IConnectionPointContainer)(unsafe.Pointer(unknown))
|
||||||
|
var point *ole.IConnectionPoint
|
||||||
|
err = container.FindConnectionPoint(iid, &point)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if edisp, ok := idisp.(*ole.IUnknown); ok {
|
||||||
|
cookie, err = point.Advise(edisp)
|
||||||
|
container.Release()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rv := reflect.ValueOf(disp).Elem()
|
||||||
|
if rv.Type().Kind() == reflect.Struct {
|
||||||
|
dest := &stdDispatch{}
|
||||||
|
dest.lpVtbl = &stdDispatchVtbl{}
|
||||||
|
dest.lpVtbl.pQueryInterface = syscall.NewCallback(dispQueryInterface)
|
||||||
|
dest.lpVtbl.pAddRef = syscall.NewCallback(dispAddRef)
|
||||||
|
dest.lpVtbl.pRelease = syscall.NewCallback(dispRelease)
|
||||||
|
dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(dispGetTypeInfoCount)
|
||||||
|
dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(dispGetTypeInfo)
|
||||||
|
dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(dispGetIDsOfNames)
|
||||||
|
dest.lpVtbl.pInvoke = syscall.NewCallback(dispInvoke)
|
||||||
|
dest.iface = disp
|
||||||
|
dest.iid = iid
|
||||||
|
cookie, err = point.Advise((*ole.IUnknown)(unsafe.Pointer(dest)))
|
||||||
|
container.Release()
|
||||||
|
if err != nil {
|
||||||
|
point.Release()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
container.Release()
|
||||||
|
|
||||||
|
return 0, ole.NewError(ole.E_INVALIDARG)
|
||||||
|
}
|
||||||
6
vendor/github.com/go-ole/go-ole/oleutil/go-get.go
generated
vendored
Normal file
6
vendor/github.com/go-ole/go-ole/oleutil/go-get.go
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// This file is here so go get succeeds as without it errors with:
|
||||||
|
// no buildable Go source files in ...
|
||||||
|
//
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package oleutil
|
||||||
127
vendor/github.com/go-ole/go-ole/oleutil/oleutil.go
generated
vendored
Normal file
127
vendor/github.com/go-ole/go-ole/oleutil/oleutil.go
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
package oleutil
|
||||||
|
|
||||||
|
import ole "github.com/go-ole/go-ole"
|
||||||
|
|
||||||
|
// ClassIDFrom retrieves class ID whether given is program ID or application string.
|
||||||
|
func ClassIDFrom(programID string) (classID *ole.GUID, err error) {
|
||||||
|
return ole.ClassIDFrom(programID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateObject creates object from programID based on interface type.
|
||||||
|
//
|
||||||
|
// Only supports IUnknown.
|
||||||
|
//
|
||||||
|
// Program ID can be either program ID or application string.
|
||||||
|
func CreateObject(programID string) (unknown *ole.IUnknown, err error) {
|
||||||
|
classID, err := ole.ClassIDFrom(programID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
unknown, err = ole.CreateInstance(classID, ole.IID_IUnknown)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetActiveObject retrieves active object for program ID and interface ID based
|
||||||
|
// on interface type.
|
||||||
|
//
|
||||||
|
// Only supports IUnknown.
|
||||||
|
//
|
||||||
|
// Program ID can be either program ID or application string.
|
||||||
|
func GetActiveObject(programID string) (unknown *ole.IUnknown, err error) {
|
||||||
|
classID, err := ole.ClassIDFrom(programID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
unknown, err = ole.GetActiveObject(classID, ole.IID_IUnknown)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CallMethod calls method on IDispatch with parameters.
|
||||||
|
func CallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||||
|
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_METHOD, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustCallMethod calls method on IDispatch with parameters or panics.
|
||||||
|
func MustCallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||||
|
r, err := CallMethod(disp, name, params...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetProperty retrieves property from IDispatch.
|
||||||
|
func GetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||||
|
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYGET, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustGetProperty retrieves property from IDispatch or panics.
|
||||||
|
func MustGetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||||
|
r, err := GetProperty(disp, name, params...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutProperty mutates property.
|
||||||
|
func PutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||||
|
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUT, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustPutProperty mutates property or panics.
|
||||||
|
func MustPutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||||
|
r, err := PutProperty(disp, name, params...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutPropertyRef mutates property reference.
|
||||||
|
func PutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||||
|
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUTREF, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustPutPropertyRef mutates property reference or panics.
|
||||||
|
func MustPutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||||
|
r, err := PutPropertyRef(disp, name, params...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func ForEach(disp *ole.IDispatch, f func(v *ole.VARIANT) error) error {
|
||||||
|
newEnum, err := disp.GetProperty("_NewEnum")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer newEnum.Clear()
|
||||||
|
|
||||||
|
enum, err := newEnum.ToIUnknown().IEnumVARIANT(ole.IID_IEnumVariant)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer enum.Release()
|
||||||
|
|
||||||
|
for item, length, err := enum.Next(1); length > 0; item, length, err = enum.Next(1) {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if ferr := f(&item); ferr != nil {
|
||||||
|
return ferr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
27
vendor/github.com/go-ole/go-ole/safearray.go
generated
vendored
Normal file
27
vendor/github.com/go-ole/go-ole/safearray.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// Package is meant to retrieve and process safe array data returned from COM.
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
// SafeArrayBound defines the SafeArray boundaries.
|
||||||
|
type SafeArrayBound struct {
|
||||||
|
Elements uint32
|
||||||
|
LowerBound int32
|
||||||
|
}
|
||||||
|
|
||||||
|
// SafeArray is how COM handles arrays.
|
||||||
|
type SafeArray struct {
|
||||||
|
Dimensions uint16
|
||||||
|
FeaturesFlag uint16
|
||||||
|
ElementsSize uint32
|
||||||
|
LocksAmount uint32
|
||||||
|
Data uint32
|
||||||
|
Bounds [16]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// SAFEARRAY is obsolete, exists for backwards compatibility.
|
||||||
|
// Use SafeArray
|
||||||
|
type SAFEARRAY SafeArray
|
||||||
|
|
||||||
|
// SAFEARRAYBOUND is obsolete, exists for backwards compatibility.
|
||||||
|
// Use SafeArrayBound
|
||||||
|
type SAFEARRAYBOUND SafeArrayBound
|
||||||
211
vendor/github.com/go-ole/go-ole/safearray_func.go
generated
vendored
Normal file
211
vendor/github.com/go-ole/go-ole/safearray_func.go
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// safeArrayAccessData returns raw array pointer.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayAccessData in Windows API.
|
||||||
|
func safeArrayAccessData(safearray *SafeArray) (uintptr, error) {
|
||||||
|
return uintptr(0), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayUnaccessData releases raw array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayUnaccessData in Windows API.
|
||||||
|
func safeArrayUnaccessData(safearray *SafeArray) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayAllocData allocates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayAllocData in Windows API.
|
||||||
|
func safeArrayAllocData(safearray *SafeArray) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayAllocDescriptor allocates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayAllocDescriptor in Windows API.
|
||||||
|
func safeArrayAllocDescriptor(dimensions uint32) (*SafeArray, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayAllocDescriptorEx allocates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayAllocDescriptorEx in Windows API.
|
||||||
|
func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (*SafeArray, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCopy returns copy of SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCopy in Windows API.
|
||||||
|
func safeArrayCopy(original *SafeArray) (*SafeArray, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCopyData duplicates SafeArray into another SafeArray object.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCopyData in Windows API.
|
||||||
|
func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCreate creates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCreate in Windows API.
|
||||||
|
func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (*SafeArray, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCreateEx creates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCreateEx in Windows API.
|
||||||
|
func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (*SafeArray, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCreateVector creates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCreateVector in Windows API.
|
||||||
|
func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (*SafeArray, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCreateVectorEx creates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCreateVectorEx in Windows API.
|
||||||
|
func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (*SafeArray, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayDestroy destroys SafeArray object.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayDestroy in Windows API.
|
||||||
|
func safeArrayDestroy(safearray *SafeArray) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayDestroyData destroys SafeArray object.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayDestroyData in Windows API.
|
||||||
|
func safeArrayDestroyData(safearray *SafeArray) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayDestroyDescriptor destroys SafeArray object.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayDestroyDescriptor in Windows API.
|
||||||
|
func safeArrayDestroyDescriptor(safearray *SafeArray) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetDim is the amount of dimensions in the SafeArray.
|
||||||
|
//
|
||||||
|
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||||
|
// multidimensional array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetDim in Windows API.
|
||||||
|
func safeArrayGetDim(safearray *SafeArray) (*uint32, error) {
|
||||||
|
u := uint32(0)
|
||||||
|
return &u, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetElementSize is the element size in bytes.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetElemsize in Windows API.
|
||||||
|
func safeArrayGetElementSize(safearray *SafeArray) (*uint32, error) {
|
||||||
|
u := uint32(0)
|
||||||
|
return &u, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetElement retrieves element at given index.
|
||||||
|
func safeArrayGetElement(safearray *SafeArray, index int32, pv unsafe.Pointer) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetElement retrieves element at given index and converts to string.
|
||||||
|
func safeArrayGetElementString(safearray *SafeArray, index int32) (string, error) {
|
||||||
|
return "", NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetIID is the InterfaceID of the elements in the SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetIID in Windows API.
|
||||||
|
func safeArrayGetIID(safearray *SafeArray) (*GUID, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetLBound returns lower bounds of SafeArray.
|
||||||
|
//
|
||||||
|
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||||
|
// multidimensional array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetLBound in Windows API.
|
||||||
|
func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (int32, error) {
|
||||||
|
return int32(0), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetUBound returns upper bounds of SafeArray.
|
||||||
|
//
|
||||||
|
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||||
|
// multidimensional array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetUBound in Windows API.
|
||||||
|
func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (int32, error) {
|
||||||
|
return int32(0), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetVartype returns data type of SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetVartype in Windows API.
|
||||||
|
func safeArrayGetVartype(safearray *SafeArray) (uint16, error) {
|
||||||
|
return uint16(0), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayLock locks SafeArray for reading to modify SafeArray.
|
||||||
|
//
|
||||||
|
// This must be called during some calls to ensure that another process does not
|
||||||
|
// read or write to the SafeArray during editing.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayLock in Windows API.
|
||||||
|
func safeArrayLock(safearray *SafeArray) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayUnlock unlocks SafeArray for reading.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayUnlock in Windows API.
|
||||||
|
func safeArrayUnlock(safearray *SafeArray) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayPutElement stores the data element at the specified location in the
|
||||||
|
// array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayPutElement in Windows API.
|
||||||
|
func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetRecordInfo accesses IRecordInfo info for custom types.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetRecordInfo in Windows API.
|
||||||
|
//
|
||||||
|
// XXX: Must implement IRecordInfo interface for this to return.
|
||||||
|
func safeArrayGetRecordInfo(safearray *SafeArray) (interface{}, error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArraySetRecordInfo mutates IRecordInfo info for custom types.
|
||||||
|
//
|
||||||
|
// AKA: SafeArraySetRecordInfo in Windows API.
|
||||||
|
//
|
||||||
|
// XXX: Must implement IRecordInfo interface for this to return.
|
||||||
|
func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) error {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
337
vendor/github.com/go-ole/go-ole/safearray_windows.go
generated
vendored
Normal file
337
vendor/github.com/go-ole/go-ole/safearray_windows.go
generated
vendored
Normal file
@@ -0,0 +1,337 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
procSafeArrayAccessData = modoleaut32.NewProc("SafeArrayAccessData")
|
||||||
|
procSafeArrayAllocData = modoleaut32.NewProc("SafeArrayAllocData")
|
||||||
|
procSafeArrayAllocDescriptor = modoleaut32.NewProc("SafeArrayAllocDescriptor")
|
||||||
|
procSafeArrayAllocDescriptorEx = modoleaut32.NewProc("SafeArrayAllocDescriptorEx")
|
||||||
|
procSafeArrayCopy = modoleaut32.NewProc("SafeArrayCopy")
|
||||||
|
procSafeArrayCopyData = modoleaut32.NewProc("SafeArrayCopyData")
|
||||||
|
procSafeArrayCreate = modoleaut32.NewProc("SafeArrayCreate")
|
||||||
|
procSafeArrayCreateEx = modoleaut32.NewProc("SafeArrayCreateEx")
|
||||||
|
procSafeArrayCreateVector = modoleaut32.NewProc("SafeArrayCreateVector")
|
||||||
|
procSafeArrayCreateVectorEx = modoleaut32.NewProc("SafeArrayCreateVectorEx")
|
||||||
|
procSafeArrayDestroy = modoleaut32.NewProc("SafeArrayDestroy")
|
||||||
|
procSafeArrayDestroyData = modoleaut32.NewProc("SafeArrayDestroyData")
|
||||||
|
procSafeArrayDestroyDescriptor = modoleaut32.NewProc("SafeArrayDestroyDescriptor")
|
||||||
|
procSafeArrayGetDim = modoleaut32.NewProc("SafeArrayGetDim")
|
||||||
|
procSafeArrayGetElement = modoleaut32.NewProc("SafeArrayGetElement")
|
||||||
|
procSafeArrayGetElemsize = modoleaut32.NewProc("SafeArrayGetElemsize")
|
||||||
|
procSafeArrayGetIID = modoleaut32.NewProc("SafeArrayGetIID")
|
||||||
|
procSafeArrayGetLBound = modoleaut32.NewProc("SafeArrayGetLBound")
|
||||||
|
procSafeArrayGetUBound = modoleaut32.NewProc("SafeArrayGetUBound")
|
||||||
|
procSafeArrayGetVartype = modoleaut32.NewProc("SafeArrayGetVartype")
|
||||||
|
procSafeArrayLock = modoleaut32.NewProc("SafeArrayLock")
|
||||||
|
procSafeArrayPtrOfIndex = modoleaut32.NewProc("SafeArrayPtrOfIndex")
|
||||||
|
procSafeArrayUnaccessData = modoleaut32.NewProc("SafeArrayUnaccessData")
|
||||||
|
procSafeArrayUnlock = modoleaut32.NewProc("SafeArrayUnlock")
|
||||||
|
procSafeArrayPutElement = modoleaut32.NewProc("SafeArrayPutElement")
|
||||||
|
//procSafeArrayRedim = modoleaut32.NewProc("SafeArrayRedim") // TODO
|
||||||
|
//procSafeArraySetIID = modoleaut32.NewProc("SafeArraySetIID") // TODO
|
||||||
|
procSafeArrayGetRecordInfo = modoleaut32.NewProc("SafeArrayGetRecordInfo")
|
||||||
|
procSafeArraySetRecordInfo = modoleaut32.NewProc("SafeArraySetRecordInfo")
|
||||||
|
)
|
||||||
|
|
||||||
|
// safeArrayAccessData returns raw array pointer.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayAccessData in Windows API.
|
||||||
|
// Todo: Test
|
||||||
|
func safeArrayAccessData(safearray *SafeArray) (element uintptr, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayAccessData.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(unsafe.Pointer(&element))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayUnaccessData releases raw array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayUnaccessData in Windows API.
|
||||||
|
func safeArrayUnaccessData(safearray *SafeArray) (err error) {
|
||||||
|
err = convertHresultToError(procSafeArrayUnaccessData.Call(uintptr(unsafe.Pointer(safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayAllocData allocates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayAllocData in Windows API.
|
||||||
|
func safeArrayAllocData(safearray *SafeArray) (err error) {
|
||||||
|
err = convertHresultToError(procSafeArrayAllocData.Call(uintptr(unsafe.Pointer(safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayAllocDescriptor allocates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayAllocDescriptor in Windows API.
|
||||||
|
func safeArrayAllocDescriptor(dimensions uint32) (safearray *SafeArray, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayAllocDescriptor.Call(uintptr(dimensions), uintptr(unsafe.Pointer(&safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayAllocDescriptorEx allocates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayAllocDescriptorEx in Windows API.
|
||||||
|
func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (safearray *SafeArray, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayAllocDescriptorEx.Call(
|
||||||
|
uintptr(variantType),
|
||||||
|
uintptr(dimensions),
|
||||||
|
uintptr(unsafe.Pointer(&safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCopy returns copy of SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCopy in Windows API.
|
||||||
|
func safeArrayCopy(original *SafeArray) (safearray *SafeArray, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayCopy.Call(
|
||||||
|
uintptr(unsafe.Pointer(original)),
|
||||||
|
uintptr(unsafe.Pointer(&safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCopyData duplicates SafeArray into another SafeArray object.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCopyData in Windows API.
|
||||||
|
func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) (err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayCopyData.Call(
|
||||||
|
uintptr(unsafe.Pointer(original)),
|
||||||
|
uintptr(unsafe.Pointer(duplicate))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCreate creates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCreate in Windows API.
|
||||||
|
func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (safearray *SafeArray, err error) {
|
||||||
|
sa, _, err := procSafeArrayCreate.Call(
|
||||||
|
uintptr(variantType),
|
||||||
|
uintptr(dimensions),
|
||||||
|
uintptr(unsafe.Pointer(bounds)))
|
||||||
|
safearray = (*SafeArray)(unsafe.Pointer(&sa))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCreateEx creates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCreateEx in Windows API.
|
||||||
|
func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (safearray *SafeArray, err error) {
|
||||||
|
sa, _, err := procSafeArrayCreateEx.Call(
|
||||||
|
uintptr(variantType),
|
||||||
|
uintptr(dimensions),
|
||||||
|
uintptr(unsafe.Pointer(bounds)),
|
||||||
|
extra)
|
||||||
|
safearray = (*SafeArray)(unsafe.Pointer(sa))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCreateVector creates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCreateVector in Windows API.
|
||||||
|
func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (safearray *SafeArray, err error) {
|
||||||
|
sa, _, err := procSafeArrayCreateVector.Call(
|
||||||
|
uintptr(variantType),
|
||||||
|
uintptr(lowerBound),
|
||||||
|
uintptr(length))
|
||||||
|
safearray = (*SafeArray)(unsafe.Pointer(sa))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayCreateVectorEx creates SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayCreateVectorEx in Windows API.
|
||||||
|
func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (safearray *SafeArray, err error) {
|
||||||
|
sa, _, err := procSafeArrayCreateVectorEx.Call(
|
||||||
|
uintptr(variantType),
|
||||||
|
uintptr(lowerBound),
|
||||||
|
uintptr(length),
|
||||||
|
extra)
|
||||||
|
safearray = (*SafeArray)(unsafe.Pointer(sa))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayDestroy destroys SafeArray object.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayDestroy in Windows API.
|
||||||
|
func safeArrayDestroy(safearray *SafeArray) (err error) {
|
||||||
|
err = convertHresultToError(procSafeArrayDestroy.Call(uintptr(unsafe.Pointer(safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayDestroyData destroys SafeArray object.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayDestroyData in Windows API.
|
||||||
|
func safeArrayDestroyData(safearray *SafeArray) (err error) {
|
||||||
|
err = convertHresultToError(procSafeArrayDestroyData.Call(uintptr(unsafe.Pointer(safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayDestroyDescriptor destroys SafeArray object.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayDestroyDescriptor in Windows API.
|
||||||
|
func safeArrayDestroyDescriptor(safearray *SafeArray) (err error) {
|
||||||
|
err = convertHresultToError(procSafeArrayDestroyDescriptor.Call(uintptr(unsafe.Pointer(safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetDim is the amount of dimensions in the SafeArray.
|
||||||
|
//
|
||||||
|
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||||
|
// multidimensional array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetDim in Windows API.
|
||||||
|
func safeArrayGetDim(safearray *SafeArray) (dimensions *uint32, err error) {
|
||||||
|
l, _, err := procSafeArrayGetDim.Call(uintptr(unsafe.Pointer(safearray)))
|
||||||
|
dimensions = (*uint32)(unsafe.Pointer(l))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetElementSize is the element size in bytes.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetElemsize in Windows API.
|
||||||
|
func safeArrayGetElementSize(safearray *SafeArray) (length *uint32, err error) {
|
||||||
|
l, _, err := procSafeArrayGetElemsize.Call(uintptr(unsafe.Pointer(safearray)))
|
||||||
|
length = (*uint32)(unsafe.Pointer(l))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetElement retrieves element at given index.
|
||||||
|
func safeArrayGetElement(safearray *SafeArray, index int32, pv unsafe.Pointer) error {
|
||||||
|
return convertHresultToError(
|
||||||
|
procSafeArrayGetElement.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(unsafe.Pointer(&index)),
|
||||||
|
uintptr(pv)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetElementString retrieves element at given index and converts to string.
|
||||||
|
func safeArrayGetElementString(safearray *SafeArray, index int32) (str string, err error) {
|
||||||
|
var element *int16
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayGetElement.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(unsafe.Pointer(&index)),
|
||||||
|
uintptr(unsafe.Pointer(&element))))
|
||||||
|
str = BstrToString(*(**uint16)(unsafe.Pointer(&element)))
|
||||||
|
SysFreeString(element)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetIID is the InterfaceID of the elements in the SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetIID in Windows API.
|
||||||
|
func safeArrayGetIID(safearray *SafeArray) (guid *GUID, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayGetIID.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(unsafe.Pointer(&guid))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetLBound returns lower bounds of SafeArray.
|
||||||
|
//
|
||||||
|
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||||
|
// multidimensional array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetLBound in Windows API.
|
||||||
|
func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (lowerBound int32, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayGetLBound.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(dimension),
|
||||||
|
uintptr(unsafe.Pointer(&lowerBound))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetUBound returns upper bounds of SafeArray.
|
||||||
|
//
|
||||||
|
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||||
|
// multidimensional array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetUBound in Windows API.
|
||||||
|
func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (upperBound int32, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayGetUBound.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(dimension),
|
||||||
|
uintptr(unsafe.Pointer(&upperBound))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetVartype returns data type of SafeArray.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetVartype in Windows API.
|
||||||
|
func safeArrayGetVartype(safearray *SafeArray) (varType uint16, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayGetVartype.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(unsafe.Pointer(&varType))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayLock locks SafeArray for reading to modify SafeArray.
|
||||||
|
//
|
||||||
|
// This must be called during some calls to ensure that another process does not
|
||||||
|
// read or write to the SafeArray during editing.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayLock in Windows API.
|
||||||
|
func safeArrayLock(safearray *SafeArray) (err error) {
|
||||||
|
err = convertHresultToError(procSafeArrayLock.Call(uintptr(unsafe.Pointer(safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayUnlock unlocks SafeArray for reading.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayUnlock in Windows API.
|
||||||
|
func safeArrayUnlock(safearray *SafeArray) (err error) {
|
||||||
|
err = convertHresultToError(procSafeArrayUnlock.Call(uintptr(unsafe.Pointer(safearray))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayPutElement stores the data element at the specified location in the
|
||||||
|
// array.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayPutElement in Windows API.
|
||||||
|
func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) (err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayPutElement.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(unsafe.Pointer(&index)),
|
||||||
|
uintptr(unsafe.Pointer(element))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArrayGetRecordInfo accesses IRecordInfo info for custom types.
|
||||||
|
//
|
||||||
|
// AKA: SafeArrayGetRecordInfo in Windows API.
|
||||||
|
//
|
||||||
|
// XXX: Must implement IRecordInfo interface for this to return.
|
||||||
|
func safeArrayGetRecordInfo(safearray *SafeArray) (recordInfo interface{}, err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArrayGetRecordInfo.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(unsafe.Pointer(&recordInfo))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeArraySetRecordInfo mutates IRecordInfo info for custom types.
|
||||||
|
//
|
||||||
|
// AKA: SafeArraySetRecordInfo in Windows API.
|
||||||
|
//
|
||||||
|
// XXX: Must implement IRecordInfo interface for this to return.
|
||||||
|
func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) (err error) {
|
||||||
|
err = convertHresultToError(
|
||||||
|
procSafeArraySetRecordInfo.Call(
|
||||||
|
uintptr(unsafe.Pointer(safearray)),
|
||||||
|
uintptr(unsafe.Pointer(&recordInfo))))
|
||||||
|
return
|
||||||
|
}
|
||||||
140
vendor/github.com/go-ole/go-ole/safearrayconversion.go
generated
vendored
Normal file
140
vendor/github.com/go-ole/go-ole/safearrayconversion.go
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
// Helper for converting SafeArray to array of objects.
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SafeArrayConversion struct {
|
||||||
|
Array *SafeArray
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sac *SafeArrayConversion) ToStringArray() (strings []string) {
|
||||||
|
totalElements, _ := sac.TotalElements(0)
|
||||||
|
strings = make([]string, totalElements)
|
||||||
|
|
||||||
|
for i := int32(0); i < totalElements; i++ {
|
||||||
|
strings[int32(i)], _ = safeArrayGetElementString(sac.Array, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sac *SafeArrayConversion) ToByteArray() (bytes []byte) {
|
||||||
|
totalElements, _ := sac.TotalElements(0)
|
||||||
|
bytes = make([]byte, totalElements)
|
||||||
|
|
||||||
|
for i := int32(0); i < totalElements; i++ {
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&bytes[int32(i)]))
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sac *SafeArrayConversion) ToValueArray() (values []interface{}) {
|
||||||
|
totalElements, _ := sac.TotalElements(0)
|
||||||
|
values = make([]interface{}, totalElements)
|
||||||
|
vt, _ := safeArrayGetVartype(sac.Array)
|
||||||
|
|
||||||
|
for i := int32(0); i < totalElements; i++ {
|
||||||
|
switch VT(vt) {
|
||||||
|
case VT_BOOL:
|
||||||
|
var v bool
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_I1:
|
||||||
|
var v int8
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_I2:
|
||||||
|
var v int16
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_I4:
|
||||||
|
var v int32
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_I8:
|
||||||
|
var v int64
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_UI1:
|
||||||
|
var v uint8
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_UI2:
|
||||||
|
var v uint16
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_UI4:
|
||||||
|
var v uint32
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_UI8:
|
||||||
|
var v uint64
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_R4:
|
||||||
|
var v float32
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_R8:
|
||||||
|
var v float64
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v
|
||||||
|
case VT_BSTR:
|
||||||
|
v , _ := safeArrayGetElementString(sac.Array, i)
|
||||||
|
values[i] = v
|
||||||
|
case VT_VARIANT:
|
||||||
|
var v VARIANT
|
||||||
|
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||||
|
values[i] = v.Value()
|
||||||
|
v.Clear()
|
||||||
|
default:
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sac *SafeArrayConversion) GetType() (varType uint16, err error) {
|
||||||
|
return safeArrayGetVartype(sac.Array)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sac *SafeArrayConversion) GetDimensions() (dimensions *uint32, err error) {
|
||||||
|
return safeArrayGetDim(sac.Array)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sac *SafeArrayConversion) GetSize() (length *uint32, err error) {
|
||||||
|
return safeArrayGetElementSize(sac.Array)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sac *SafeArrayConversion) TotalElements(index uint32) (totalElements int32, err error) {
|
||||||
|
if index < 1 {
|
||||||
|
index = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get array bounds
|
||||||
|
var LowerBounds int32
|
||||||
|
var UpperBounds int32
|
||||||
|
|
||||||
|
LowerBounds, err = safeArrayGetLBound(sac.Array, index)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
UpperBounds, err = safeArrayGetUBound(sac.Array, index)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
totalElements = UpperBounds - LowerBounds + 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release Safe Array memory
|
||||||
|
func (sac *SafeArrayConversion) Release() {
|
||||||
|
safeArrayDestroy(sac.Array)
|
||||||
|
}
|
||||||
33
vendor/github.com/go-ole/go-ole/safearrayslices.go
generated
vendored
Normal file
33
vendor/github.com/go-ole/go-ole/safearrayslices.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func safeArrayFromByteSlice(slice []byte) *SafeArray {
|
||||||
|
array, _ := safeArrayCreateVector(VT_UI1, 0, uint32(len(slice)))
|
||||||
|
|
||||||
|
if array == nil {
|
||||||
|
panic("Could not convert []byte to SAFEARRAY")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, v := range slice {
|
||||||
|
safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(&v)))
|
||||||
|
}
|
||||||
|
return array
|
||||||
|
}
|
||||||
|
|
||||||
|
func safeArrayFromStringSlice(slice []string) *SafeArray {
|
||||||
|
array, _ := safeArrayCreateVector(VT_BSTR, 0, uint32(len(slice)))
|
||||||
|
|
||||||
|
if array == nil {
|
||||||
|
panic("Could not convert []string to SAFEARRAY")
|
||||||
|
}
|
||||||
|
// SysAllocStringLen(s)
|
||||||
|
for i, v := range slice {
|
||||||
|
safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(SysAllocStringLen(v))))
|
||||||
|
}
|
||||||
|
return array
|
||||||
|
}
|
||||||
101
vendor/github.com/go-ole/go-ole/utility.go
generated
vendored
Normal file
101
vendor/github.com/go-ole/go-ole/utility.go
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unicode/utf16"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ClassIDFrom retrieves class ID whether given is program ID or application string.
|
||||||
|
//
|
||||||
|
// Helper that provides check against both Class ID from Program ID and Class ID from string. It is
|
||||||
|
// faster, if you know which you are using, to use the individual functions, but this will check
|
||||||
|
// against available functions for you.
|
||||||
|
func ClassIDFrom(programID string) (classID *GUID, err error) {
|
||||||
|
classID, err = CLSIDFromProgID(programID)
|
||||||
|
if err != nil {
|
||||||
|
classID, err = CLSIDFromString(programID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BytePtrToString converts byte pointer to a Go string.
|
||||||
|
func BytePtrToString(p *byte) string {
|
||||||
|
a := (*[10000]uint8)(unsafe.Pointer(p))
|
||||||
|
i := 0
|
||||||
|
for a[i] != 0 {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return string(a[:i])
|
||||||
|
}
|
||||||
|
|
||||||
|
// UTF16PtrToString is alias for LpOleStrToString.
|
||||||
|
//
|
||||||
|
// Kept for compatibility reasons.
|
||||||
|
func UTF16PtrToString(p *uint16) string {
|
||||||
|
return LpOleStrToString(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LpOleStrToString converts COM Unicode to Go string.
|
||||||
|
func LpOleStrToString(p *uint16) string {
|
||||||
|
if p == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
length := lpOleStrLen(p)
|
||||||
|
a := make([]uint16, length)
|
||||||
|
|
||||||
|
ptr := unsafe.Pointer(p)
|
||||||
|
|
||||||
|
for i := 0; i < int(length); i++ {
|
||||||
|
a[i] = *(*uint16)(ptr)
|
||||||
|
ptr = unsafe.Pointer(uintptr(ptr) + 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(utf16.Decode(a))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BstrToString converts COM binary string to Go string.
|
||||||
|
func BstrToString(p *uint16) string {
|
||||||
|
if p == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
length := SysStringLen((*int16)(unsafe.Pointer(p)))
|
||||||
|
a := make([]uint16, length)
|
||||||
|
|
||||||
|
ptr := unsafe.Pointer(p)
|
||||||
|
|
||||||
|
for i := 0; i < int(length); i++ {
|
||||||
|
a[i] = *(*uint16)(ptr)
|
||||||
|
ptr = unsafe.Pointer(uintptr(ptr) + 2)
|
||||||
|
}
|
||||||
|
return string(utf16.Decode(a))
|
||||||
|
}
|
||||||
|
|
||||||
|
// lpOleStrLen returns the length of Unicode string.
|
||||||
|
func lpOleStrLen(p *uint16) (length int64) {
|
||||||
|
if p == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr := unsafe.Pointer(p)
|
||||||
|
|
||||||
|
for i := 0; ; i++ {
|
||||||
|
if 0 == *(*uint16)(ptr) {
|
||||||
|
length = int64(i)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
ptr = unsafe.Pointer(uintptr(ptr) + 2)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertHresultToError converts syscall to error, if call is unsuccessful.
|
||||||
|
func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) {
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
15
vendor/github.com/go-ole/go-ole/variables.go
generated
vendored
Normal file
15
vendor/github.com/go-ole/go-ole/variables.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
modcombase = windows.NewLazySystemDLL("combase.dll")
|
||||||
|
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||||
|
modole32 = windows.NewLazySystemDLL("ole32.dll")
|
||||||
|
modoleaut32 = windows.NewLazySystemDLL("oleaut32.dll")
|
||||||
|
moduser32 = windows.NewLazySystemDLL("user32.dll")
|
||||||
|
)
|
||||||
105
vendor/github.com/go-ole/go-ole/variant.go
generated
vendored
Normal file
105
vendor/github.com/go-ole/go-ole/variant.go
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package ole
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
// NewVariant returns new variant based on type and value.
|
||||||
|
func NewVariant(vt VT, val int64) VARIANT {
|
||||||
|
return VARIANT{VT: vt, Val: val}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToIUnknown converts Variant to Unknown object.
|
||||||
|
func (v *VARIANT) ToIUnknown() *IUnknown {
|
||||||
|
if v.VT != VT_UNKNOWN {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return (*IUnknown)(unsafe.Pointer(uintptr(v.Val)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToIDispatch converts variant to dispatch object.
|
||||||
|
func (v *VARIANT) ToIDispatch() *IDispatch {
|
||||||
|
if v.VT != VT_DISPATCH {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return (*IDispatch)(unsafe.Pointer(uintptr(v.Val)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToArray converts variant to SafeArray helper.
|
||||||
|
func (v *VARIANT) ToArray() *SafeArrayConversion {
|
||||||
|
if v.VT != VT_SAFEARRAY {
|
||||||
|
if v.VT&VT_ARRAY == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var safeArray *SafeArray = (*SafeArray)(unsafe.Pointer(uintptr(v.Val)))
|
||||||
|
return &SafeArrayConversion{safeArray}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToString converts variant to Go string.
|
||||||
|
func (v *VARIANT) ToString() string {
|
||||||
|
if v.VT != VT_BSTR {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return BstrToString(*(**uint16)(unsafe.Pointer(&v.Val)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the memory of variant object.
|
||||||
|
func (v *VARIANT) Clear() error {
|
||||||
|
return VariantClear(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns variant value based on its type.
|
||||||
|
//
|
||||||
|
// Currently supported types: 2- and 4-byte integers, strings, bools.
|
||||||
|
// Note that 64-bit integers, datetimes, and other types are stored as strings
|
||||||
|
// and will be returned as strings.
|
||||||
|
//
|
||||||
|
// Needs to be further converted, because this returns an interface{}.
|
||||||
|
func (v *VARIANT) Value() interface{} {
|
||||||
|
switch v.VT {
|
||||||
|
case VT_I1:
|
||||||
|
return int8(v.Val)
|
||||||
|
case VT_UI1:
|
||||||
|
return uint8(v.Val)
|
||||||
|
case VT_I2:
|
||||||
|
return int16(v.Val)
|
||||||
|
case VT_UI2:
|
||||||
|
return uint16(v.Val)
|
||||||
|
case VT_I4:
|
||||||
|
return int32(v.Val)
|
||||||
|
case VT_UI4:
|
||||||
|
return uint32(v.Val)
|
||||||
|
case VT_I8:
|
||||||
|
return int64(v.Val)
|
||||||
|
case VT_UI8:
|
||||||
|
return uint64(v.Val)
|
||||||
|
case VT_INT:
|
||||||
|
return int(v.Val)
|
||||||
|
case VT_UINT:
|
||||||
|
return uint(v.Val)
|
||||||
|
case VT_INT_PTR:
|
||||||
|
return uintptr(v.Val) // TODO
|
||||||
|
case VT_UINT_PTR:
|
||||||
|
return uintptr(v.Val)
|
||||||
|
case VT_R4:
|
||||||
|
return *(*float32)(unsafe.Pointer(&v.Val))
|
||||||
|
case VT_R8:
|
||||||
|
return *(*float64)(unsafe.Pointer(&v.Val))
|
||||||
|
case VT_BSTR:
|
||||||
|
return v.ToString()
|
||||||
|
case VT_DATE:
|
||||||
|
// VT_DATE type will either return float64 or time.Time.
|
||||||
|
d := uint64(v.Val)
|
||||||
|
date, err := GetVariantDate(d)
|
||||||
|
if err != nil {
|
||||||
|
return float64(v.Val)
|
||||||
|
}
|
||||||
|
return date
|
||||||
|
case VT_UNKNOWN:
|
||||||
|
return v.ToIUnknown()
|
||||||
|
case VT_DISPATCH:
|
||||||
|
return v.ToIDispatch()
|
||||||
|
case VT_BOOL:
|
||||||
|
return (v.Val & 0xffff) != 0
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
11
vendor/github.com/go-ole/go-ole/variant_386.go
generated
vendored
Normal file
11
vendor/github.com/go-ole/go-ole/variant_386.go
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// +build 386
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
type VARIANT struct {
|
||||||
|
VT VT // 2
|
||||||
|
wReserved1 uint16 // 4
|
||||||
|
wReserved2 uint16 // 6
|
||||||
|
wReserved3 uint16 // 8
|
||||||
|
Val int64 // 16
|
||||||
|
}
|
||||||
12
vendor/github.com/go-ole/go-ole/variant_amd64.go
generated
vendored
Normal file
12
vendor/github.com/go-ole/go-ole/variant_amd64.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// +build amd64
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
type VARIANT struct {
|
||||||
|
VT VT // 2
|
||||||
|
wReserved1 uint16 // 4
|
||||||
|
wReserved2 uint16 // 6
|
||||||
|
wReserved3 uint16 // 8
|
||||||
|
Val int64 // 16
|
||||||
|
_ [8]byte // 24
|
||||||
|
}
|
||||||
11
vendor/github.com/go-ole/go-ole/variant_arm.go
generated
vendored
Normal file
11
vendor/github.com/go-ole/go-ole/variant_arm.go
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// +build arm
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
type VARIANT struct {
|
||||||
|
VT VT // 2
|
||||||
|
wReserved1 uint16 // 4
|
||||||
|
wReserved2 uint16 // 6
|
||||||
|
wReserved3 uint16 // 8
|
||||||
|
Val int64 // 16
|
||||||
|
}
|
||||||
13
vendor/github.com/go-ole/go-ole/variant_arm64.go
generated
vendored
Normal file
13
vendor/github.com/go-ole/go-ole/variant_arm64.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
//go:build arm64
|
||||||
|
// +build arm64
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
type VARIANT struct {
|
||||||
|
VT VT // 2
|
||||||
|
wReserved1 uint16 // 4
|
||||||
|
wReserved2 uint16 // 6
|
||||||
|
wReserved3 uint16 // 8
|
||||||
|
Val int64 // 16
|
||||||
|
_ [8]byte // 24
|
||||||
|
}
|
||||||
22
vendor/github.com/go-ole/go-ole/variant_date_386.go
generated
vendored
Normal file
22
vendor/github.com/go-ole/go-ole/variant_date_386.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// +build windows,386
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
||||||
|
func GetVariantDate(value uint64) (time.Time, error) {
|
||||||
|
var st syscall.Systemtime
|
||||||
|
v1 := uint32(value)
|
||||||
|
v2 := uint32(value >> 32)
|
||||||
|
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(v1), uintptr(v2), uintptr(unsafe.Pointer(&st)))
|
||||||
|
if r != 0 {
|
||||||
|
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
|
||||||
|
}
|
||||||
|
return time.Now(), errors.New("Could not convert to time, passing current time.")
|
||||||
|
}
|
||||||
20
vendor/github.com/go-ole/go-ole/variant_date_amd64.go
generated
vendored
Normal file
20
vendor/github.com/go-ole/go-ole/variant_date_amd64.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// +build windows,amd64
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
||||||
|
func GetVariantDate(value uint64) (time.Time, error) {
|
||||||
|
var st syscall.Systemtime
|
||||||
|
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(value), uintptr(unsafe.Pointer(&st)))
|
||||||
|
if r != 0 {
|
||||||
|
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
|
||||||
|
}
|
||||||
|
return time.Now(), errors.New("Could not convert to time, passing current time.")
|
||||||
|
}
|
||||||
22
vendor/github.com/go-ole/go-ole/variant_date_arm.go
generated
vendored
Normal file
22
vendor/github.com/go-ole/go-ole/variant_date_arm.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// +build windows,arm
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
||||||
|
func GetVariantDate(value uint64) (time.Time, error) {
|
||||||
|
var st syscall.Systemtime
|
||||||
|
v1 := uint32(value)
|
||||||
|
v2 := uint32(value >> 32)
|
||||||
|
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(v1), uintptr(v2), uintptr(unsafe.Pointer(&st)))
|
||||||
|
if r != 0 {
|
||||||
|
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
|
||||||
|
}
|
||||||
|
return time.Now(), errors.New("Could not convert to time, passing current time.")
|
||||||
|
}
|
||||||
23
vendor/github.com/go-ole/go-ole/variant_date_arm64.go
generated
vendored
Normal file
23
vendor/github.com/go-ole/go-ole/variant_date_arm64.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//go:build windows && arm64
|
||||||
|
// +build windows,arm64
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
||||||
|
func GetVariantDate(value uint64) (time.Time, error) {
|
||||||
|
var st syscall.Systemtime
|
||||||
|
v1 := uint32(value)
|
||||||
|
v2 := uint32(value >> 32)
|
||||||
|
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(v1), uintptr(v2), uintptr(unsafe.Pointer(&st)))
|
||||||
|
if r != 0 {
|
||||||
|
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
|
||||||
|
}
|
||||||
|
return time.Now(), errors.New("Could not convert to time, passing current time.")
|
||||||
|
}
|
||||||
12
vendor/github.com/go-ole/go-ole/variant_ppc64le.go
generated
vendored
Normal file
12
vendor/github.com/go-ole/go-ole/variant_ppc64le.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// +build ppc64le
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
type VARIANT struct {
|
||||||
|
VT VT // 2
|
||||||
|
wReserved1 uint16 // 4
|
||||||
|
wReserved2 uint16 // 6
|
||||||
|
wReserved3 uint16 // 8
|
||||||
|
Val int64 // 16
|
||||||
|
_ [8]byte // 24
|
||||||
|
}
|
||||||
12
vendor/github.com/go-ole/go-ole/variant_s390x.go
generated
vendored
Normal file
12
vendor/github.com/go-ole/go-ole/variant_s390x.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// +build s390x
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
type VARIANT struct {
|
||||||
|
VT VT // 2
|
||||||
|
wReserved1 uint16 // 4
|
||||||
|
wReserved2 uint16 // 6
|
||||||
|
wReserved3 uint16 // 8
|
||||||
|
Val int64 // 16
|
||||||
|
_ [8]byte // 24
|
||||||
|
}
|
||||||
58
vendor/github.com/go-ole/go-ole/vt_string.go
generated
vendored
Normal file
58
vendor/github.com/go-ole/go-ole/vt_string.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// generated by stringer -output vt_string.go -type VT; DO NOT EDIT
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
const (
|
||||||
|
_VT_name_0 = "VT_EMPTYVT_NULLVT_I2VT_I4VT_R4VT_R8VT_CYVT_DATEVT_BSTRVT_DISPATCHVT_ERRORVT_BOOLVT_VARIANTVT_UNKNOWNVT_DECIMAL"
|
||||||
|
_VT_name_1 = "VT_I1VT_UI1VT_UI2VT_UI4VT_I8VT_UI8VT_INTVT_UINTVT_VOIDVT_HRESULTVT_PTRVT_SAFEARRAYVT_CARRAYVT_USERDEFINEDVT_LPSTRVT_LPWSTR"
|
||||||
|
_VT_name_2 = "VT_RECORDVT_INT_PTRVT_UINT_PTR"
|
||||||
|
_VT_name_3 = "VT_FILETIMEVT_BLOBVT_STREAMVT_STORAGEVT_STREAMED_OBJECTVT_STORED_OBJECTVT_BLOB_OBJECTVT_CFVT_CLSID"
|
||||||
|
_VT_name_4 = "VT_BSTR_BLOBVT_VECTOR"
|
||||||
|
_VT_name_5 = "VT_ARRAY"
|
||||||
|
_VT_name_6 = "VT_BYREF"
|
||||||
|
_VT_name_7 = "VT_RESERVED"
|
||||||
|
_VT_name_8 = "VT_ILLEGAL"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_VT_index_0 = [...]uint8{0, 8, 15, 20, 25, 30, 35, 40, 47, 54, 65, 73, 80, 90, 100, 110}
|
||||||
|
_VT_index_1 = [...]uint8{0, 5, 11, 17, 23, 28, 34, 40, 47, 54, 64, 70, 82, 91, 105, 113, 122}
|
||||||
|
_VT_index_2 = [...]uint8{0, 9, 19, 30}
|
||||||
|
_VT_index_3 = [...]uint8{0, 11, 18, 27, 37, 55, 71, 85, 90, 98}
|
||||||
|
_VT_index_4 = [...]uint8{0, 12, 21}
|
||||||
|
_VT_index_5 = [...]uint8{0, 8}
|
||||||
|
_VT_index_6 = [...]uint8{0, 8}
|
||||||
|
_VT_index_7 = [...]uint8{0, 11}
|
||||||
|
_VT_index_8 = [...]uint8{0, 10}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i VT) String() string {
|
||||||
|
switch {
|
||||||
|
case 0 <= i && i <= 14:
|
||||||
|
return _VT_name_0[_VT_index_0[i]:_VT_index_0[i+1]]
|
||||||
|
case 16 <= i && i <= 31:
|
||||||
|
i -= 16
|
||||||
|
return _VT_name_1[_VT_index_1[i]:_VT_index_1[i+1]]
|
||||||
|
case 36 <= i && i <= 38:
|
||||||
|
i -= 36
|
||||||
|
return _VT_name_2[_VT_index_2[i]:_VT_index_2[i+1]]
|
||||||
|
case 64 <= i && i <= 72:
|
||||||
|
i -= 64
|
||||||
|
return _VT_name_3[_VT_index_3[i]:_VT_index_3[i+1]]
|
||||||
|
case 4095 <= i && i <= 4096:
|
||||||
|
i -= 4095
|
||||||
|
return _VT_name_4[_VT_index_4[i]:_VT_index_4[i+1]]
|
||||||
|
case i == 8192:
|
||||||
|
return _VT_name_5
|
||||||
|
case i == 16384:
|
||||||
|
return _VT_name_6
|
||||||
|
case i == 32768:
|
||||||
|
return _VT_name_7
|
||||||
|
case i == 65535:
|
||||||
|
return _VT_name_8
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("VT(%d)", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
99
vendor/github.com/go-ole/go-ole/winrt.go
generated
vendored
Normal file
99
vendor/github.com/go-ole/go-ole/winrt.go
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"syscall"
|
||||||
|
"unicode/utf8"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
procRoInitialize = modcombase.NewProc("RoInitialize")
|
||||||
|
procRoActivateInstance = modcombase.NewProc("RoActivateInstance")
|
||||||
|
procRoGetActivationFactory = modcombase.NewProc("RoGetActivationFactory")
|
||||||
|
procWindowsCreateString = modcombase.NewProc("WindowsCreateString")
|
||||||
|
procWindowsDeleteString = modcombase.NewProc("WindowsDeleteString")
|
||||||
|
procWindowsGetStringRawBuffer = modcombase.NewProc("WindowsGetStringRawBuffer")
|
||||||
|
)
|
||||||
|
|
||||||
|
func RoInitialize(thread_type uint32) (err error) {
|
||||||
|
hr, _, _ := procRoInitialize.Call(uintptr(thread_type))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func RoActivateInstance(clsid string) (ins *IInspectable, err error) {
|
||||||
|
hClsid, err := NewHString(clsid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer DeleteHString(hClsid)
|
||||||
|
|
||||||
|
hr, _, _ := procRoActivateInstance.Call(
|
||||||
|
uintptr(unsafe.Pointer(hClsid)),
|
||||||
|
uintptr(unsafe.Pointer(&ins)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error) {
|
||||||
|
hClsid, err := NewHString(clsid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer DeleteHString(hClsid)
|
||||||
|
|
||||||
|
hr, _, _ := procRoGetActivationFactory.Call(
|
||||||
|
uintptr(unsafe.Pointer(hClsid)),
|
||||||
|
uintptr(unsafe.Pointer(iid)),
|
||||||
|
uintptr(unsafe.Pointer(&ins)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// HString is handle string for pointers.
|
||||||
|
type HString uintptr
|
||||||
|
|
||||||
|
// NewHString returns a new HString for Go string.
|
||||||
|
func NewHString(s string) (hstring HString, err error) {
|
||||||
|
u16 := syscall.StringToUTF16Ptr(s)
|
||||||
|
len := uint32(utf8.RuneCountInString(s))
|
||||||
|
hr, _, _ := procWindowsCreateString.Call(
|
||||||
|
uintptr(unsafe.Pointer(u16)),
|
||||||
|
uintptr(len),
|
||||||
|
uintptr(unsafe.Pointer(&hstring)))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteHString deletes HString.
|
||||||
|
func DeleteHString(hstring HString) (err error) {
|
||||||
|
hr, _, _ := procWindowsDeleteString.Call(uintptr(hstring))
|
||||||
|
if hr != 0 {
|
||||||
|
err = NewError(hr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns Go string value of HString.
|
||||||
|
func (h HString) String() string {
|
||||||
|
var u16buf uintptr
|
||||||
|
var u16len uint32
|
||||||
|
u16buf, _, _ = procWindowsGetStringRawBuffer.Call(
|
||||||
|
uintptr(h),
|
||||||
|
uintptr(unsafe.Pointer(&u16len)))
|
||||||
|
|
||||||
|
u16hdr := reflect.SliceHeader{Data: u16buf, Len: int(u16len), Cap: int(u16len)}
|
||||||
|
u16 := *(*[]uint16)(unsafe.Pointer(&u16hdr))
|
||||||
|
return syscall.UTF16ToString(u16)
|
||||||
|
}
|
||||||
36
vendor/github.com/go-ole/go-ole/winrt_doc.go
generated
vendored
Normal file
36
vendor/github.com/go-ole/go-ole/winrt_doc.go
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package ole
|
||||||
|
|
||||||
|
// RoInitialize
|
||||||
|
func RoInitialize(thread_type uint32) (err error) {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoActivateInstance
|
||||||
|
func RoActivateInstance(clsid string) (ins *IInspectable, err error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoGetActivationFactory
|
||||||
|
func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error) {
|
||||||
|
return nil, NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HString is handle string for pointers.
|
||||||
|
type HString uintptr
|
||||||
|
|
||||||
|
// NewHString returns a new HString for Go string.
|
||||||
|
func NewHString(s string) (hstring HString, err error) {
|
||||||
|
return HString(uintptr(0)), NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteHString deletes HString.
|
||||||
|
func DeleteHString(hstring HString) (err error) {
|
||||||
|
return NewError(E_NOTIMPL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns Go string value of HString.
|
||||||
|
func (h HString) String() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
12
vendor/github.com/lufia/plan9stats/.gitignore
generated
vendored
Normal file
12
vendor/github.com/lufia/plan9stats/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, build with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
29
vendor/github.com/lufia/plan9stats/LICENSE
generated
vendored
Normal file
29
vendor/github.com/lufia/plan9stats/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
BSD 3-Clause License
|
||||||
|
|
||||||
|
Copyright (c) 2019, KADOTA, Kyohei
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
13
vendor/github.com/lufia/plan9stats/README.md
generated
vendored
Normal file
13
vendor/github.com/lufia/plan9stats/README.md
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# plan9stats
|
||||||
|
A module for retrieving statistics of Plan 9
|
||||||
|
|
||||||
|
[![GoDev][godev-image]][godev-url]
|
||||||
|
[![Actions Status][actions-image]][actions-url]
|
||||||
|
[![Coverage Status][coveralls-image]][coveralls-url]
|
||||||
|
|
||||||
|
[godev-image]: https://pkg.go.dev/badge/github.com/lufia/plan9stats
|
||||||
|
[godev-url]: https://pkg.go.dev/github.com/lufia/plan9stats
|
||||||
|
[actions-image]: https://github.com/lufia/plan9stats/workflows/Test/badge.svg?branch=main
|
||||||
|
[actions-url]: https://github.com/lufia/plan9stats/actions?workflow=Test
|
||||||
|
[coveralls-image]: https://coveralls.io/repos/github/lufia/plan9stats/badge.svg
|
||||||
|
[coveralls-url]: https://coveralls.io/github/lufia/plan9stats
|
||||||
291
vendor/github.com/lufia/plan9stats/cpu.go
generated
vendored
Normal file
291
vendor/github.com/lufia/plan9stats/cpu.go
generated
vendored
Normal file
@@ -0,0 +1,291 @@
|
|||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CPUType represents /dev/cputype.
|
||||||
|
type CPUType struct {
|
||||||
|
Name string
|
||||||
|
Clock int // clock rate in MHz
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadCPUType(ctx context.Context, opts ...Option) (*CPUType, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
var c CPUType
|
||||||
|
if err := readCPUType(cfg.rootdir, &c); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type SysStats struct {
|
||||||
|
ID int
|
||||||
|
NumCtxSwitch int64
|
||||||
|
NumInterrupt int64
|
||||||
|
NumSyscall int64
|
||||||
|
NumFault int64
|
||||||
|
NumTLBFault int64
|
||||||
|
NumTLBPurge int64
|
||||||
|
LoadAvg int64 // in units of milli-CPUs and is decayed over time
|
||||||
|
Idle int // percentage
|
||||||
|
Interrupt int // percentage
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadSysStats reads system statistics from /dev/sysstat.
|
||||||
|
func ReadSysStats(ctx context.Context, opts ...Option) ([]*SysStats, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
file := filepath.Join(cfg.rootdir, "/dev/sysstat")
|
||||||
|
f, err := os.Open(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
var stats []*SysStats
|
||||||
|
for scanner.Scan() {
|
||||||
|
a := strings.Fields(scanner.Text())
|
||||||
|
if len(a) != 10 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
p intParser
|
||||||
|
stat SysStats
|
||||||
|
)
|
||||||
|
stat.ID = p.ParseInt(a[0], 10)
|
||||||
|
stat.NumCtxSwitch = p.ParseInt64(a[1], 10)
|
||||||
|
stat.NumInterrupt = p.ParseInt64(a[2], 10)
|
||||||
|
stat.NumSyscall = p.ParseInt64(a[3], 10)
|
||||||
|
stat.NumFault = p.ParseInt64(a[4], 10)
|
||||||
|
stat.NumTLBFault = p.ParseInt64(a[5], 10)
|
||||||
|
stat.NumTLBPurge = p.ParseInt64(a[6], 10)
|
||||||
|
stat.LoadAvg = p.ParseInt64(a[7], 10)
|
||||||
|
stat.Idle = p.ParseInt(a[8], 10)
|
||||||
|
stat.Interrupt = p.ParseInt(a[9], 10)
|
||||||
|
if err := p.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
stats = append(stats, &stat)
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readCPUType(rootdir string, c *CPUType) error {
|
||||||
|
file := filepath.Join(rootdir, "/dev/cputype")
|
||||||
|
b, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b = bytes.TrimSpace(b)
|
||||||
|
i := bytes.LastIndexByte(b, ' ')
|
||||||
|
if i < 0 {
|
||||||
|
return fmt.Errorf("%s: invalid format", file)
|
||||||
|
}
|
||||||
|
clock, err := strconv.Atoi(string(b[i+1:]))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Name = string(b[:i])
|
||||||
|
c.Clock = clock
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time represents /dev/time.
|
||||||
|
type Time struct {
|
||||||
|
Unix time.Duration
|
||||||
|
UnixNano time.Duration
|
||||||
|
Ticks int64 // clock ticks
|
||||||
|
Freq int64 //cloc frequency
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uptime returns uptime.
|
||||||
|
func (t *Time) Uptime() time.Duration {
|
||||||
|
v := float64(t.Ticks) / float64(t.Freq)
|
||||||
|
return time.Duration(v*1000_000_000) * time.Nanosecond
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadTime(ctx context.Context, opts ...Option) (*Time, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
file := filepath.Join(cfg.rootdir, "/dev/time")
|
||||||
|
var t Time
|
||||||
|
if err := readTime(file, &t); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &t, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcStatus represents a /proc/n/status.
|
||||||
|
type ProcStatus struct {
|
||||||
|
Name string
|
||||||
|
User string
|
||||||
|
State string
|
||||||
|
Times CPUTime
|
||||||
|
MemUsed int64 // in units of 1024 bytes
|
||||||
|
BasePriority uint32 // 0(low) to 19(high)
|
||||||
|
Priority uint32 // 0(low) to 19(high)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CPUTime represents /dev/cputime or a part of /proc/n/status.
|
||||||
|
type CPUTime struct {
|
||||||
|
User time.Duration // the time in user mode (millisecconds)
|
||||||
|
Sys time.Duration
|
||||||
|
Real time.Duration
|
||||||
|
ChildUser time.Duration // exited children and descendants time in user mode
|
||||||
|
ChildSys time.Duration
|
||||||
|
ChildReal time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// CPUStats emulates Linux's /proc/stat.
|
||||||
|
type CPUStats struct {
|
||||||
|
User time.Duration
|
||||||
|
Sys time.Duration
|
||||||
|
Idle time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadCPUStats(ctx context.Context, opts ...Option) (*CPUStats, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
a, err := ReadSysStats(ctx, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := filepath.Join(cfg.rootdir, "/proc")
|
||||||
|
d, err := os.Open(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer d.Close()
|
||||||
|
|
||||||
|
names, err := d.Readdirnames(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var up uint32parser
|
||||||
|
pids := make([]uint32, len(names))
|
||||||
|
for i, s := range names {
|
||||||
|
if s == "trace" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pids[i] = up.Parse(s)
|
||||||
|
}
|
||||||
|
if err := up.err; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sort.Slice(pids, func(i, j int) bool {
|
||||||
|
return pids[i] < pids[j]
|
||||||
|
})
|
||||||
|
|
||||||
|
var stat CPUStats
|
||||||
|
for _, pid := range pids {
|
||||||
|
s := strconv.FormatUint(uint64(pid), 10)
|
||||||
|
file := filepath.Join(dir, s, "status")
|
||||||
|
var p ProcStatus
|
||||||
|
if err := readProcStatus(file, &p); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
stat.User += p.Times.User
|
||||||
|
stat.Sys += p.Times.Sys
|
||||||
|
}
|
||||||
|
|
||||||
|
var t Time
|
||||||
|
file := filepath.Join(cfg.rootdir, "/dev/time")
|
||||||
|
if err := readTime(file, &t); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// In multi-processor host, Idle should multiple by number of cores.
|
||||||
|
u := t.Uptime() * time.Duration(len(a))
|
||||||
|
stat.Idle = u - stat.User - stat.Sys
|
||||||
|
return &stat, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readProcStatus(file string, p *ProcStatus) error {
|
||||||
|
b, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fields := strings.Fields(string(b))
|
||||||
|
if len(fields) != 12 {
|
||||||
|
return errors.New("invalid format")
|
||||||
|
}
|
||||||
|
p.Name = string(fields[0])
|
||||||
|
p.User = string(fields[1])
|
||||||
|
p.State = string(fields[2])
|
||||||
|
var up uint32parser
|
||||||
|
p.Times.User = time.Duration(up.Parse(fields[3])) * time.Millisecond
|
||||||
|
p.Times.Sys = time.Duration(up.Parse(fields[4])) * time.Millisecond
|
||||||
|
p.Times.Real = time.Duration(up.Parse(fields[5])) * time.Millisecond
|
||||||
|
p.Times.ChildUser = time.Duration(up.Parse(fields[6])) * time.Millisecond
|
||||||
|
p.Times.ChildSys = time.Duration(up.Parse(fields[7])) * time.Millisecond
|
||||||
|
p.Times.ChildReal = time.Duration(up.Parse(fields[8])) * time.Millisecond
|
||||||
|
p.MemUsed, err = strconv.ParseInt(fields[9], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.BasePriority = up.Parse(fields[10])
|
||||||
|
p.Priority = up.Parse(fields[11])
|
||||||
|
return up.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func readTime(file string, t *Time) error {
|
||||||
|
b, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fields := strings.Fields(string(b))
|
||||||
|
if len(fields) != 4 {
|
||||||
|
return errors.New("invalid format")
|
||||||
|
}
|
||||||
|
n, err := strconv.ParseInt(fields[0], 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
t.Unix = time.Duration(n) * time.Second
|
||||||
|
v, err := strconv.ParseInt(fields[1], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
t.UnixNano = time.Duration(v) * time.Nanosecond
|
||||||
|
t.Ticks, err = strconv.ParseInt(fields[2], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
t.Freq, err = strconv.ParseInt(fields[3], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type uint32parser struct {
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *uint32parser) Parse(s string) uint32 {
|
||||||
|
if p.err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
n, err := strconv.ParseUint(s, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
p.err = err
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return uint32(n)
|
||||||
|
}
|
||||||
116
vendor/github.com/lufia/plan9stats/disk.go
generated
vendored
Normal file
116
vendor/github.com/lufia/plan9stats/disk.go
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Storage represents /dev/sdXX/ctl.
|
||||||
|
type Storage struct {
|
||||||
|
Name string
|
||||||
|
Model string
|
||||||
|
Capacity int64
|
||||||
|
Partitions []*Partition
|
||||||
|
}
|
||||||
|
|
||||||
|
// Partition represents a part of /dev/sdXX/ctl.
|
||||||
|
type Partition struct {
|
||||||
|
Name string
|
||||||
|
Start uint64
|
||||||
|
End uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadStorages(ctx context.Context, opts ...Option) ([]*Storage, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
sdctl := filepath.Join(cfg.rootdir, "/dev/sdctl")
|
||||||
|
f, err := os.Open(sdctl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var a []*Storage
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
fields := bytes.Split(scanner.Bytes(), delim)
|
||||||
|
if len(fields) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
exp := string(fields[0]) + "*"
|
||||||
|
if !strings.HasPrefix(exp, "sd") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dir := filepath.Join(cfg.rootdir, "/dev", exp)
|
||||||
|
m, err := filepath.Glob(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, dir := range m {
|
||||||
|
s, err := readStorage(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
a = append(a, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readStorage(dir string) (*Storage, error) {
|
||||||
|
ctl := filepath.Join(dir, "ctl")
|
||||||
|
f, err := os.Open(ctl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var s Storage
|
||||||
|
s.Name = filepath.Base(dir)
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Bytes()
|
||||||
|
switch {
|
||||||
|
case bytes.HasPrefix(line, []byte("inquiry ")):
|
||||||
|
s.Model = string(bytes.TrimSpace(line[7:]))
|
||||||
|
case bytes.HasPrefix(line, []byte("geometry ")):
|
||||||
|
fields := bytes.Split(line, delim)
|
||||||
|
if len(fields) < 3 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var p intParser
|
||||||
|
sec := p.ParseInt64(string(fields[1]), 10)
|
||||||
|
size := p.ParseInt64(string(fields[2]), 10)
|
||||||
|
if err := p.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
s.Capacity = sec * size
|
||||||
|
case bytes.HasPrefix(line, []byte("part ")):
|
||||||
|
fields := bytes.Split(line, delim)
|
||||||
|
if len(fields) < 4 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var p intParser
|
||||||
|
start := p.ParseUint64(string(fields[2]), 10)
|
||||||
|
end := p.ParseUint64(string(fields[3]), 10)
|
||||||
|
if err := p.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
s.Partitions = append(s.Partitions, &Partition{
|
||||||
|
Name: string(fields[1]),
|
||||||
|
Start: start,
|
||||||
|
End: end,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &s, nil
|
||||||
|
}
|
||||||
2
vendor/github.com/lufia/plan9stats/doc.go
generated
vendored
Normal file
2
vendor/github.com/lufia/plan9stats/doc.go
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Package stats provides statistic utilities for Plan 9.
|
||||||
|
package stats
|
||||||
223
vendor/github.com/lufia/plan9stats/host.go
generated
vendored
Normal file
223
vendor/github.com/lufia/plan9stats/host.go
generated
vendored
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
delim = []byte{' '}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Host represents host status.
|
||||||
|
type Host struct {
|
||||||
|
Sysname string
|
||||||
|
Storages []*Storage
|
||||||
|
Interfaces []*Interface
|
||||||
|
}
|
||||||
|
|
||||||
|
// MemStats represents the memory statistics.
|
||||||
|
type MemStats struct {
|
||||||
|
Total int64 // total memory in byte
|
||||||
|
PageSize int64 // a page size in byte
|
||||||
|
KernelPages int64
|
||||||
|
UserPages Gauge
|
||||||
|
SwapPages Gauge
|
||||||
|
|
||||||
|
Malloced Gauge // kernel malloced data in byte
|
||||||
|
Graphics Gauge // kernel graphics data in byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gauge is used/available gauge.
|
||||||
|
type Gauge struct {
|
||||||
|
Used int64
|
||||||
|
Avail int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Gauge) Free() int64 {
|
||||||
|
return g.Avail - g.Used
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadMemStats reads memory statistics from /dev/swap.
|
||||||
|
func ReadMemStats(ctx context.Context, opts ...Option) (*MemStats, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
swap := filepath.Join(cfg.rootdir, "/dev/swap")
|
||||||
|
f, err := os.Open(swap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var stat MemStats
|
||||||
|
m := map[string]interface{}{
|
||||||
|
"memory": &stat.Total,
|
||||||
|
"pagesize": &stat.PageSize,
|
||||||
|
"kernel": &stat.KernelPages,
|
||||||
|
"user": &stat.UserPages,
|
||||||
|
"swap": &stat.SwapPages,
|
||||||
|
"kernel malloc": &stat.Malloced,
|
||||||
|
"kernel draw": &stat.Graphics,
|
||||||
|
}
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
fields := bytes.SplitN(scanner.Bytes(), delim, 2)
|
||||||
|
if len(fields) < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch key := string(fields[1]); key {
|
||||||
|
case "memory", "pagesize", "kernel":
|
||||||
|
v := m[key].(*int64)
|
||||||
|
n, err := strconv.ParseInt(string(fields[0]), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
*v = n
|
||||||
|
case "user", "swap", "kernel malloc", "kernel draw":
|
||||||
|
v := m[key].(*Gauge)
|
||||||
|
if err := parseGauge(string(fields[0]), v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &stat, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGauge(s string, r *Gauge) error {
|
||||||
|
a := strings.SplitN(s, "/", 2)
|
||||||
|
if len(a) != 2 {
|
||||||
|
return fmt.Errorf("can't parse ratio: %s", s)
|
||||||
|
}
|
||||||
|
var p intParser
|
||||||
|
u := p.ParseInt64(a[0], 10)
|
||||||
|
n := p.ParseInt64(a[1], 10)
|
||||||
|
if err := p.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.Used = u
|
||||||
|
r.Avail = n
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Interface struct {
|
||||||
|
Name string
|
||||||
|
Addr string
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
numEther = 8 // see ether(3)
|
||||||
|
numIpifc = 16 // see ip(3)
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadInterfaces reads network interfaces from etherN.
|
||||||
|
func ReadInterfaces(ctx context.Context, opts ...Option) ([]*Interface, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
var a []*Interface
|
||||||
|
for i := 0; i < numEther; i++ {
|
||||||
|
p, err := readInterface(cfg.rootdir, i)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
a = append(a, p)
|
||||||
|
}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readInterface(netroot string, i int) (*Interface, error) {
|
||||||
|
ether := fmt.Sprintf("ether%d", i)
|
||||||
|
dir := filepath.Join(netroot, ether)
|
||||||
|
info, err := os.Stat(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
return nil, fmt.Errorf("%s: is not directory", dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
addr, err := ioutil.ReadFile(filepath.Join(dir, "addr"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &Interface{
|
||||||
|
Name: ether,
|
||||||
|
Addr: string(addr),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
netdirs = []string{"/net", "/net.alt"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadHost reads host status.
|
||||||
|
func ReadHost(ctx context.Context, opts ...Option) (*Host, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
var h Host
|
||||||
|
name, err := readSysname(cfg.rootdir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
h.Sysname = name
|
||||||
|
|
||||||
|
a, err := ReadStorages(ctx, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
h.Storages = a
|
||||||
|
|
||||||
|
for _, s := range netdirs {
|
||||||
|
netroot := filepath.Join(cfg.rootdir, s)
|
||||||
|
ifaces, err := ReadInterfaces(ctx, WithRootDir(netroot))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
h.Interfaces = append(h.Interfaces, ifaces...)
|
||||||
|
}
|
||||||
|
return &h, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readSysname(rootdir string) (string, error) {
|
||||||
|
file := filepath.Join(rootdir, "/dev/sysname")
|
||||||
|
b, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(bytes.TrimSpace(b)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type IPStats struct {
|
||||||
|
ID int // number of interface in ipifc dir
|
||||||
|
Device string // associated physical device
|
||||||
|
MTU int // max transfer unit
|
||||||
|
Sendra6 uint8 // on == send router adv
|
||||||
|
Recvra6 uint8 // on == recv router adv
|
||||||
|
|
||||||
|
Pktin int64 // packets read
|
||||||
|
Pktout int64 // packets written
|
||||||
|
Errin int64 // read errors
|
||||||
|
Errout int64 // write errors
|
||||||
|
}
|
||||||
|
|
||||||
|
type Iplifc struct {
|
||||||
|
IP net.IP
|
||||||
|
Mask net.IPMask
|
||||||
|
Net net.IP // ip & mask
|
||||||
|
PerfLifetime int64 // preferred lifetime
|
||||||
|
ValidLifetime int64 // valid lifetime
|
||||||
|
}
|
||||||
|
|
||||||
|
type Ipv6rp struct {
|
||||||
|
// TODO(lufia): see ip(2)
|
||||||
|
}
|
||||||
40
vendor/github.com/lufia/plan9stats/int.go
generated
vendored
Normal file
40
vendor/github.com/lufia/plan9stats/int.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type intParser struct {
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *intParser) ParseInt(s string, base int) int {
|
||||||
|
if p.err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var n int64
|
||||||
|
n, p.err = strconv.ParseInt(s, base, 0)
|
||||||
|
return int(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *intParser) ParseInt64(s string, base int) int64 {
|
||||||
|
if p.err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var n int64
|
||||||
|
n, p.err = strconv.ParseInt(s, base, 64)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *intParser) ParseUint64(s string, base int) uint64 {
|
||||||
|
if p.err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var n uint64
|
||||||
|
n, p.err = strconv.ParseUint(s, base, 64)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *intParser) Err() error {
|
||||||
|
return p.err
|
||||||
|
}
|
||||||
21
vendor/github.com/lufia/plan9stats/opts.go
generated
vendored
Normal file
21
vendor/github.com/lufia/plan9stats/opts.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package stats
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rootdir string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Option func(*Config)
|
||||||
|
|
||||||
|
func newConfig(opts ...Option) *Config {
|
||||||
|
var cfg Config
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(&cfg)
|
||||||
|
}
|
||||||
|
return &cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithRootDir(dir string) Option {
|
||||||
|
return func(cfg *Config) {
|
||||||
|
cfg.rootdir = dir
|
||||||
|
}
|
||||||
|
}
|
||||||
88
vendor/github.com/lufia/plan9stats/stats.go
generated
vendored
Normal file
88
vendor/github.com/lufia/plan9stats/stats.go
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InterfaceStats struct {
|
||||||
|
PacketsReceived int64 // in packets
|
||||||
|
Link int // link status
|
||||||
|
PacketsSent int64 // out packets
|
||||||
|
NumCRCErr int // input CRC errors
|
||||||
|
NumOverflows int // packet overflows
|
||||||
|
NumSoftOverflows int // software overflow
|
||||||
|
NumFramingErr int // framing errors
|
||||||
|
NumBufferingErr int // buffering errors
|
||||||
|
NumOutputErr int // output errors
|
||||||
|
Promiscuous int // number of promiscuous opens
|
||||||
|
Mbps int // megabits per sec
|
||||||
|
Addr string
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadInterfaceStats(ctx context.Context, opts ...Option) (*InterfaceStats, error) {
|
||||||
|
cfg := newConfig(opts...)
|
||||||
|
file := filepath.Join(cfg.rootdir, "stats")
|
||||||
|
f, err := os.Open(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var stats InterfaceStats
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
s := strings.TrimSpace(scanner.Text())
|
||||||
|
a := strings.SplitN(s, ":", 2)
|
||||||
|
if len(a) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var p intParser
|
||||||
|
v := strings.TrimSpace(a[1])
|
||||||
|
switch a[0] {
|
||||||
|
case "in":
|
||||||
|
stats.PacketsReceived = p.ParseInt64(v, 10)
|
||||||
|
case "link":
|
||||||
|
stats.Link = p.ParseInt(v, 10)
|
||||||
|
case "out":
|
||||||
|
stats.PacketsSent = p.ParseInt64(v, 10)
|
||||||
|
case "crc":
|
||||||
|
stats.NumCRCErr = p.ParseInt(v, 10)
|
||||||
|
case "overflows":
|
||||||
|
stats.NumOverflows = p.ParseInt(v, 10)
|
||||||
|
case "soft overflows":
|
||||||
|
stats.NumSoftOverflows = p.ParseInt(v, 10)
|
||||||
|
case "framing errs":
|
||||||
|
stats.NumFramingErr = p.ParseInt(v, 10)
|
||||||
|
case "buffer errs":
|
||||||
|
stats.NumBufferingErr = p.ParseInt(v, 10)
|
||||||
|
case "output errs":
|
||||||
|
stats.NumOutputErr = p.ParseInt(v, 10)
|
||||||
|
case "prom":
|
||||||
|
stats.Promiscuous = p.ParseInt(v, 10)
|
||||||
|
case "mbps":
|
||||||
|
stats.Mbps = p.ParseInt(v, 10)
|
||||||
|
case "addr":
|
||||||
|
stats.Addr = v
|
||||||
|
}
|
||||||
|
if err := p.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &stats, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type TCPStats struct {
|
||||||
|
MaxConn int
|
||||||
|
MaxSegment int
|
||||||
|
ActiveOpens int
|
||||||
|
PassiveOpens int
|
||||||
|
EstablishedResets int
|
||||||
|
CurrentEstablished int
|
||||||
|
}
|
||||||
23
vendor/github.com/power-devops/perfstat/LICENSE
generated
vendored
Normal file
23
vendor/github.com/power-devops/perfstat/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Power DevOps
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
159
vendor/github.com/power-devops/perfstat/c_helpers.c
generated
vendored
Normal file
159
vendor/github.com/power-devops/perfstat/c_helpers.c
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
#include "c_helpers.h"
|
||||||
|
|
||||||
|
GETFUNC(cpu)
|
||||||
|
GETFUNC(disk)
|
||||||
|
GETFUNC(diskadapter)
|
||||||
|
GETFUNC(diskpath)
|
||||||
|
GETFUNC(fcstat)
|
||||||
|
GETFUNC(logicalvolume)
|
||||||
|
GETFUNC(memory_page)
|
||||||
|
GETFUNC(netadapter)
|
||||||
|
GETFUNC(netbuffer)
|
||||||
|
GETFUNC(netinterface)
|
||||||
|
GETFUNC(pagingspace)
|
||||||
|
GETFUNC(process)
|
||||||
|
GETFUNC(thread)
|
||||||
|
GETFUNC(volumegroup)
|
||||||
|
|
||||||
|
double get_partition_mhz(perfstat_partition_config_t pinfo) {
|
||||||
|
return pinfo.processorMHz;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_ps_hostname(perfstat_pagingspace_t *ps) {
|
||||||
|
return ps->u.nfs_paging.hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_ps_filename(perfstat_pagingspace_t *ps) {
|
||||||
|
return ps->u.nfs_paging.filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_ps_vgname(perfstat_pagingspace_t *ps) {
|
||||||
|
return ps->u.lv_paging.vgname;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t boottime()
|
||||||
|
{
|
||||||
|
register struct utmpx *utmp;
|
||||||
|
|
||||||
|
setutxent();
|
||||||
|
while ( (utmp = getutxent()) != NULL ) {
|
||||||
|
if (utmp->ut_type == BOOT_TIME) {
|
||||||
|
return utmp->ut_tv.tv_sec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endutxent();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fsinfo *get_filesystem_stat(struct fsinfo *fs_all, int n) {
|
||||||
|
if (!fs_all) return NULL;
|
||||||
|
return &(fs_all[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_mounts(struct vmount **vmountpp) {
|
||||||
|
int size;
|
||||||
|
struct vmount *vm;
|
||||||
|
int nmounts;
|
||||||
|
|
||||||
|
size = BUFSIZ;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if ((vm = (struct vmount *)malloc((size_t)size)) == NULL) {
|
||||||
|
perror("malloc failed");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
if ((nmounts = mntctl(MCTL_QUERY, size, (caddr_t)vm)) > 0) {
|
||||||
|
*vmountpp = vm;
|
||||||
|
return nmounts;
|
||||||
|
} else if (nmounts == 0) {
|
||||||
|
size = *(int *)vm;
|
||||||
|
free((void *)vm);
|
||||||
|
} else {
|
||||||
|
free((void *)vm);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill_fsinfo(struct statfs statbuf, struct fsinfo *fs) {
|
||||||
|
fsblkcnt_t freeblks, totblks, usedblks;
|
||||||
|
fsblkcnt_t tinodes, ninodes, ifree;
|
||||||
|
uint cfactor;
|
||||||
|
|
||||||
|
if (statbuf.f_blocks == -1) {
|
||||||
|
fs->totalblks = 0;
|
||||||
|
fs->freeblks = 0;
|
||||||
|
fs->totalinodes = 0;
|
||||||
|
fs->freeinodes = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfactor = statbuf.f_bsize / 512;
|
||||||
|
fs->freeblks = statbuf.f_bavail * cfactor;
|
||||||
|
fs->totalblks = statbuf.f_blocks * cfactor;
|
||||||
|
|
||||||
|
fs->freeinodes = statbuf.f_ffree;
|
||||||
|
fs->totalinodes = statbuf.f_files;
|
||||||
|
|
||||||
|
if (fs->freeblks < 0)
|
||||||
|
fs->freeblks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getfsinfo(char *fsname, char *devname, char *host, char *options, int flags, int fstype, struct fsinfo *fs) {
|
||||||
|
struct statfs statbuf;
|
||||||
|
int devname_size = strlen(devname);
|
||||||
|
int fsname_size = strlen(fsname);
|
||||||
|
char buf[BUFSIZ];
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if (fs == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (p = strtok(options, ","); p != NULL; p = strtok(NULL, ","))
|
||||||
|
if (strcmp(p, "ignore") == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (*host != 0 && strcmp(host, "-") != 0) {
|
||||||
|
sprintf(buf, "%s:%s", host, devname);
|
||||||
|
devname = buf;
|
||||||
|
}
|
||||||
|
fs->devname = (char *)calloc(devname_size+1, 1);
|
||||||
|
fs->fsname = (char *)calloc(fsname_size+1, 1);
|
||||||
|
strncpy(fs->devname, devname, devname_size);
|
||||||
|
strncpy(fs->fsname, fsname, fsname_size);
|
||||||
|
fs->flags = flags;
|
||||||
|
fs->fstype = fstype;
|
||||||
|
|
||||||
|
if (statfs(fsname,&statbuf) < 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fill_fsinfo(statbuf, fs);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fsinfo *get_all_fs(int *rc) {
|
||||||
|
struct vmount *mnt;
|
||||||
|
struct fsinfo *fs_all;
|
||||||
|
int nmounts;
|
||||||
|
|
||||||
|
*rc = -1;
|
||||||
|
if ((nmounts = get_mounts(&mnt)) <= 0) {
|
||||||
|
perror("Can't get mount table info");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs_all = (struct fsinfo *)calloc(sizeof(struct fsinfo), nmounts);
|
||||||
|
while ((*rc)++, nmounts--) {
|
||||||
|
getfsinfo(vmt2dataptr(mnt, VMT_STUB),
|
||||||
|
vmt2dataptr(mnt, VMT_OBJECT),
|
||||||
|
vmt2dataptr(mnt, VMT_HOST),
|
||||||
|
vmt2dataptr(mnt, VMT_ARGS),
|
||||||
|
mnt->vmt_flags,
|
||||||
|
mnt->vmt_gfstype,
|
||||||
|
&fs_all[*rc]);
|
||||||
|
mnt = (struct vmount *)((char *)mnt + mnt->vmt_length);
|
||||||
|
}
|
||||||
|
return fs_all;
|
||||||
|
}
|
||||||
58
vendor/github.com/power-devops/perfstat/c_helpers.h
generated
vendored
Normal file
58
vendor/github.com/power-devops/perfstat/c_helpers.h
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#ifndef C_HELPERS_H
|
||||||
|
#define C_HELPERS_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/mntctl.h>
|
||||||
|
#include <sys/vmount.h>
|
||||||
|
#include <sys/statfs.h>
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <utmpx.h>
|
||||||
|
|
||||||
|
#define GETFUNC(TYPE) perfstat_##TYPE##_t *get_##TYPE##_stat(perfstat_##TYPE##_t *b, int n) { \
|
||||||
|
if (!b) return NULL; \
|
||||||
|
return &(b[n]); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GETFUNC_EXT(TYPE) extern perfstat_##TYPE##_t *get_##TYPE##_stat(perfstat_##TYPE##_t *, int);
|
||||||
|
|
||||||
|
GETFUNC_EXT(cpu)
|
||||||
|
GETFUNC_EXT(disk)
|
||||||
|
GETFUNC_EXT(diskadapter)
|
||||||
|
GETFUNC_EXT(diskpath)
|
||||||
|
GETFUNC_EXT(fcstat)
|
||||||
|
GETFUNC_EXT(logicalvolume)
|
||||||
|
GETFUNC_EXT(memory_page)
|
||||||
|
GETFUNC_EXT(netadapter)
|
||||||
|
GETFUNC_EXT(netbuffer)
|
||||||
|
GETFUNC_EXT(netinterface)
|
||||||
|
GETFUNC_EXT(pagingspace)
|
||||||
|
GETFUNC_EXT(process)
|
||||||
|
GETFUNC_EXT(thread)
|
||||||
|
GETFUNC_EXT(volumegroup)
|
||||||
|
|
||||||
|
struct fsinfo {
|
||||||
|
char *devname;
|
||||||
|
char *fsname;
|
||||||
|
int flags;
|
||||||
|
int fstype;
|
||||||
|
unsigned long totalblks;
|
||||||
|
unsigned long freeblks;
|
||||||
|
unsigned long totalinodes;
|
||||||
|
unsigned long freeinodes;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern double get_partition_mhz(perfstat_partition_config_t);
|
||||||
|
extern char *get_ps_hostname(perfstat_pagingspace_t *);
|
||||||
|
extern char *get_ps_filename(perfstat_pagingspace_t *);
|
||||||
|
extern char *get_ps_vgname(perfstat_pagingspace_t *);
|
||||||
|
extern time_t boottime();
|
||||||
|
struct fsinfo *get_filesystem_stat(struct fsinfo *, int);
|
||||||
|
int get_mounts(struct vmount **);
|
||||||
|
void fill_statfs(struct statfs, struct fsinfo *);
|
||||||
|
int getfsinfo(char *, char *, char *, char *, int, int, struct fsinfo *);
|
||||||
|
struct fsinfo *get_all_fs(int *);
|
||||||
|
|
||||||
|
#endif
|
||||||
19
vendor/github.com/power-devops/perfstat/config.go
generated
vendored
Normal file
19
vendor/github.com/power-devops/perfstat/config.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
func EnableLVMStat() {
|
||||||
|
C.perfstat_config(C.PERFSTAT_ENABLE|C.PERFSTAT_LV|C.PERFSTAT_VG, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DisableLVMStat() {
|
||||||
|
C.perfstat_config(C.PERFSTAT_DISABLE|C.PERFSTAT_LV|C.PERFSTAT_VG, nil)
|
||||||
|
}
|
||||||
138
vendor/github.com/power-devops/perfstat/cpustat.go
generated
vendored
Normal file
138
vendor/github.com/power-devops/perfstat/cpustat.go
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "c_helpers.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var old_cpu_total_stat *C.perfstat_cpu_total_t
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
old_cpu_total_stat = (*C.perfstat_cpu_total_t)(C.malloc(C.sizeof_perfstat_cpu_total_t))
|
||||||
|
C.perfstat_cpu_total(nil, old_cpu_total_stat, C.sizeof_perfstat_cpu_total_t, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CpuStat() ([]CPU, error) {
|
||||||
|
var cpustat *C.perfstat_cpu_t
|
||||||
|
var cpu C.perfstat_id_t
|
||||||
|
|
||||||
|
ncpu := runtime.NumCPU()
|
||||||
|
|
||||||
|
cpustat_len := C.sizeof_perfstat_cpu_t * C.ulong(ncpu)
|
||||||
|
cpustat = (*C.perfstat_cpu_t)(C.malloc(cpustat_len))
|
||||||
|
defer C.free(unsafe.Pointer(cpustat))
|
||||||
|
C.strcpy(&cpu.name[0], C.CString(C.FIRST_CPU))
|
||||||
|
r := C.perfstat_cpu(&cpu, cpustat, C.sizeof_perfstat_cpu_t, C.int(ncpu))
|
||||||
|
if r <= 0 {
|
||||||
|
return nil, fmt.Errorf("error perfstat_cpu()")
|
||||||
|
}
|
||||||
|
c := make([]CPU, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
n := C.get_cpu_stat(cpustat, C.int(i))
|
||||||
|
if n != nil {
|
||||||
|
c[i] = perfstatcpu2cpu(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CpuTotalStat() (*CPUTotal, error) {
|
||||||
|
var cpustat *C.perfstat_cpu_total_t
|
||||||
|
|
||||||
|
cpustat = (*C.perfstat_cpu_total_t)(C.malloc(C.sizeof_perfstat_cpu_total_t))
|
||||||
|
defer C.free(unsafe.Pointer(cpustat))
|
||||||
|
r := C.perfstat_cpu_total(nil, cpustat, C.sizeof_perfstat_cpu_total_t, 1)
|
||||||
|
if r <= 0 {
|
||||||
|
return nil, fmt.Errorf("error perfstat_cpu_total()")
|
||||||
|
}
|
||||||
|
c := perfstatcputotal2cputotal(cpustat)
|
||||||
|
return &c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CpuUtilStat(intvl time.Duration) (*CPUUtil, error) {
|
||||||
|
var cpuutil *C.perfstat_cpu_util_t
|
||||||
|
var newt *C.perfstat_cpu_total_t
|
||||||
|
var oldt *C.perfstat_cpu_total_t
|
||||||
|
var data C.perfstat_rawdata_t
|
||||||
|
|
||||||
|
oldt = (*C.perfstat_cpu_total_t)(C.malloc(C.sizeof_perfstat_cpu_total_t))
|
||||||
|
newt = (*C.perfstat_cpu_total_t)(C.malloc(C.sizeof_perfstat_cpu_total_t))
|
||||||
|
cpuutil = (*C.perfstat_cpu_util_t)(C.malloc(C.sizeof_perfstat_cpu_util_t))
|
||||||
|
defer C.free(unsafe.Pointer(oldt))
|
||||||
|
defer C.free(unsafe.Pointer(newt))
|
||||||
|
defer C.free(unsafe.Pointer(cpuutil))
|
||||||
|
|
||||||
|
r := C.perfstat_cpu_total(nil, oldt, C.sizeof_perfstat_cpu_total_t, 1)
|
||||||
|
if r <= 0 {
|
||||||
|
return nil, fmt.Errorf("error perfstat_cpu_total()")
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(intvl)
|
||||||
|
|
||||||
|
r = C.perfstat_cpu_total(nil, newt, C.sizeof_perfstat_cpu_total_t, 1)
|
||||||
|
if r <= 0 {
|
||||||
|
return nil, fmt.Errorf("error perfstat_cpu_total()")
|
||||||
|
}
|
||||||
|
|
||||||
|
data._type = C.UTIL_CPU_TOTAL
|
||||||
|
data.curstat = unsafe.Pointer(newt)
|
||||||
|
data.prevstat = unsafe.Pointer(oldt)
|
||||||
|
data.sizeof_data = C.sizeof_perfstat_cpu_total_t
|
||||||
|
data.cur_elems = 1
|
||||||
|
data.prev_elems = 1
|
||||||
|
|
||||||
|
r = C.perfstat_cpu_util(&data, cpuutil, C.sizeof_perfstat_cpu_util_t, 1)
|
||||||
|
if r <= 0 {
|
||||||
|
return nil, fmt.Errorf("error perfstat_cpu_util()")
|
||||||
|
}
|
||||||
|
u := perfstatcpuutil2cpuutil(cpuutil)
|
||||||
|
return &u, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CpuUtilTotalStat() (*CPUUtil, error) {
|
||||||
|
var cpuutil *C.perfstat_cpu_util_t
|
||||||
|
var new_cpu_total_stat *C.perfstat_cpu_total_t
|
||||||
|
var data C.perfstat_rawdata_t
|
||||||
|
|
||||||
|
new_cpu_total_stat = (*C.perfstat_cpu_total_t)(C.malloc(C.sizeof_perfstat_cpu_total_t))
|
||||||
|
cpuutil = (*C.perfstat_cpu_util_t)(C.malloc(C.sizeof_perfstat_cpu_util_t))
|
||||||
|
defer C.free(unsafe.Pointer(cpuutil))
|
||||||
|
|
||||||
|
r := C.perfstat_cpu_total(nil, new_cpu_total_stat, C.sizeof_perfstat_cpu_total_t, 1)
|
||||||
|
if r <= 0 {
|
||||||
|
C.free(unsafe.Pointer(new_cpu_total_stat))
|
||||||
|
return nil, fmt.Errorf("error perfstat_cpu_total()")
|
||||||
|
}
|
||||||
|
|
||||||
|
data._type = C.UTIL_CPU_TOTAL
|
||||||
|
data.curstat = unsafe.Pointer(new_cpu_total_stat)
|
||||||
|
data.prevstat = unsafe.Pointer(old_cpu_total_stat)
|
||||||
|
data.sizeof_data = C.sizeof_perfstat_cpu_total_t
|
||||||
|
data.cur_elems = 1
|
||||||
|
data.prev_elems = 1
|
||||||
|
|
||||||
|
r = C.perfstat_cpu_util(&data, cpuutil, C.sizeof_perfstat_cpu_util_t, 1)
|
||||||
|
C.free(unsafe.Pointer(old_cpu_total_stat))
|
||||||
|
old_cpu_total_stat = new_cpu_total_stat
|
||||||
|
if r <= 0 {
|
||||||
|
return nil, fmt.Errorf("error perfstat_cpu_util()")
|
||||||
|
}
|
||||||
|
u := perfstatcpuutil2cpuutil(cpuutil)
|
||||||
|
return &u, nil
|
||||||
|
}
|
||||||
138
vendor/github.com/power-devops/perfstat/diskstat.go
generated
vendored
Normal file
138
vendor/github.com/power-devops/perfstat/diskstat.go
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "c_helpers.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DiskTotalStat() (*DiskTotal, error) {
|
||||||
|
var disk C.perfstat_disk_total_t
|
||||||
|
|
||||||
|
rc := C.perfstat_disk_total(nil, &disk, C.sizeof_perfstat_disk_total_t, 1)
|
||||||
|
if rc != 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_disk_total() error")
|
||||||
|
}
|
||||||
|
d := perfstatdisktotal2disktotal(disk)
|
||||||
|
return &d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiskAdapterStat() ([]DiskAdapter, error) {
|
||||||
|
var adapter *C.perfstat_diskadapter_t
|
||||||
|
var adptname C.perfstat_id_t
|
||||||
|
|
||||||
|
numadpt := C.perfstat_diskadapter(nil, nil, C.sizeof_perfstat_diskadapter_t, 0)
|
||||||
|
if numadpt <= 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_diskadapter() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
adapter_len := C.sizeof_perfstat_diskadapter_t * C.ulong(numadpt)
|
||||||
|
adapter = (*C.perfstat_diskadapter_t)(C.malloc(adapter_len))
|
||||||
|
defer C.free(unsafe.Pointer(adapter))
|
||||||
|
C.strcpy(&adptname.name[0], C.CString(C.FIRST_DISKADAPTER))
|
||||||
|
r := C.perfstat_diskadapter(&adptname, adapter, C.sizeof_perfstat_diskadapter_t, numadpt)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_diskadapter() error")
|
||||||
|
}
|
||||||
|
da := make([]DiskAdapter, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
d := C.get_diskadapter_stat(adapter, C.int(i))
|
||||||
|
if d != nil {
|
||||||
|
da[i] = perfstatdiskadapter2diskadapter(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return da, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiskStat() ([]Disk, error) {
|
||||||
|
var disk *C.perfstat_disk_t
|
||||||
|
var diskname C.perfstat_id_t
|
||||||
|
|
||||||
|
numdisk := C.perfstat_disk(nil, nil, C.sizeof_perfstat_disk_t, 0)
|
||||||
|
if numdisk <= 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_disk() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
disk_len := C.sizeof_perfstat_disk_t * C.ulong(numdisk)
|
||||||
|
disk = (*C.perfstat_disk_t)(C.malloc(disk_len))
|
||||||
|
defer C.free(unsafe.Pointer(disk))
|
||||||
|
C.strcpy(&diskname.name[0], C.CString(C.FIRST_DISK))
|
||||||
|
r := C.perfstat_disk(&diskname, disk, C.sizeof_perfstat_disk_t, numdisk)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_disk() error")
|
||||||
|
}
|
||||||
|
d := make([]Disk, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
ds := C.get_disk_stat(disk, C.int(i))
|
||||||
|
if ds != nil {
|
||||||
|
d[i] = perfstatdisk2disk(ds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiskPathStat() ([]DiskPath, error) {
|
||||||
|
var diskpath *C.perfstat_diskpath_t
|
||||||
|
var pathname C.perfstat_id_t
|
||||||
|
|
||||||
|
numpaths := C.perfstat_diskpath(nil, nil, C.sizeof_perfstat_diskpath_t, 0)
|
||||||
|
if numpaths <= 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_diskpath() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
path_len := C.sizeof_perfstat_diskpath_t * C.ulong(numpaths)
|
||||||
|
diskpath = (*C.perfstat_diskpath_t)(C.malloc(path_len))
|
||||||
|
defer C.free(unsafe.Pointer(diskpath))
|
||||||
|
C.strcpy(&pathname.name[0], C.CString(C.FIRST_DISKPATH))
|
||||||
|
r := C.perfstat_diskpath(&pathname, diskpath, C.sizeof_perfstat_diskpath_t, numpaths)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_diskpath() error")
|
||||||
|
}
|
||||||
|
d := make([]DiskPath, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
p := C.get_diskpath_stat(diskpath, C.int(i))
|
||||||
|
if p != nil {
|
||||||
|
d[i] = perfstatdiskpath2diskpath(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func FCAdapterStat() ([]FCAdapter, error) {
|
||||||
|
var fcstat *C.perfstat_fcstat_t
|
||||||
|
var fcname C.perfstat_id_t
|
||||||
|
|
||||||
|
numadpt := C.perfstat_fcstat(nil, nil, C.sizeof_perfstat_fcstat_t, 0)
|
||||||
|
if numadpt <= 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_fcstat() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
fcstat_len := C.sizeof_perfstat_fcstat_t * C.ulong(numadpt)
|
||||||
|
fcstat = (*C.perfstat_fcstat_t)(C.malloc(fcstat_len))
|
||||||
|
defer C.free(unsafe.Pointer(fcstat))
|
||||||
|
C.strcpy(&fcname.name[0], C.CString(C.FIRST_NETINTERFACE))
|
||||||
|
r := C.perfstat_fcstat(&fcname, fcstat, C.sizeof_perfstat_fcstat_t, numadpt)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_fcstat() error")
|
||||||
|
}
|
||||||
|
fca := make([]FCAdapter, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
f := C.get_fcstat_stat(fcstat, C.int(i))
|
||||||
|
if f != nil {
|
||||||
|
fca[i] = perfstatfcstat2fcadapter(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fca, nil
|
||||||
|
}
|
||||||
316
vendor/github.com/power-devops/perfstat/doc.go
generated
vendored
Normal file
316
vendor/github.com/power-devops/perfstat/doc.go
generated
vendored
Normal file
@@ -0,0 +1,316 @@
|
|||||||
|
//go:build !aix
|
||||||
|
// +build !aix
|
||||||
|
|
||||||
|
// Copyright 2020 Power-Devops.com. All rights reserved.
|
||||||
|
// Use of this source code is governed by the license
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
/*
|
||||||
|
Package perfstat is Go interface to IBM AIX libperfstat.
|
||||||
|
To use it you need AIX with installed bos.perf.libperfstat. You can check, if is installed using the following command:
|
||||||
|
|
||||||
|
$ lslpp -L bos.perf.perfstat
|
||||||
|
|
||||||
|
The package is written using Go 1.14.7 and AIX 7.2 TL5. It should work with earlier TLs of AIX 7.2, but I
|
||||||
|
can't guarantee that perfstat structures in the TLs have all the same fields as the structures in AIX 7.2 TL5.
|
||||||
|
|
||||||
|
For documentation of perfstat on AIX and using it in programs refer to the official IBM documentation:
|
||||||
|
https://www.ibm.com/support/knowledgecenter/ssw_aix_72/performancetools/idprftools_perfstat.html
|
||||||
|
*/
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EnableLVMStat() switches on LVM (logical volumes and volume groups) performance statistics.
|
||||||
|
// With this enabled you can use fields KBReads, KBWrites, and IOCnt
|
||||||
|
// in LogicalVolume and VolumeGroup data types.
|
||||||
|
func EnableLVMStat() {}
|
||||||
|
|
||||||
|
// DisableLVMStat() switchess of LVM (logical volumes and volume groups) performance statistics.
|
||||||
|
// This is the default state. In this case LogicalVolume and VolumeGroup data types are
|
||||||
|
// populated with informations about LVM structures, but performance statistics fields
|
||||||
|
// (KBReads, KBWrites, IOCnt) are empty.
|
||||||
|
func DisableLVMStat() {}
|
||||||
|
|
||||||
|
// CpuStat() returns array of CPU structures with information about
|
||||||
|
// logical CPUs on the system.
|
||||||
|
// IBM documentation:
|
||||||
|
// - https://www.ibm.com/support/knowledgecenter/ssw_aix_72/performancetools/idprftools_perfstat_int_cpu.html
|
||||||
|
// - https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/p_bostechref/perfstat_cpu.html
|
||||||
|
func CpuStat() ([]CPU, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpuTotalStat() returns general information about CPUs on the system.
|
||||||
|
// IBM documentation:
|
||||||
|
// - https://www.ibm.com/support/knowledgecenter/ssw_aix_72/performancetools/idprftools_perfstat_glob_cpu.html
|
||||||
|
// - https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/p_bostechref/perfstat_cputot.html
|
||||||
|
func CpuTotalStat() (*CPUTotal, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpuUtilStat() calculates CPU utilization.
|
||||||
|
// IBM documentation:
|
||||||
|
// - https://www.ibm.com/support/knowledgecenter/ssw_aix_72/performancetools/idprftools_perfstat_cpu_util.html
|
||||||
|
// - https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/p_bostechref/perfstat_cpu_util.html
|
||||||
|
func CpuUtilStat(intvl time.Duration) (*CPUUtil, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiskTotalStat() (*DiskTotal, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiskAdapterStat() ([]DiskAdapter, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiskStat() ([]Disk, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiskPathStat() ([]DiskPath, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func FCAdapterStat() ([]FCAdapter, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func PartitionStat() (*PartitionConfig, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func LogicalVolumeStat() ([]LogicalVolume, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func VolumeGroupStat() ([]VolumeGroup, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func MemoryTotalStat() (*MemoryTotal, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func MemoryPageStat() ([]MemoryPage, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func PagingSpaceStat() ([]PagingSpace, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NetIfaceTotalStat() (*NetIfaceTotal, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NetBufferStat() ([]NetBuffer, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NetIfaceStat() ([]NetIface, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NetAdapterStat() ([]NetAdapter, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProcessStat() ([]Process, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ThreadStat() ([]Thread, error) {
|
||||||
|
return nil, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Sysconf(name int32) (int64, error) {
|
||||||
|
return 0, fmt.Errorf("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCPUImplementation() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func POWER9OrNewer() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func POWER9() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func POWER8OrNewer() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func POWER8() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func POWER7OrNewer() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func POWER7() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func HasTransactionalMemory() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func Is64Bit() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsSMP() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func HasVMX() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func HasVSX() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func HasDFP() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func HasNxGzip() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func PksCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func PksEnabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func CPUMode() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func KernelBits() int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsLPAR() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func CpuAddCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func CpuRemoveCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func MemoryAddCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func MemoryRemoveCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func DLparCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsNUMA() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func KernelKeys() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func RecoveryMode() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnhancedAffinity() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func VTpmEnabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsVIOS() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func MLSEnabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func SPLparCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func SPLparEnabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func DedicatedLpar() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func SPLparCapped() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func SPLparDonating() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func SmtCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func SmtEnabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func VrmCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func VrmEnabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func AmeEnabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func EcoCapable() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func EcoEnabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func BootTime() (uint64, error) {
|
||||||
|
return 0, fmt.Errorf("Not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func UptimeSeconds() (uint64, error) {
|
||||||
|
return 0, fmt.Errorf("Not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func FileSystemStat() ([]FileSystem, error) {
|
||||||
|
return nil, fmt.Errorf("Not implemented")
|
||||||
|
}
|
||||||
32
vendor/github.com/power-devops/perfstat/fsstat.go
generated
vendored
Normal file
32
vendor/github.com/power-devops/perfstat/fsstat.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include "c_helpers.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FileSystemStat() ([]FileSystem, error) {
|
||||||
|
var fsinfo *C.struct_fsinfo
|
||||||
|
var nmounts C.int
|
||||||
|
|
||||||
|
fsinfo = C.get_all_fs(&nmounts)
|
||||||
|
if nmounts <= 0 {
|
||||||
|
return nil, fmt.Errorf("No mounts found")
|
||||||
|
}
|
||||||
|
|
||||||
|
fs := make([]FileSystem, nmounts)
|
||||||
|
for i := 0; i < int(nmounts); i++ {
|
||||||
|
f := C.get_filesystem_stat(fsinfo, C.int(i))
|
||||||
|
if f != nil {
|
||||||
|
fs[i] = fsinfo2filesystem(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fs, nil
|
||||||
|
}
|
||||||
819
vendor/github.com/power-devops/perfstat/helpers.go
generated
vendored
Normal file
819
vendor/github.com/power-devops/perfstat/helpers.go
generated
vendored
Normal file
@@ -0,0 +1,819 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <sys/proc.h>
|
||||||
|
#include <sys/dr.h>
|
||||||
|
|
||||||
|
#include "c_helpers.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
func perfstatcpu2cpu(n *C.perfstat_cpu_t) CPU {
|
||||||
|
var c CPU
|
||||||
|
c.Name = C.GoString(&n.name[0])
|
||||||
|
c.User = int64(n.user)
|
||||||
|
c.Sys = int64(n.sys)
|
||||||
|
c.Idle = int64(n.idle)
|
||||||
|
c.Wait = int64(n.wait)
|
||||||
|
c.PSwitch = int64(n.pswitch)
|
||||||
|
c.Syscall = int64(n.syscall)
|
||||||
|
c.Sysread = int64(n.sysread)
|
||||||
|
c.Syswrite = int64(n.syswrite)
|
||||||
|
c.Sysfork = int64(n.sysfork)
|
||||||
|
c.Sysexec = int64(n.sysexec)
|
||||||
|
c.Readch = int64(n.readch)
|
||||||
|
c.Writech = int64(n.writech)
|
||||||
|
c.Bread = int64(n.bread)
|
||||||
|
c.Bwrite = int64(n.bwrite)
|
||||||
|
c.Lread = int64(n.lread)
|
||||||
|
c.Lwrite = int64(n.lwrite)
|
||||||
|
c.Phread = int64(n.phread)
|
||||||
|
c.Phwrite = int64(n.phwrite)
|
||||||
|
c.Iget = int64(n.iget)
|
||||||
|
c.Namei = int64(n.namei)
|
||||||
|
c.Dirblk = int64(n.dirblk)
|
||||||
|
c.Msg = int64(n.msg)
|
||||||
|
c.Sema = int64(n.sema)
|
||||||
|
c.MinFaults = int64(n.minfaults)
|
||||||
|
c.MajFaults = int64(n.majfaults)
|
||||||
|
c.PUser = int64(n.puser)
|
||||||
|
c.PSys = int64(n.psys)
|
||||||
|
c.PIdle = int64(n.pidle)
|
||||||
|
c.PWait = int64(n.pwait)
|
||||||
|
c.RedispSD0 = int64(n.redisp_sd0)
|
||||||
|
c.RedispSD1 = int64(n.redisp_sd1)
|
||||||
|
c.RedispSD2 = int64(n.redisp_sd2)
|
||||||
|
c.RedispSD3 = int64(n.redisp_sd3)
|
||||||
|
c.RedispSD4 = int64(n.redisp_sd4)
|
||||||
|
c.RedispSD5 = int64(n.redisp_sd5)
|
||||||
|
c.MigrationPush = int64(n.migration_push)
|
||||||
|
c.MigrationS3grq = int64(n.migration_S3grq)
|
||||||
|
c.MigrationS3pul = int64(n.migration_S3pul)
|
||||||
|
c.InvolCSwitch = int64(n.invol_cswitch)
|
||||||
|
c.VolCSwitch = int64(n.vol_cswitch)
|
||||||
|
c.RunQueue = int64(n.runque)
|
||||||
|
c.Bound = int64(n.bound)
|
||||||
|
c.DecrIntrs = int64(n.decrintrs)
|
||||||
|
c.MpcRIntrs = int64(n.mpcrintrs)
|
||||||
|
c.MpcSIntrs = int64(n.mpcsintrs)
|
||||||
|
c.SoftIntrs = int64(n.softintrs)
|
||||||
|
c.DevIntrs = int64(n.devintrs)
|
||||||
|
c.PhantIntrs = int64(n.phantintrs)
|
||||||
|
c.IdleDonatedPurr = int64(n.idle_donated_purr)
|
||||||
|
c.IdleDonatedSpurr = int64(n.idle_donated_spurr)
|
||||||
|
c.BusyDonatedPurr = int64(n.busy_donated_purr)
|
||||||
|
c.BusyDonatedSpurr = int64(n.busy_donated_spurr)
|
||||||
|
c.IdleStolenPurr = int64(n.idle_stolen_purr)
|
||||||
|
c.IdleStolenSpurr = int64(n.idle_stolen_spurr)
|
||||||
|
c.BusyStolenPurr = int64(n.busy_stolen_purr)
|
||||||
|
c.BusyStolenSpurr = int64(n.busy_stolen_spurr)
|
||||||
|
c.Hpi = int64(n.hpi)
|
||||||
|
c.Hpit = int64(n.hpit)
|
||||||
|
c.PUserSpurr = int64(n.puser_spurr)
|
||||||
|
c.PSysSpurr = int64(n.psys_spurr)
|
||||||
|
c.PIdleSpurr = int64(n.pidle_spurr)
|
||||||
|
c.PWaitSpurr = int64(n.pwait_spurr)
|
||||||
|
c.SpurrFlag = int32(n.spurrflag)
|
||||||
|
c.LocalDispatch = int64(n.localdispatch)
|
||||||
|
c.NearDispatch = int64(n.neardispatch)
|
||||||
|
c.FarDispatch = int64(n.fardispatch)
|
||||||
|
c.CSwitches = int64(n.cswitches)
|
||||||
|
c.Version = int64(n.version)
|
||||||
|
c.TbLast = int64(n.tb_last)
|
||||||
|
c.State = int(n.state)
|
||||||
|
c.VtbLast = int64(n.vtb_last)
|
||||||
|
c.ICountLast = int64(n.icount_last)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatcputotal2cputotal(n *C.perfstat_cpu_total_t) CPUTotal {
|
||||||
|
var c CPUTotal
|
||||||
|
c.NCpus = int(n.ncpus)
|
||||||
|
c.NCpusCfg = int(n.ncpus_cfg)
|
||||||
|
c.Description = C.GoString(&n.description[0])
|
||||||
|
c.ProcessorHz = int64(n.processorHZ)
|
||||||
|
c.User = int64(n.user)
|
||||||
|
c.Sys = int64(n.sys)
|
||||||
|
c.Idle = int64(n.idle)
|
||||||
|
c.Wait = int64(n.wait)
|
||||||
|
c.PSwitch = int64(n.pswitch)
|
||||||
|
c.Syscall = int64(n.syscall)
|
||||||
|
c.Sysread = int64(n.sysread)
|
||||||
|
c.Syswrite = int64(n.syswrite)
|
||||||
|
c.Sysfork = int64(n.sysfork)
|
||||||
|
c.Sysexec = int64(n.sysexec)
|
||||||
|
c.Readch = int64(n.readch)
|
||||||
|
c.Writech = int64(n.writech)
|
||||||
|
c.DevIntrs = int64(n.devintrs)
|
||||||
|
c.SoftIntrs = int64(n.softintrs)
|
||||||
|
c.Lbolt = int64(n.lbolt)
|
||||||
|
c.LoadAvg1 = (float32(n.loadavg[0]) / (1 << C.SBITS))
|
||||||
|
c.LoadAvg5 = (float32(n.loadavg[1]) / (1 << C.SBITS))
|
||||||
|
c.LoadAvg15 = (float32(n.loadavg[2]) / (1 << C.SBITS))
|
||||||
|
c.RunQueue = int64(n.runque)
|
||||||
|
c.SwpQueue = int64(n.swpque)
|
||||||
|
c.Bread = int64(n.bread)
|
||||||
|
c.Bwrite = int64(n.bwrite)
|
||||||
|
c.Lread = int64(n.lread)
|
||||||
|
c.Lwrite = int64(n.lwrite)
|
||||||
|
c.Phread = int64(n.phread)
|
||||||
|
c.Phwrite = int64(n.phwrite)
|
||||||
|
c.RunOcc = int64(n.runocc)
|
||||||
|
c.SwpOcc = int64(n.swpocc)
|
||||||
|
c.Iget = int64(n.iget)
|
||||||
|
c.Namei = int64(n.namei)
|
||||||
|
c.Dirblk = int64(n.dirblk)
|
||||||
|
c.Msg = int64(n.msg)
|
||||||
|
c.Sema = int64(n.sema)
|
||||||
|
c.RcvInt = int64(n.rcvint)
|
||||||
|
c.XmtInt = int64(n.xmtint)
|
||||||
|
c.MdmInt = int64(n.mdmint)
|
||||||
|
c.TtyRawInch = int64(n.tty_rawinch)
|
||||||
|
c.TtyCanInch = int64(n.tty_caninch)
|
||||||
|
c.TtyRawOutch = int64(n.tty_rawoutch)
|
||||||
|
c.Ksched = int64(n.ksched)
|
||||||
|
c.Koverf = int64(n.koverf)
|
||||||
|
c.Kexit = int64(n.kexit)
|
||||||
|
c.Rbread = int64(n.rbread)
|
||||||
|
c.Rcread = int64(n.rcread)
|
||||||
|
c.Rbwrt = int64(n.rbwrt)
|
||||||
|
c.Rcwrt = int64(n.rcwrt)
|
||||||
|
c.Traps = int64(n.traps)
|
||||||
|
c.NCpusHigh = int64(n.ncpus_high)
|
||||||
|
c.PUser = int64(n.puser)
|
||||||
|
c.PSys = int64(n.psys)
|
||||||
|
c.PIdle = int64(n.pidle)
|
||||||
|
c.PWait = int64(n.pwait)
|
||||||
|
c.DecrIntrs = int64(n.decrintrs)
|
||||||
|
c.MpcRIntrs = int64(n.mpcrintrs)
|
||||||
|
c.MpcSIntrs = int64(n.mpcsintrs)
|
||||||
|
c.PhantIntrs = int64(n.phantintrs)
|
||||||
|
c.IdleDonatedPurr = int64(n.idle_donated_purr)
|
||||||
|
c.IdleDonatedSpurr = int64(n.idle_donated_spurr)
|
||||||
|
c.BusyDonatedPurr = int64(n.busy_donated_purr)
|
||||||
|
c.BusyDonatedSpurr = int64(n.busy_donated_spurr)
|
||||||
|
c.IdleStolenPurr = int64(n.idle_stolen_purr)
|
||||||
|
c.IdleStolenSpurr = int64(n.idle_stolen_spurr)
|
||||||
|
c.BusyStolenPurr = int64(n.busy_stolen_purr)
|
||||||
|
c.BusyStolenSpurr = int64(n.busy_stolen_spurr)
|
||||||
|
c.IOWait = int32(n.iowait)
|
||||||
|
c.PhysIO = int32(n.physio)
|
||||||
|
c.TWait = int64(n.twait)
|
||||||
|
c.Hpi = int64(n.hpi)
|
||||||
|
c.Hpit = int64(n.hpit)
|
||||||
|
c.PUserSpurr = int64(n.puser_spurr)
|
||||||
|
c.PSysSpurr = int64(n.psys_spurr)
|
||||||
|
c.PIdleSpurr = int64(n.pidle_spurr)
|
||||||
|
c.PWaitSpurr = int64(n.pwait_spurr)
|
||||||
|
c.SpurrFlag = int(n.spurrflag)
|
||||||
|
c.Version = int64(n.version)
|
||||||
|
c.TbLast = int64(n.tb_last)
|
||||||
|
c.PurrCoalescing = int64(n.purr_coalescing)
|
||||||
|
c.SpurrCoalescing = int64(n.spurr_coalescing)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatcpuutil2cpuutil(n *C.perfstat_cpu_util_t) CPUUtil {
|
||||||
|
var c CPUUtil
|
||||||
|
|
||||||
|
c.Version = int64(n.version)
|
||||||
|
c.CpuID = C.GoString(&n.cpu_id[0])
|
||||||
|
c.Entitlement = float32(n.entitlement)
|
||||||
|
c.UserPct = float32(n.user_pct)
|
||||||
|
c.KernPct = float32(n.kern_pct)
|
||||||
|
c.IdlePct = float32(n.idle_pct)
|
||||||
|
c.WaitPct = float32(n.wait_pct)
|
||||||
|
c.PhysicalBusy = float32(n.physical_busy)
|
||||||
|
c.PhysicalConsumed = float32(n.physical_consumed)
|
||||||
|
c.FreqPct = float32(n.freq_pct)
|
||||||
|
c.EntitlementPct = float32(n.entitlement_pct)
|
||||||
|
c.BusyPct = float32(n.busy_pct)
|
||||||
|
c.IdleDonatedPct = float32(n.idle_donated_pct)
|
||||||
|
c.BusyDonatedPct = float32(n.busy_donated_pct)
|
||||||
|
c.IdleStolenPct = float32(n.idle_stolen_pct)
|
||||||
|
c.BusyStolenPct = float32(n.busy_stolen_pct)
|
||||||
|
c.LUserPct = float32(n.l_user_pct)
|
||||||
|
c.LKernPct = float32(n.l_kern_pct)
|
||||||
|
c.LIdlePct = float32(n.l_idle_pct)
|
||||||
|
c.LWaitPct = float32(n.l_wait_pct)
|
||||||
|
c.DeltaTime = int64(n.delta_time)
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatdisktotal2disktotal(n C.perfstat_disk_total_t) DiskTotal {
|
||||||
|
var d DiskTotal
|
||||||
|
|
||||||
|
d.Number = int32(n.number)
|
||||||
|
d.Size = int64(n.size)
|
||||||
|
d.Free = int64(n.free)
|
||||||
|
d.XRate = int64(n.xrate)
|
||||||
|
d.Xfers = int64(n.xfers)
|
||||||
|
d.Wblks = int64(n.wblks)
|
||||||
|
d.Rblks = int64(n.rblks)
|
||||||
|
d.Time = int64(n.time)
|
||||||
|
d.Version = int64(n.version)
|
||||||
|
d.Rserv = int64(n.rserv)
|
||||||
|
d.MinRserv = int64(n.min_rserv)
|
||||||
|
d.MaxRserv = int64(n.max_rserv)
|
||||||
|
d.RTimeOut = int64(n.rtimeout)
|
||||||
|
d.RFailed = int64(n.rfailed)
|
||||||
|
d.Wserv = int64(n.wserv)
|
||||||
|
d.MinWserv = int64(n.min_wserv)
|
||||||
|
d.MaxWserv = int64(n.max_wserv)
|
||||||
|
d.WTimeOut = int64(n.wtimeout)
|
||||||
|
d.WFailed = int64(n.wfailed)
|
||||||
|
d.WqDepth = int64(n.wq_depth)
|
||||||
|
d.WqTime = int64(n.wq_time)
|
||||||
|
d.WqMinTime = int64(n.wq_min_time)
|
||||||
|
d.WqMaxTime = int64(n.wq_max_time)
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatdiskadapter2diskadapter(n *C.perfstat_diskadapter_t) DiskAdapter {
|
||||||
|
var d DiskAdapter
|
||||||
|
|
||||||
|
d.Name = C.GoString(&n.name[0])
|
||||||
|
d.Description = C.GoString(&n.description[0])
|
||||||
|
d.Number = int32(n.number)
|
||||||
|
d.Size = int64(n.size)
|
||||||
|
d.Free = int64(n.free)
|
||||||
|
d.XRate = int64(n.xrate)
|
||||||
|
d.Xfers = int64(n.xfers)
|
||||||
|
d.Rblks = int64(n.rblks)
|
||||||
|
d.Wblks = int64(n.wblks)
|
||||||
|
d.Time = int64(n.time)
|
||||||
|
d.Version = int64(n.version)
|
||||||
|
d.AdapterType = int64(n.adapter_type)
|
||||||
|
d.DkBSize = int64(n.dk_bsize)
|
||||||
|
d.DkRserv = int64(n.dk_rserv)
|
||||||
|
d.DkWserv = int64(n.dk_wserv)
|
||||||
|
d.MinRserv = int64(n.min_rserv)
|
||||||
|
d.MaxRserv = int64(n.max_rserv)
|
||||||
|
d.MinWserv = int64(n.min_wserv)
|
||||||
|
d.MaxWserv = int64(n.max_wserv)
|
||||||
|
d.WqDepth = int64(n.wq_depth)
|
||||||
|
d.WqSampled = int64(n.wq_sampled)
|
||||||
|
d.WqTime = int64(n.wq_time)
|
||||||
|
d.WqMinTime = int64(n.wq_min_time)
|
||||||
|
d.WqMaxTime = int64(n.wq_max_time)
|
||||||
|
d.QFull = int64(n.q_full)
|
||||||
|
d.QSampled = int64(n.q_sampled)
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatpartitionconfig2partitionconfig(n C.perfstat_partition_config_t) PartitionConfig {
|
||||||
|
var p PartitionConfig
|
||||||
|
p.Version = int64(n.version)
|
||||||
|
p.Name = C.GoString(&n.partitionname[0])
|
||||||
|
p.Node = C.GoString(&n.nodename[0])
|
||||||
|
p.Conf.SmtCapable = (n.conf[0] & (1 << 7)) > 0
|
||||||
|
p.Conf.SmtEnabled = (n.conf[0] & (1 << 6)) > 0
|
||||||
|
p.Conf.LparCapable = (n.conf[0] & (1 << 5)) > 0
|
||||||
|
p.Conf.LparEnabled = (n.conf[0] & (1 << 4)) > 0
|
||||||
|
p.Conf.SharedCapable = (n.conf[0] & (1 << 3)) > 0
|
||||||
|
p.Conf.SharedEnabled = (n.conf[0] & (1 << 2)) > 0
|
||||||
|
p.Conf.DLparCapable = (n.conf[0] & (1 << 1)) > 0
|
||||||
|
p.Conf.Capped = (n.conf[0] & (1 << 0)) > 0
|
||||||
|
p.Conf.Kernel64bit = (n.conf[1] & (1 << 7)) > 0
|
||||||
|
p.Conf.PoolUtilAuthority = (n.conf[1] & (1 << 6)) > 0
|
||||||
|
p.Conf.DonateCapable = (n.conf[1] & (1 << 5)) > 0
|
||||||
|
p.Conf.DonateEnabled = (n.conf[1] & (1 << 4)) > 0
|
||||||
|
p.Conf.AmsCapable = (n.conf[1] & (1 << 3)) > 0
|
||||||
|
p.Conf.AmsEnabled = (n.conf[1] & (1 << 2)) > 0
|
||||||
|
p.Conf.PowerSave = (n.conf[1] & (1 << 1)) > 0
|
||||||
|
p.Conf.AmeEnabled = (n.conf[1] & (1 << 0)) > 0
|
||||||
|
p.Conf.SharedExtended = (n.conf[2] & (1 << 7)) > 0
|
||||||
|
p.Number = int32(n.partitionnum)
|
||||||
|
p.GroupID = int32(n.groupid)
|
||||||
|
p.ProcessorFamily = C.GoString(&n.processorFamily[0])
|
||||||
|
p.ProcessorModel = C.GoString(&n.processorModel[0])
|
||||||
|
p.MachineID = C.GoString(&n.machineID[0])
|
||||||
|
p.ProcessorMhz = float64(C.get_partition_mhz(n))
|
||||||
|
p.NumProcessors.Online = int64(n.numProcessors.online)
|
||||||
|
p.NumProcessors.Max = int64(n.numProcessors.max)
|
||||||
|
p.NumProcessors.Min = int64(n.numProcessors.min)
|
||||||
|
p.NumProcessors.Desired = int64(n.numProcessors.desired)
|
||||||
|
p.OSName = C.GoString(&n.OSName[0])
|
||||||
|
p.OSVersion = C.GoString(&n.OSVersion[0])
|
||||||
|
p.OSBuild = C.GoString(&n.OSBuild[0])
|
||||||
|
p.LCpus = int32(n.lcpus)
|
||||||
|
p.SmtThreads = int32(n.smtthreads)
|
||||||
|
p.Drives = int32(n.drives)
|
||||||
|
p.NetworkAdapters = int32(n.nw_adapters)
|
||||||
|
p.CpuCap.Online = int64(n.cpucap.online)
|
||||||
|
p.CpuCap.Max = int64(n.cpucap.max)
|
||||||
|
p.CpuCap.Min = int64(n.cpucap.min)
|
||||||
|
p.CpuCap.Desired = int64(n.cpucap.desired)
|
||||||
|
p.Weightage = int32(n.cpucap_weightage)
|
||||||
|
p.EntCapacity = int32(n.entitled_proc_capacity)
|
||||||
|
p.VCpus.Online = int64(n.vcpus.online)
|
||||||
|
p.VCpus.Max = int64(n.vcpus.max)
|
||||||
|
p.VCpus.Min = int64(n.vcpus.min)
|
||||||
|
p.VCpus.Desired = int64(n.vcpus.desired)
|
||||||
|
p.PoolID = int32(n.processor_poolid)
|
||||||
|
p.ActiveCpusInPool = int32(n.activecpusinpool)
|
||||||
|
p.PoolWeightage = int32(n.cpupool_weightage)
|
||||||
|
p.SharedPCpu = int32(n.sharedpcpu)
|
||||||
|
p.MaxPoolCap = int32(n.maxpoolcap)
|
||||||
|
p.EntPoolCap = int32(n.entpoolcap)
|
||||||
|
p.Mem.Online = int64(n.mem.online)
|
||||||
|
p.Mem.Max = int64(n.mem.max)
|
||||||
|
p.Mem.Min = int64(n.mem.min)
|
||||||
|
p.Mem.Desired = int64(n.mem.desired)
|
||||||
|
p.MemWeightage = int32(n.mem_weightage)
|
||||||
|
p.TotalIOMemoryEntitlement = int64(n.totiomement)
|
||||||
|
p.MemPoolID = int32(n.mempoolid)
|
||||||
|
p.HyperPgSize = int64(n.hyperpgsize)
|
||||||
|
p.ExpMem.Online = int64(n.exp_mem.online)
|
||||||
|
p.ExpMem.Max = int64(n.exp_mem.max)
|
||||||
|
p.ExpMem.Min = int64(n.exp_mem.min)
|
||||||
|
p.ExpMem.Desired = int64(n.exp_mem.desired)
|
||||||
|
p.TargetMemExpFactor = int64(n.targetmemexpfactor)
|
||||||
|
p.TargetMemExpSize = int64(n.targetmemexpsize)
|
||||||
|
p.SubProcessorMode = int32(n.subprocessor_mode)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatmemorytotal2memorytotal(n C.perfstat_memory_total_t) MemoryTotal {
|
||||||
|
var m MemoryTotal
|
||||||
|
m.VirtualTotal = int64(n.virt_total)
|
||||||
|
m.RealTotal = int64(n.real_total)
|
||||||
|
m.RealFree = int64(n.real_free)
|
||||||
|
m.RealPinned = int64(n.real_pinned)
|
||||||
|
m.RealInUse = int64(n.real_inuse)
|
||||||
|
m.BadPages = int64(n.pgbad)
|
||||||
|
m.PageFaults = int64(n.pgexct)
|
||||||
|
m.PageIn = int64(n.pgins)
|
||||||
|
m.PageOut = int64(n.pgouts)
|
||||||
|
m.PgSpIn = int64(n.pgspins)
|
||||||
|
m.PgSpOut = int64(n.pgspouts)
|
||||||
|
m.Scans = int64(n.scans)
|
||||||
|
m.Cycles = int64(n.cycles)
|
||||||
|
m.PgSteals = int64(n.pgsteals)
|
||||||
|
m.NumPerm = int64(n.numperm)
|
||||||
|
m.PgSpTotal = int64(n.pgsp_total)
|
||||||
|
m.PgSpFree = int64(n.pgsp_free)
|
||||||
|
m.PgSpRsvd = int64(n.pgsp_rsvd)
|
||||||
|
m.RealSystem = int64(n.real_system)
|
||||||
|
m.RealUser = int64(n.real_user)
|
||||||
|
m.RealProcess = int64(n.real_process)
|
||||||
|
m.VirtualActive = int64(n.virt_active)
|
||||||
|
m.IOME = int64(n.iome)
|
||||||
|
m.IOMU = int64(n.iomu)
|
||||||
|
m.IOHWM = int64(n.iohwm)
|
||||||
|
m.PMem = int64(n.pmem)
|
||||||
|
m.CompressedTotal = int64(n.comprsd_total)
|
||||||
|
m.CompressedWSegPg = int64(n.comprsd_wseg_pgs)
|
||||||
|
m.CPgIn = int64(n.cpgins)
|
||||||
|
m.CPgOut = int64(n.cpgouts)
|
||||||
|
m.TrueSize = int64(n.true_size)
|
||||||
|
m.ExpandedMemory = int64(n.expanded_memory)
|
||||||
|
m.CompressedWSegSize = int64(n.comprsd_wseg_size)
|
||||||
|
m.TargetCPoolSize = int64(n.target_cpool_size)
|
||||||
|
m.MaxCPoolSize = int64(n.max_cpool_size)
|
||||||
|
m.MinUCPoolSize = int64(n.min_ucpool_size)
|
||||||
|
m.CPoolSize = int64(n.cpool_size)
|
||||||
|
m.UCPoolSize = int64(n.ucpool_size)
|
||||||
|
m.CPoolInUse = int64(n.cpool_inuse)
|
||||||
|
m.UCPoolInUse = int64(n.ucpool_inuse)
|
||||||
|
m.Version = int64(n.version)
|
||||||
|
m.RealAvailable = int64(n.real_avail)
|
||||||
|
m.BytesCoalesced = int64(n.bytes_coalesced)
|
||||||
|
m.BytesCoalescedMemPool = int64(n.bytes_coalesced_mempool)
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatnetinterfacetotal2netifacetotal(n C.perfstat_netinterface_total_t) NetIfaceTotal {
|
||||||
|
var i NetIfaceTotal
|
||||||
|
|
||||||
|
i.Number = int32(n.number)
|
||||||
|
i.IPackets = int64(n.ipackets)
|
||||||
|
i.IBytes = int64(n.ibytes)
|
||||||
|
i.IErrors = int64(n.ierrors)
|
||||||
|
i.OPackets = int64(n.opackets)
|
||||||
|
i.OBytes = int64(n.obytes)
|
||||||
|
i.OErrors = int64(n.oerrors)
|
||||||
|
i.Collisions = int64(n.collisions)
|
||||||
|
i.XmitDrops = int64(n.xmitdrops)
|
||||||
|
i.Version = int64(n.version)
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatdisk2disk(n *C.perfstat_disk_t) Disk {
|
||||||
|
var d Disk
|
||||||
|
|
||||||
|
d.Name = C.GoString(&n.name[0])
|
||||||
|
d.Description = C.GoString(&n.description[0])
|
||||||
|
d.VGName = C.GoString(&n.vgname[0])
|
||||||
|
d.Size = int64(n.size)
|
||||||
|
d.Free = int64(n.free)
|
||||||
|
d.BSize = int64(n.bsize)
|
||||||
|
d.XRate = int64(n.xrate)
|
||||||
|
d.Xfers = int64(n.xfers)
|
||||||
|
d.Wblks = int64(n.wblks)
|
||||||
|
d.Rblks = int64(n.rblks)
|
||||||
|
d.QDepth = int64(n.qdepth)
|
||||||
|
d.Time = int64(n.time)
|
||||||
|
d.Adapter = C.GoString(&n.adapter[0])
|
||||||
|
d.PathsCount = int32(n.paths_count)
|
||||||
|
d.QFull = int64(n.q_full)
|
||||||
|
d.Rserv = int64(n.rserv)
|
||||||
|
d.RTimeOut = int64(n.rtimeout)
|
||||||
|
d.Rfailed = int64(n.rfailed)
|
||||||
|
d.MinRserv = int64(n.min_rserv)
|
||||||
|
d.MaxRserv = int64(n.max_rserv)
|
||||||
|
d.Wserv = int64(n.wserv)
|
||||||
|
d.WTimeOut = int64(n.wtimeout)
|
||||||
|
d.Wfailed = int64(n.wfailed)
|
||||||
|
d.MinWserv = int64(n.min_wserv)
|
||||||
|
d.MaxWserv = int64(n.max_wserv)
|
||||||
|
d.WqDepth = int64(n.wq_depth)
|
||||||
|
d.WqSampled = int64(n.wq_sampled)
|
||||||
|
d.WqTime = int64(n.wq_time)
|
||||||
|
d.WqMinTime = int64(n.wq_min_time)
|
||||||
|
d.WqMaxTime = int64(n.wq_max_time)
|
||||||
|
d.QSampled = int64(n.q_sampled)
|
||||||
|
d.Version = int64(n.version)
|
||||||
|
d.PseudoDisk = (n.dk_type[0] & (1 << 7)) > 0
|
||||||
|
d.VTDisk = (n.dk_type[0] & (1 << 6)) > 0
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatdiskpath2diskpath(n *C.perfstat_diskpath_t) DiskPath {
|
||||||
|
var d DiskPath
|
||||||
|
|
||||||
|
d.Name = C.GoString(&n.name[0])
|
||||||
|
d.XRate = int64(n.xrate)
|
||||||
|
d.Xfers = int64(n.xfers)
|
||||||
|
d.Rblks = int64(n.rblks)
|
||||||
|
d.Wblks = int64(n.wblks)
|
||||||
|
d.Time = int64(n.time)
|
||||||
|
d.Adapter = C.GoString(&n.adapter[0])
|
||||||
|
d.QFull = int64(n.q_full)
|
||||||
|
d.Rserv = int64(n.rserv)
|
||||||
|
d.RTimeOut = int64(n.rtimeout)
|
||||||
|
d.Rfailed = int64(n.rfailed)
|
||||||
|
d.MinRserv = int64(n.min_rserv)
|
||||||
|
d.MaxRserv = int64(n.max_rserv)
|
||||||
|
d.Wserv = int64(n.wserv)
|
||||||
|
d.WTimeOut = int64(n.wtimeout)
|
||||||
|
d.Wfailed = int64(n.wfailed)
|
||||||
|
d.MinWserv = int64(n.min_wserv)
|
||||||
|
d.MaxWserv = int64(n.max_wserv)
|
||||||
|
d.WqDepth = int64(n.wq_depth)
|
||||||
|
d.WqSampled = int64(n.wq_sampled)
|
||||||
|
d.WqTime = int64(n.wq_time)
|
||||||
|
d.WqMinTime = int64(n.wq_min_time)
|
||||||
|
d.WqMaxTime = int64(n.wq_max_time)
|
||||||
|
d.QSampled = int64(n.q_sampled)
|
||||||
|
d.Version = int64(n.version)
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatfcstat2fcadapter(n *C.perfstat_fcstat_t) FCAdapter {
|
||||||
|
var f FCAdapter
|
||||||
|
|
||||||
|
f.Version = int64(n.version)
|
||||||
|
f.Name = C.GoString(&n.name[0])
|
||||||
|
f.State = int32(n.state)
|
||||||
|
f.InputRequests = int64(n.InputRequests)
|
||||||
|
f.OutputRequests = int64(n.OutputRequests)
|
||||||
|
f.InputBytes = int64(n.InputBytes)
|
||||||
|
f.OutputBytes = int64(n.OutputBytes)
|
||||||
|
f.EffMaxTransfer = int64(n.EffMaxTransfer)
|
||||||
|
f.NoDMAResourceCnt = int64(n.NoDMAResourceCnt)
|
||||||
|
f.NoCmdResourceCnt = int64(n.NoCmdResourceCnt)
|
||||||
|
f.AttentionType = int32(n.AttentionType)
|
||||||
|
f.SecondsSinceLastReset = int64(n.SecondsSinceLastReset)
|
||||||
|
f.TxFrames = int64(n.TxFrames)
|
||||||
|
f.TxWords = int64(n.TxWords)
|
||||||
|
f.RxFrames = int64(n.RxFrames)
|
||||||
|
f.RxWords = int64(n.RxWords)
|
||||||
|
f.LIPCount = int64(n.LIPCount)
|
||||||
|
f.NOSCount = int64(n.NOSCount)
|
||||||
|
f.ErrorFrames = int64(n.ErrorFrames)
|
||||||
|
f.DumpedFrames = int64(n.DumpedFrames)
|
||||||
|
f.LinkFailureCount = int64(n.LinkFailureCount)
|
||||||
|
f.LossofSyncCount = int64(n.LossofSyncCount)
|
||||||
|
f.LossofSignal = int64(n.LossofSignal)
|
||||||
|
f.PrimitiveSeqProtocolErrCount = int64(n.PrimitiveSeqProtocolErrCount)
|
||||||
|
f.InvalidTxWordCount = int64(n.InvalidTxWordCount)
|
||||||
|
f.InvalidCRCCount = int64(n.InvalidCRCCount)
|
||||||
|
f.PortFcId = int64(n.PortFcId)
|
||||||
|
f.PortSpeed = int64(n.PortSpeed)
|
||||||
|
f.PortType = C.GoString(&n.PortType[0])
|
||||||
|
f.PortWWN = int64(n.PortWWN)
|
||||||
|
f.PortSupportedSpeed = int64(n.PortSupportedSpeed)
|
||||||
|
f.AdapterType = int(n.adapter_type)
|
||||||
|
f.VfcName = C.GoString(&n.vfc_name[0])
|
||||||
|
f.ClientPartName = C.GoString(&n.client_part_name[0])
|
||||||
|
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatlogicalvolume2logicalvolume(n *C.perfstat_logicalvolume_t) LogicalVolume {
|
||||||
|
var l LogicalVolume
|
||||||
|
|
||||||
|
l.Name = C.GoString(&n.name[0])
|
||||||
|
l.VGName = C.GoString(&n.vgname[0])
|
||||||
|
l.OpenClose = int64(n.open_close)
|
||||||
|
l.State = int64(n.state)
|
||||||
|
l.MirrorPolicy = int64(n.mirror_policy)
|
||||||
|
l.MirrorWriteConsistency = int64(n.mirror_write_consistency)
|
||||||
|
l.WriteVerify = int64(n.write_verify)
|
||||||
|
l.PPsize = int64(n.ppsize)
|
||||||
|
l.LogicalPartitions = int64(n.logical_partitions)
|
||||||
|
l.Mirrors = int32(n.mirrors)
|
||||||
|
l.IOCnt = int64(n.iocnt)
|
||||||
|
l.KBReads = int64(n.kbreads)
|
||||||
|
l.KBWrites = int64(n.kbwrites)
|
||||||
|
l.Version = int64(n.version)
|
||||||
|
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatvolumegroup2volumegroup(n *C.perfstat_volumegroup_t) VolumeGroup {
|
||||||
|
var v VolumeGroup
|
||||||
|
|
||||||
|
v.Name = C.GoString(&n.name[0])
|
||||||
|
v.TotalDisks = int64(n.total_disks)
|
||||||
|
v.ActiveDisks = int64(n.active_disks)
|
||||||
|
v.TotalLogicalVolumes = int64(n.total_logical_volumes)
|
||||||
|
v.OpenedLogicalVolumes = int64(n.opened_logical_volumes)
|
||||||
|
v.IOCnt = int64(n.iocnt)
|
||||||
|
v.KBReads = int64(n.kbreads)
|
||||||
|
v.KBWrites = int64(n.kbwrites)
|
||||||
|
v.Version = int64(n.version)
|
||||||
|
v.VariedState = int(n.variedState)
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatmemorypage2memorypage(n *C.perfstat_memory_page_t) MemoryPage {
|
||||||
|
var m MemoryPage
|
||||||
|
|
||||||
|
m.PSize = int64(n.psize)
|
||||||
|
m.RealTotal = int64(n.real_total)
|
||||||
|
m.RealFree = int64(n.real_free)
|
||||||
|
m.RealPinned = int64(n.real_pinned)
|
||||||
|
m.RealInUse = int64(n.real_inuse)
|
||||||
|
m.PgExct = int64(n.pgexct)
|
||||||
|
m.PgIns = int64(n.pgins)
|
||||||
|
m.PgOuts = int64(n.pgouts)
|
||||||
|
m.PgSpIns = int64(n.pgspins)
|
||||||
|
m.PgSpOuts = int64(n.pgspouts)
|
||||||
|
m.Scans = int64(n.scans)
|
||||||
|
m.Cycles = int64(n.cycles)
|
||||||
|
m.PgSteals = int64(n.pgsteals)
|
||||||
|
m.NumPerm = int64(n.numperm)
|
||||||
|
m.NumPgSp = int64(n.numpgsp)
|
||||||
|
m.RealSystem = int64(n.real_system)
|
||||||
|
m.RealUser = int64(n.real_user)
|
||||||
|
m.RealProcess = int64(n.real_process)
|
||||||
|
m.VirtActive = int64(n.virt_active)
|
||||||
|
m.ComprsdTotal = int64(n.comprsd_total)
|
||||||
|
m.ComprsdWsegPgs = int64(n.comprsd_wseg_pgs)
|
||||||
|
m.CPgIns = int64(n.cpgins)
|
||||||
|
m.CPgOuts = int64(n.cpgouts)
|
||||||
|
m.CPoolInUse = int64(n.cpool_inuse)
|
||||||
|
m.UCPoolSize = int64(n.ucpool_size)
|
||||||
|
m.ComprsdWsegSize = int64(n.comprsd_wseg_size)
|
||||||
|
m.Version = int64(n.version)
|
||||||
|
m.RealAvail = int64(n.real_avail)
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatnetbuffer2netbuffer(n *C.perfstat_netbuffer_t) NetBuffer {
|
||||||
|
var b NetBuffer
|
||||||
|
|
||||||
|
b.Name = C.GoString(&n.name[0])
|
||||||
|
b.InUse = int64(n.inuse)
|
||||||
|
b.Calls = int64(n.calls)
|
||||||
|
b.Delayed = int64(n.delayed)
|
||||||
|
b.Free = int64(n.free)
|
||||||
|
b.Failed = int64(n.failed)
|
||||||
|
b.HighWatermark = int64(n.highwatermark)
|
||||||
|
b.Freed = int64(n.freed)
|
||||||
|
b.Version = int64(n.version)
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatnetinterface2netiface(n *C.perfstat_netinterface_t) NetIface {
|
||||||
|
var i NetIface
|
||||||
|
|
||||||
|
i.Name = C.GoString(&n.name[0])
|
||||||
|
i.Description = C.GoString(&n.description[0])
|
||||||
|
i.Type = uint8(n._type)
|
||||||
|
i.MTU = int64(n.mtu)
|
||||||
|
i.IPackets = int64(n.ipackets)
|
||||||
|
i.IBytes = int64(n.ibytes)
|
||||||
|
i.IErrors = int64(n.ierrors)
|
||||||
|
i.OPackets = int64(n.opackets)
|
||||||
|
i.OBytes = int64(n.obytes)
|
||||||
|
i.OErrors = int64(n.oerrors)
|
||||||
|
i.Collisions = int64(n.collisions)
|
||||||
|
i.Bitrate = int64(n.bitrate)
|
||||||
|
i.XmitDrops = int64(n.xmitdrops)
|
||||||
|
i.Version = int64(n.version)
|
||||||
|
i.IfIqDrops = int64(n.if_iqdrops)
|
||||||
|
i.IfArpDrops = int64(n.if_arpdrops)
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatnetadapter2netadapter(n *C.perfstat_netadapter_t) NetAdapter {
|
||||||
|
var i NetAdapter
|
||||||
|
|
||||||
|
i.Version = int64(n.version)
|
||||||
|
i.Name = C.GoString(&n.name[0])
|
||||||
|
i.TxPackets = int64(n.tx_packets)
|
||||||
|
i.TxBytes = int64(n.tx_bytes)
|
||||||
|
i.TxInterrupts = int64(n.tx_interrupts)
|
||||||
|
i.TxErrors = int64(n.tx_errors)
|
||||||
|
i.TxPacketsDropped = int64(n.tx_packets_dropped)
|
||||||
|
i.TxQueueSize = int64(n.tx_queue_size)
|
||||||
|
i.TxQueueLen = int64(n.tx_queue_len)
|
||||||
|
i.TxQueueOverflow = int64(n.tx_queue_overflow)
|
||||||
|
i.TxBroadcastPackets = int64(n.tx_broadcast_packets)
|
||||||
|
i.TxMulticastPackets = int64(n.tx_multicast_packets)
|
||||||
|
i.TxCarrierSense = int64(n.tx_carrier_sense)
|
||||||
|
i.TxDMAUnderrun = int64(n.tx_DMA_underrun)
|
||||||
|
i.TxLostCTSErrors = int64(n.tx_lost_CTS_errors)
|
||||||
|
i.TxMaxCollisionErrors = int64(n.tx_max_collision_errors)
|
||||||
|
i.TxLateCollisionErrors = int64(n.tx_late_collision_errors)
|
||||||
|
i.TxDeferred = int64(n.tx_deferred)
|
||||||
|
i.TxTimeoutErrors = int64(n.tx_timeout_errors)
|
||||||
|
i.TxSingleCollisionCount = int64(n.tx_single_collision_count)
|
||||||
|
i.TxMultipleCollisionCount = int64(n.tx_multiple_collision_count)
|
||||||
|
i.RxPackets = int64(n.rx_packets)
|
||||||
|
i.RxBytes = int64(n.rx_bytes)
|
||||||
|
i.RxInterrupts = int64(n.rx_interrupts)
|
||||||
|
i.RxErrors = int64(n.rx_errors)
|
||||||
|
i.RxPacketsDropped = int64(n.rx_packets_dropped)
|
||||||
|
i.RxBadPackets = int64(n.rx_bad_packets)
|
||||||
|
i.RxMulticastPackets = int64(n.rx_multicast_packets)
|
||||||
|
i.RxBroadcastPackets = int64(n.rx_broadcast_packets)
|
||||||
|
i.RxCRCErrors = int64(n.rx_CRC_errors)
|
||||||
|
i.RxDMAOverrun = int64(n.rx_DMA_overrun)
|
||||||
|
i.RxAlignmentErrors = int64(n.rx_alignment_errors)
|
||||||
|
i.RxNoResourceErrors = int64(n.rx_noresource_errors)
|
||||||
|
i.RxCollisionErrors = int64(n.rx_collision_errors)
|
||||||
|
i.RxPacketTooShortErrors = int64(n.rx_packet_tooshort_errors)
|
||||||
|
i.RxPacketTooLongErrors = int64(n.rx_packet_toolong_errors)
|
||||||
|
i.RxPacketDiscardedByAdapter = int64(n.rx_packets_discardedbyadapter)
|
||||||
|
i.AdapterType = int32(n.adapter_type)
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatpagingspace2pagingspace(n *C.perfstat_pagingspace_t) PagingSpace {
|
||||||
|
var i PagingSpace
|
||||||
|
|
||||||
|
i.Name = C.GoString(&n.name[0])
|
||||||
|
i.Type = uint8(n._type)
|
||||||
|
i.VGName = C.GoString(C.get_ps_vgname(n))
|
||||||
|
i.Hostname = C.GoString(C.get_ps_hostname(n))
|
||||||
|
i.Filename = C.GoString(C.get_ps_filename(n))
|
||||||
|
i.LPSize = int64(n.lp_size)
|
||||||
|
i.MBSize = int64(n.mb_size)
|
||||||
|
i.MBUsed = int64(n.mb_used)
|
||||||
|
i.IOPending = int64(n.io_pending)
|
||||||
|
i.Active = uint8(n.active)
|
||||||
|
i.Automatic = uint8(n.automatic)
|
||||||
|
i.Version = int64(n.version)
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatprocess2process(n *C.perfstat_process_t) Process {
|
||||||
|
var i Process
|
||||||
|
|
||||||
|
i.Version = int64(n.version)
|
||||||
|
i.PID = int64(n.pid)
|
||||||
|
i.ProcessName = C.GoString(&n.proc_name[0])
|
||||||
|
i.Priority = int32(n.proc_priority)
|
||||||
|
i.NumThreads = int64(n.num_threads)
|
||||||
|
i.UID = int64(n.proc_uid)
|
||||||
|
i.ClassID = int64(n.proc_classid)
|
||||||
|
i.Size = int64(n.proc_size)
|
||||||
|
i.RealMemData = int64(n.proc_real_mem_data)
|
||||||
|
i.RealMemText = int64(n.proc_real_mem_text)
|
||||||
|
i.VirtMemData = int64(n.proc_virt_mem_data)
|
||||||
|
i.VirtMemText = int64(n.proc_virt_mem_text)
|
||||||
|
i.SharedLibDataSize = int64(n.shared_lib_data_size)
|
||||||
|
i.HeapSize = int64(n.heap_size)
|
||||||
|
i.RealInUse = int64(n.real_inuse)
|
||||||
|
i.VirtInUse = int64(n.virt_inuse)
|
||||||
|
i.Pinned = int64(n.pinned)
|
||||||
|
i.PgSpInUse = int64(n.pgsp_inuse)
|
||||||
|
i.FilePages = int64(n.filepages)
|
||||||
|
i.RealInUseMap = int64(n.real_inuse_map)
|
||||||
|
i.VirtInUseMap = int64(n.virt_inuse_map)
|
||||||
|
i.PinnedInUseMap = int64(n.pinned_inuse_map)
|
||||||
|
i.UCpuTime = float64(n.ucpu_time)
|
||||||
|
i.SCpuTime = float64(n.scpu_time)
|
||||||
|
i.LastTimeBase = int64(n.last_timebase)
|
||||||
|
i.InBytes = int64(n.inBytes)
|
||||||
|
i.OutBytes = int64(n.outBytes)
|
||||||
|
i.InOps = int64(n.inOps)
|
||||||
|
i.OutOps = int64(n.outOps)
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func perfstatthread2thread(n *C.perfstat_thread_t) Thread {
|
||||||
|
var i Thread
|
||||||
|
|
||||||
|
i.TID = int64(n.tid)
|
||||||
|
i.PID = int64(n.pid)
|
||||||
|
i.CpuID = int64(n.cpuid)
|
||||||
|
i.UCpuTime = float64(n.ucpu_time)
|
||||||
|
i.SCpuTime = float64(n.scpu_time)
|
||||||
|
i.LastTimeBase = int64(n.last_timebase)
|
||||||
|
i.Version = int64(n.version)
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func fsinfo2filesystem(n *C.struct_fsinfo) FileSystem {
|
||||||
|
var i FileSystem
|
||||||
|
|
||||||
|
i.Device = C.GoString(n.devname)
|
||||||
|
i.MountPoint = C.GoString(n.fsname)
|
||||||
|
i.FSType = int(n.fstype)
|
||||||
|
i.Flags = uint(n.flags)
|
||||||
|
i.TotalBlocks = int64(n.totalblks)
|
||||||
|
i.FreeBlocks = int64(n.freeblks)
|
||||||
|
i.TotalInodes = int64(n.totalinodes)
|
||||||
|
i.FreeInodes = int64(n.freeinodes)
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func lparinfo2partinfo(n C.lpar_info_format2_t) PartitionInfo {
|
||||||
|
var i PartitionInfo
|
||||||
|
|
||||||
|
i.Version = int(n.version)
|
||||||
|
i.OnlineMemory = uint64(n.online_memory)
|
||||||
|
i.TotalDispatchTime = uint64(n.tot_dispatch_time)
|
||||||
|
i.PoolIdleTime = uint64(n.pool_idle_time)
|
||||||
|
i.DispatchLatency = uint64(n.dispatch_latency)
|
||||||
|
i.LparFlags = uint(n.lpar_flags)
|
||||||
|
i.PCpusInSys = uint(n.pcpus_in_sys)
|
||||||
|
i.OnlineVCpus = uint(n.online_vcpus)
|
||||||
|
i.OnlineLCpus = uint(n.online_lcpus)
|
||||||
|
i.PCpusInPool = uint(n.pcpus_in_pool)
|
||||||
|
i.UnallocCapacity = uint(n.unalloc_capacity)
|
||||||
|
i.EntitledCapacity = uint(n.entitled_capacity)
|
||||||
|
i.VariableWeight = uint(n.variable_weight)
|
||||||
|
i.UnallocWeight = uint(n.unalloc_weight)
|
||||||
|
i.MinReqVCpuCapacity = uint(n.min_req_vcpu_capacity)
|
||||||
|
i.GroupId = uint8(n.group_id)
|
||||||
|
i.PoolId = uint8(n.pool_id)
|
||||||
|
i.ShCpusInSys = uint(n.shcpus_in_sys)
|
||||||
|
i.MaxPoolCapacity = uint(n.max_pool_capacity)
|
||||||
|
i.EntitledPoolCapacity = uint(n.entitled_pool_capacity)
|
||||||
|
i.PoolMaxTime = uint64(n.pool_max_time)
|
||||||
|
i.PoolBusyTime = uint64(n.pool_busy_time)
|
||||||
|
i.PoolScaledBusyTime = uint64(n.pool_scaled_busy_time)
|
||||||
|
i.ShCpuTotalTime = uint64(n.shcpu_tot_time)
|
||||||
|
i.ShCpuBusyTime = uint64(n.shcpu_busy_time)
|
||||||
|
i.ShCpuScaledBusyTime = uint64(n.shcpu_scaled_busy_time)
|
||||||
|
i.EntMemCapacity = uint64(n.ent_mem_capacity)
|
||||||
|
i.PhysMem = uint64(n.phys_mem)
|
||||||
|
i.VrmPoolPhysMem = uint64(n.vrm_pool_physmem)
|
||||||
|
i.HypPageSize = uint(n.hyp_pagesize)
|
||||||
|
i.VrmPoolId = int(n.vrm_pool_id)
|
||||||
|
i.VrmGroupId = int(n.vrm_group_id)
|
||||||
|
i.VarMemWeight = int(n.var_mem_weight)
|
||||||
|
i.UnallocVarMemWeight = int(n.unalloc_var_mem_weight)
|
||||||
|
i.UnallocEntMemCapacity = uint64(n.unalloc_ent_mem_capacity)
|
||||||
|
i.TrueOnlineMemory = uint64(n.true_online_memory)
|
||||||
|
i.AmeOnlineMemory = uint64(n.ame_online_memory)
|
||||||
|
i.AmeType = uint8(n.ame_type)
|
||||||
|
i.SpecExecMode = uint8(n.spec_exec_mode)
|
||||||
|
i.AmeFactor = uint(n.ame_factor)
|
||||||
|
i.EmPartMajorCode = uint(n.em_part_major_code)
|
||||||
|
i.EmPartMinorCode = uint(n.em_part_minor_code)
|
||||||
|
i.BytesCoalesced = uint64(n.bytes_coalesced)
|
||||||
|
i.BytesCoalescedMemPool = uint64(n.bytes_coalesced_mempool)
|
||||||
|
i.PurrCoalescing = uint64(n.purr_coalescing)
|
||||||
|
i.SpurrCoalescing = uint64(n.spurr_coalescing)
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
40
vendor/github.com/power-devops/perfstat/lparstat.go
generated
vendored
Normal file
40
vendor/github.com/power-devops/perfstat/lparstat.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <sys/dr.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PartitionStat() (*PartitionConfig, error) {
|
||||||
|
var part C.perfstat_partition_config_t
|
||||||
|
|
||||||
|
rc := C.perfstat_partition_config(nil, &part, C.sizeof_perfstat_partition_config_t, 1)
|
||||||
|
if rc != 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_partition_config() error")
|
||||||
|
}
|
||||||
|
p := perfstatpartitionconfig2partitionconfig(part)
|
||||||
|
return &p, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func LparInfo() (*PartitionInfo, error) {
|
||||||
|
var pinfo C.lpar_info_format2_t
|
||||||
|
|
||||||
|
rc := C.lpar_get_info(C.LPAR_INFO_FORMAT2, unsafe.Pointer(&pinfo), C.sizeof_lpar_info_format2_t)
|
||||||
|
if rc != 0 {
|
||||||
|
return nil, fmt.Errorf("lpar_get_info() error")
|
||||||
|
}
|
||||||
|
p := lparinfo2partinfo(pinfo)
|
||||||
|
return &p, nil
|
||||||
|
}
|
||||||
73
vendor/github.com/power-devops/perfstat/lvmstat.go
generated
vendored
Normal file
73
vendor/github.com/power-devops/perfstat/lvmstat.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "c_helpers.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func LogicalVolumeStat() ([]LogicalVolume, error) {
|
||||||
|
var lv *C.perfstat_logicalvolume_t
|
||||||
|
var lvname C.perfstat_id_t
|
||||||
|
|
||||||
|
numlvs := C.perfstat_logicalvolume(nil, nil, C.sizeof_perfstat_logicalvolume_t, 0)
|
||||||
|
if numlvs <= 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_logicalvolume() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_len := C.sizeof_perfstat_logicalvolume_t * C.ulong(numlvs)
|
||||||
|
lv = (*C.perfstat_logicalvolume_t)(C.malloc(lv_len))
|
||||||
|
defer C.free(unsafe.Pointer(lv))
|
||||||
|
C.strcpy(&lvname.name[0], C.CString(""))
|
||||||
|
r := C.perfstat_logicalvolume(&lvname, lv, C.sizeof_perfstat_logicalvolume_t, numlvs)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_logicalvolume() error")
|
||||||
|
}
|
||||||
|
lvs := make([]LogicalVolume, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
l := C.get_logicalvolume_stat(lv, C.int(i))
|
||||||
|
if l != nil {
|
||||||
|
lvs[i] = perfstatlogicalvolume2logicalvolume(l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lvs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func VolumeGroupStat() ([]VolumeGroup, error) {
|
||||||
|
var vg *C.perfstat_volumegroup_t
|
||||||
|
var vgname C.perfstat_id_t
|
||||||
|
|
||||||
|
numvgs := C.perfstat_volumegroup(nil, nil, C.sizeof_perfstat_volumegroup_t, 0)
|
||||||
|
if numvgs <= 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_volumegroup() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
vg_len := C.sizeof_perfstat_volumegroup_t * C.ulong(numvgs)
|
||||||
|
vg = (*C.perfstat_volumegroup_t)(C.malloc(vg_len))
|
||||||
|
defer C.free(unsafe.Pointer(vg))
|
||||||
|
C.strcpy(&vgname.name[0], C.CString(""))
|
||||||
|
r := C.perfstat_volumegroup(&vgname, vg, C.sizeof_perfstat_volumegroup_t, numvgs)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_volumegroup() error")
|
||||||
|
}
|
||||||
|
vgs := make([]VolumeGroup, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
v := C.get_volumegroup_stat(vg, C.int(i))
|
||||||
|
if v != nil {
|
||||||
|
vgs[i] = perfstatvolumegroup2volumegroup(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vgs, nil
|
||||||
|
}
|
||||||
85
vendor/github.com/power-devops/perfstat/memstat.go
generated
vendored
Normal file
85
vendor/github.com/power-devops/perfstat/memstat.go
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "c_helpers.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MemoryTotalStat() (*MemoryTotal, error) {
|
||||||
|
var memory C.perfstat_memory_total_t
|
||||||
|
|
||||||
|
rc := C.perfstat_memory_total(nil, &memory, C.sizeof_perfstat_memory_total_t, 1)
|
||||||
|
if rc != 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_memory_total() error")
|
||||||
|
}
|
||||||
|
m := perfstatmemorytotal2memorytotal(memory)
|
||||||
|
return &m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func MemoryPageStat() ([]MemoryPage, error) {
|
||||||
|
var mempage *C.perfstat_memory_page_t
|
||||||
|
var fps C.perfstat_psize_t
|
||||||
|
|
||||||
|
numps := C.perfstat_memory_page(nil, nil, C.sizeof_perfstat_memory_page_t, 0)
|
||||||
|
if numps < 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_memory_page() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_len := C.sizeof_perfstat_memory_page_t * C.ulong(numps)
|
||||||
|
mempage = (*C.perfstat_memory_page_t)(C.malloc(mp_len))
|
||||||
|
defer C.free(unsafe.Pointer(mempage))
|
||||||
|
fps.psize = C.FIRST_PSIZE
|
||||||
|
r := C.perfstat_memory_page(&fps, mempage, C.sizeof_perfstat_memory_page_t, numps)
|
||||||
|
if r < 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_memory_page() error")
|
||||||
|
}
|
||||||
|
ps := make([]MemoryPage, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
p := C.get_memory_page_stat(mempage, C.int(i))
|
||||||
|
if p != nil {
|
||||||
|
ps[i] = perfstatmemorypage2memorypage(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ps, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func PagingSpaceStat() ([]PagingSpace, error) {
|
||||||
|
var pspace *C.perfstat_pagingspace_t
|
||||||
|
var fps C.perfstat_id_t
|
||||||
|
|
||||||
|
numps := C.perfstat_pagingspace(nil, nil, C.sizeof_perfstat_pagingspace_t, 0)
|
||||||
|
if numps <= 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_pagingspace() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
ps_len := C.sizeof_perfstat_pagingspace_t * C.ulong(numps)
|
||||||
|
pspace = (*C.perfstat_pagingspace_t)(C.malloc(ps_len))
|
||||||
|
defer C.free(unsafe.Pointer(pspace))
|
||||||
|
C.strcpy(&fps.name[0], C.CString(C.FIRST_PAGINGSPACE))
|
||||||
|
r := C.perfstat_pagingspace(&fps, pspace, C.sizeof_perfstat_pagingspace_t, numps)
|
||||||
|
if r < 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_pagingspace() error")
|
||||||
|
}
|
||||||
|
ps := make([]PagingSpace, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
p := C.get_pagingspace_stat(pspace, C.int(i))
|
||||||
|
if p != nil {
|
||||||
|
ps[i] = perfstatpagingspace2pagingspace(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ps, nil
|
||||||
|
}
|
||||||
118
vendor/github.com/power-devops/perfstat/netstat.go
generated
vendored
Normal file
118
vendor/github.com/power-devops/perfstat/netstat.go
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "c_helpers.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NetIfaceTotalStat() (*NetIfaceTotal, error) {
|
||||||
|
var nif C.perfstat_netinterface_total_t
|
||||||
|
|
||||||
|
rc := C.perfstat_netinterface_total(nil, &nif, C.sizeof_perfstat_netinterface_total_t, 1)
|
||||||
|
if rc != 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_netinterface_total() error")
|
||||||
|
}
|
||||||
|
n := perfstatnetinterfacetotal2netifacetotal(nif)
|
||||||
|
return &n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NetBufferStat() ([]NetBuffer, error) {
|
||||||
|
var nbuf *C.perfstat_netbuffer_t
|
||||||
|
var first C.perfstat_id_t
|
||||||
|
|
||||||
|
numbuf := C.perfstat_netbuffer(nil, nil, C.sizeof_perfstat_netbuffer_t, 0)
|
||||||
|
if numbuf < 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_netbuffer() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
nblen := C.sizeof_perfstat_netbuffer_t * C.ulong(numbuf)
|
||||||
|
nbuf = (*C.perfstat_netbuffer_t)(C.malloc(nblen))
|
||||||
|
defer C.free(unsafe.Pointer(nbuf))
|
||||||
|
C.strcpy(&first.name[0], C.CString(C.FIRST_NETBUFFER))
|
||||||
|
r := C.perfstat_netbuffer(&first, nbuf, C.sizeof_perfstat_netbuffer_t, numbuf)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_netbuffer() error")
|
||||||
|
}
|
||||||
|
nb := make([]NetBuffer, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
b := C.get_netbuffer_stat(nbuf, C.int(i))
|
||||||
|
if b != nil {
|
||||||
|
nb[i] = perfstatnetbuffer2netbuffer(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nb, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NetIfaceStat() ([]NetIface, error) {
|
||||||
|
var nif *C.perfstat_netinterface_t
|
||||||
|
var first C.perfstat_id_t
|
||||||
|
|
||||||
|
numif := C.perfstat_netinterface(nil, nil, C.sizeof_perfstat_netinterface_t, 0)
|
||||||
|
if numif < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_netinterface() error")
|
||||||
|
}
|
||||||
|
if numif == 0 {
|
||||||
|
return []NetIface{}, fmt.Errorf("no network interfaces found")
|
||||||
|
}
|
||||||
|
|
||||||
|
iflen := C.sizeof_perfstat_netinterface_t * C.ulong(numif)
|
||||||
|
nif = (*C.perfstat_netinterface_t)(C.malloc(iflen))
|
||||||
|
defer C.free(unsafe.Pointer(nif))
|
||||||
|
C.strcpy(&first.name[0], C.CString(C.FIRST_NETINTERFACE))
|
||||||
|
r := C.perfstat_netinterface(&first, nif, C.sizeof_perfstat_netinterface_t, numif)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_netinterface() error")
|
||||||
|
}
|
||||||
|
ifs := make([]NetIface, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
b := C.get_netinterface_stat(nif, C.int(i))
|
||||||
|
if b != nil {
|
||||||
|
ifs[i] = perfstatnetinterface2netiface(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ifs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NetAdapterStat() ([]NetAdapter, error) {
|
||||||
|
var adapters *C.perfstat_netadapter_t
|
||||||
|
var first C.perfstat_id_t
|
||||||
|
|
||||||
|
numad := C.perfstat_netadapter(nil, nil, C.sizeof_perfstat_netadapter_t, 0)
|
||||||
|
if numad < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_netadater() error")
|
||||||
|
}
|
||||||
|
if numad == 0 {
|
||||||
|
return []NetAdapter{}, fmt.Errorf("no network adapters found")
|
||||||
|
}
|
||||||
|
|
||||||
|
adplen := C.sizeof_perfstat_netadapter_t * C.ulong(numad)
|
||||||
|
adapters = (*C.perfstat_netadapter_t)(C.malloc(adplen))
|
||||||
|
defer C.free(unsafe.Pointer(adapters))
|
||||||
|
C.strcpy(&first.name[0], C.CString(C.FIRST_NETINTERFACE))
|
||||||
|
r := C.perfstat_netadapter(&first, adapters, C.sizeof_perfstat_netadapter_t, numad)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_netadapter() error")
|
||||||
|
}
|
||||||
|
ads := make([]NetAdapter, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
b := C.get_netadapter_stat(adapters, C.int(i))
|
||||||
|
if b != nil {
|
||||||
|
ads[i] = perfstatnetadapter2netadapter(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ads, nil
|
||||||
|
}
|
||||||
76
vendor/github.com/power-devops/perfstat/procstat.go
generated
vendored
Normal file
76
vendor/github.com/power-devops/perfstat/procstat.go
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lperfstat
|
||||||
|
|
||||||
|
#include <libperfstat.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "c_helpers.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ProcessStat() ([]Process, error) {
|
||||||
|
var proc *C.perfstat_process_t
|
||||||
|
var first C.perfstat_id_t
|
||||||
|
|
||||||
|
numproc := C.perfstat_process(nil, nil, C.sizeof_perfstat_process_t, 0)
|
||||||
|
if numproc < 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_process() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
plen := C.sizeof_perfstat_process_t * C.ulong(numproc)
|
||||||
|
proc = (*C.perfstat_process_t)(C.malloc(plen))
|
||||||
|
defer C.free(unsafe.Pointer(proc))
|
||||||
|
C.strcpy(&first.name[0], C.CString(""))
|
||||||
|
r := C.perfstat_process(&first, proc, C.sizeof_perfstat_process_t, numproc)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_process() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
ps := make([]Process, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
p := C.get_process_stat(proc, C.int(i))
|
||||||
|
if p != nil {
|
||||||
|
ps[i] = perfstatprocess2process(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ps, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ThreadStat() ([]Thread, error) {
|
||||||
|
var thread *C.perfstat_thread_t
|
||||||
|
var first C.perfstat_id_t
|
||||||
|
|
||||||
|
numthr := C.perfstat_thread(nil, nil, C.sizeof_perfstat_thread_t, 0)
|
||||||
|
if numthr < 1 {
|
||||||
|
return nil, fmt.Errorf("perfstat_thread() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
thlen := C.sizeof_perfstat_thread_t * C.ulong(numthr)
|
||||||
|
thread = (*C.perfstat_thread_t)(C.malloc(thlen))
|
||||||
|
defer C.free(unsafe.Pointer(thread))
|
||||||
|
C.strcpy(&first.name[0], C.CString(""))
|
||||||
|
r := C.perfstat_thread(&first, thread, C.sizeof_perfstat_thread_t, numthr)
|
||||||
|
if r < 0 {
|
||||||
|
return nil, fmt.Errorf("perfstat_thread() error")
|
||||||
|
}
|
||||||
|
|
||||||
|
th := make([]Thread, r)
|
||||||
|
for i := 0; i < int(r); i++ {
|
||||||
|
t := C.get_thread_stat(thread, C.int(i))
|
||||||
|
if t != nil {
|
||||||
|
th[i] = perfstatthread2thread(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return th, nil
|
||||||
|
}
|
||||||
196
vendor/github.com/power-devops/perfstat/sysconf.go
generated
vendored
Normal file
196
vendor/github.com/power-devops/perfstat/sysconf.go
generated
vendored
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
//go:build aix
|
||||||
|
// +build aix
|
||||||
|
|
||||||
|
package perfstat
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <unistd.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
const (
|
||||||
|
SC_ARG_MAX = 0
|
||||||
|
SC_CHILD_MAX = 1
|
||||||
|
SC_CLK_TCK = 2
|
||||||
|
SC_NGROUPS_MAX = 3
|
||||||
|
SC_OPEN_MAX = 4
|
||||||
|
SC_STREAM_MAX = 5
|
||||||
|
SC_TZNAME_MAX = 6
|
||||||
|
SC_JOB_CONTROL = 7
|
||||||
|
SC_SAVED_IDS = 8
|
||||||
|
SC_VERSION = 9
|
||||||
|
SC_POSIX_ARG_MAX = 10
|
||||||
|
SC_POSIX_CHILD_MAX = 11
|
||||||
|
SC_POSIX_LINK_MAX = 12
|
||||||
|
SC_POSIX_MAX_CANON = 13
|
||||||
|
SC_POSIX_MAX_INPUT = 14
|
||||||
|
SC_POSIX_NAME_MAX = 15
|
||||||
|
SC_POSIX_NGROUPS_MAX = 16
|
||||||
|
SC_POSIX_OPEN_MAX = 17
|
||||||
|
SC_POSIX_PATH_MAX = 18
|
||||||
|
SC_POSIX_PIPE_BUF = 19
|
||||||
|
SC_POSIX_SSIZE_MAX = 20
|
||||||
|
SC_POSIX_STREAM_MAX = 21
|
||||||
|
SC_POSIX_TZNAME_MAX = 22
|
||||||
|
SC_BC_BASE_MAX = 23
|
||||||
|
SC_BC_DIM_MAX = 24
|
||||||
|
SC_BC_SCALE_MAX = 25
|
||||||
|
SC_BC_STRING_MAX = 26
|
||||||
|
SC_EQUIV_CLASS_MAX = 27
|
||||||
|
SC_EXPR_NEST_MAX = 28
|
||||||
|
SC_LINE_MAX = 29
|
||||||
|
SC_RE_DUP_MAX = 30
|
||||||
|
SC_2_VERSION = 31
|
||||||
|
SC_2_C_DEV = 32
|
||||||
|
SC_2_FORT_DEV = 33
|
||||||
|
SC_2_FORT_RUN = 34
|
||||||
|
SC_2_LOCALEDEF = 35
|
||||||
|
SC_2_SW_DEV = 36
|
||||||
|
SC_POSIX2_BC_BASE_MAX = 37
|
||||||
|
SC_POSIX2_BC_DIM_MAX = 38
|
||||||
|
SC_POSIX2_BC_SCALE_MAX = 39
|
||||||
|
SC_POSIX2_BC_STRING_MAX = 40
|
||||||
|
SC_POSIX2_BC_EQUIV_CLASS_MAX = 41
|
||||||
|
SC_POSIX2_BC_EXPR_NEST_MAX = 42
|
||||||
|
SC_POSIX2_BC_LINE_MAX = 43
|
||||||
|
SC_POSIX2_BC_RE_DUP_MAX = 44
|
||||||
|
SC_PASS_MAX = 45
|
||||||
|
SC_XOPEN_VERSION = 46
|
||||||
|
SC_ATEXIT_MAX = 47
|
||||||
|
SC_PAGE_SIZE = 48
|
||||||
|
SC_PAGESIZE = SC_PAGE_SIZE
|
||||||
|
SC_AES_OS_VERSION = 49
|
||||||
|
SC_COLL_WEIGHTS_MAX = 50
|
||||||
|
SC_2_C_WIND = 51
|
||||||
|
SC_2_C_VERSION = 52
|
||||||
|
SC_2_UPE = 53
|
||||||
|
SC_2_CHAR_TERM = 54
|
||||||
|
SC_XOPEN_SHM = 55
|
||||||
|
SC_XOPEN_CRYPT = 56
|
||||||
|
SC_XOPEN_ENH_I18N = 57
|
||||||
|
SC_IOV_MAX = 58
|
||||||
|
SC_THREAD_SAFE_FUNCTIONS = 59
|
||||||
|
SC_THREADS = 60
|
||||||
|
SC_THREAD_ATTR_STACKADDR = 61
|
||||||
|
SC_THREAD_ATTR_STACKSIZE = 62
|
||||||
|
SC_THREAD_FORKALL = 63
|
||||||
|
SC_THREAD_PRIORITY_SCHEDULING = 64
|
||||||
|
SC_THREAD_PRIO_INHERIT = 65
|
||||||
|
SC_THREAD_PRIO_PROTECT = 66
|
||||||
|
SC_THREAD_PROCESS_SHARED = 67
|
||||||
|
SC_THREAD_KEYS_MAX = 68
|
||||||
|
SC_THREAD_DATAKEYS_MAX = SC_THREAD_KEYS_MAX
|
||||||
|
SC_THREAD_STACK_MIN = 69
|
||||||
|
SC_THREAD_THREADS_MAX = 70
|
||||||
|
SC_NPROCESSORS_CONF = 71
|
||||||
|
SC_NPROCESSORS_ONLN = 72
|
||||||
|
SC_XOPEN_UNIX = 73
|
||||||
|
SC_AIO_LISTIO_MAX = 75
|
||||||
|
SC_AIO_MAX = 76
|
||||||
|
SC_AIO_PRIO_DELTA_MAX = 77
|
||||||
|
SC_ASYNCHRONOUS_IO = 78
|
||||||
|
SC_DELAYTIMER_MAX = 79
|
||||||
|
SC_FSYNC = 80
|
||||||
|
SC_GETGR_R_SIZE_MAX = 81
|
||||||
|
SC_GETPW_R_SIZE_MAX = 82
|
||||||
|
SC_LOGIN_NAME_MAX = 83
|
||||||
|
SC_MAPPED_FILES = 84
|
||||||
|
SC_MEMLOCK = 85
|
||||||
|
SC_MEMLOCK_RANGE = 86
|
||||||
|
SC_MEMORY_PROTECTION = 87
|
||||||
|
SC_MESSAGE_PASSING = 88
|
||||||
|
SC_MQ_OPEN_MAX = 89
|
||||||
|
SC_MQ_PRIO_MAX = 90
|
||||||
|
SC_PRIORITIZED_IO = 91
|
||||||
|
SC_PRIORITY_SCHEDULING = 92
|
||||||
|
SC_REALTIME_SIGNALS = 93
|
||||||
|
SC_RTSIG_MAX = 94
|
||||||
|
SC_SEMAPHORES = 95
|
||||||
|
SC_SEM_NSEMS_MAX = 96
|
||||||
|
SC_SEM_VALUE_MAX = 97
|
||||||
|
SC_SHARED_MEMORY_OBJECTS = 98
|
||||||
|
SC_SIGQUEUE_MAX = 99
|
||||||
|
SC_SYNCHRONIZED_IO = 100
|
||||||
|
SC_THREAD_DESTRUCTOR_ITERATIONS = 101
|
||||||
|
SC_TIMERS = 102
|
||||||
|
SC_TIMER_MAX = 103
|
||||||
|
SC_TTY_NAME_MAX = 104
|
||||||
|
SC_XBS5_ILP32_OFF32 = 105
|
||||||
|
SC_XBS5_ILP32_OFFBIG = 106
|
||||||
|
SC_XBS5_LP64_OFF64 = 107
|
||||||
|
SC_XBS5_LPBIG_OFFBIG = 108
|
||||||
|
SC_XOPEN_XCU_VERSION = 109
|
||||||
|
SC_XOPEN_REALTIME = 110
|
||||||
|
SC_XOPEN_REALTIME_THREADS = 111
|
||||||
|
SC_XOPEN_LEGACY = 112
|
||||||
|
SC_REENTRANT_FUNCTIONS = SC_THREAD_SAFE_FUNCTIONS
|
||||||
|
SC_PHYS_PAGES = 113
|
||||||
|
SC_AVPHYS_PAGES = 114
|
||||||
|
SC_LPAR_ENABLED = 115
|
||||||
|
SC_LARGE_PAGESIZE = 116
|
||||||
|
SC_AIX_KERNEL_BITMODE = 117
|
||||||
|
SC_AIX_REALMEM = 118
|
||||||
|
SC_AIX_HARDWARE_BITMODE = 119
|
||||||
|
SC_AIX_MP_CAPABLE = 120
|
||||||
|
SC_V6_ILP32_OFF32 = 121
|
||||||
|
SC_V6_ILP32_OFFBIG = 122
|
||||||
|
SC_V6_LP64_OFF64 = 123
|
||||||
|
SC_V6_LPBIG_OFFBIG = 124
|
||||||
|
SC_XOPEN_STREAMS = 125
|
||||||
|
SC_HOST_NAME_MAX = 126
|
||||||
|
SC_REGEXP = 127
|
||||||
|
SC_SHELL = 128
|
||||||
|
SC_SYMLOOP_MAX = 129
|
||||||
|
SC_ADVISORY_INFO = 130
|
||||||
|
SC_FILE_LOCKING = 131
|
||||||
|
SC_2_PBS = 132
|
||||||
|
SC_2_PBS_ACCOUNTING = 133
|
||||||
|
SC_2_PBS_CHECKPOINT = 134
|
||||||
|
SC_2_PBS_LOCATE = 135
|
||||||
|
SC_2_PBS_MESSAGE = 136
|
||||||
|
SC_2_PBS_TRACK = 137
|
||||||
|
SC_BARRIERS = 138
|
||||||
|
SC_CLOCK_SELECTION = 139
|
||||||
|
SC_CPUTIME = 140
|
||||||
|
SC_MONOTONIC_CLOCK = 141
|
||||||
|
SC_READER_WRITER_LOCKS = 142
|
||||||
|
SC_SPAWN = 143
|
||||||
|
SC_SPIN_LOCKS = 144
|
||||||
|
SC_SPORADIC_SERVER = 145
|
||||||
|
SC_THREAD_CPUTIME = 146
|
||||||
|
SC_THREAD_SPORADIC_SERVER = 147
|
||||||
|
SC_TIMEOUTS = 148
|
||||||
|
SC_TRACE = 149
|
||||||
|
SC_TRACE_EVENT_FILTER = 150
|
||||||
|
SC_TRACE_INHERIT = 151
|
||||||
|
SC_TRACE_LOG = 152
|
||||||
|
SC_TYPED_MEMORY_OBJECTS = 153
|
||||||
|
SC_IPV6 = 154
|
||||||
|
SC_RAW_SOCKETS = 155
|
||||||
|
SC_SS_REPL_MAX = 156
|
||||||
|
SC_TRACE_EVENT_NAME_MAX = 157
|
||||||
|
SC_TRACE_NAME_MAX = 158
|
||||||
|
SC_TRACE_SYS_MAX = 159
|
||||||
|
SC_TRACE_USER_EVENT_MAX = 160
|
||||||
|
SC_AIX_UKEYS = 161
|
||||||
|
SC_AIX_ENHANCED_AFFINITY = 162
|
||||||
|
SC_V7_ILP32_OFF32 = 163
|
||||||
|
SC_V7_ILP32_OFFBIG = 164
|
||||||
|
SC_V7_LP64_OFF64 = 165
|
||||||
|
SC_V7_LPBIG_OFFBIG = 166
|
||||||
|
SC_THREAD_ROBUST_PRIO_INHERIT = 167
|
||||||
|
SC_THREAD_ROBUST_PRIO_PROTECT = 168
|
||||||
|
SC_XOPEN_UUCP = 169
|
||||||
|
SC_XOPEN_ARMOR = 170
|
||||||
|
)
|
||||||
|
|
||||||
|
func Sysconf(name int32) (int64, error) {
|
||||||
|
r := C.sysconf(C.int(name))
|
||||||
|
if r == -1 {
|
||||||
|
return 0, fmt.Errorf("sysconf error")
|
||||||
|
} else {
|
||||||
|
return int64(r), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user