licenses
sequencelengths 1
3
| version
stringclasses 677
values | tree_hash
stringlengths 40
40
| path
stringclasses 1
value | type
stringclasses 2
values | size
stringlengths 2
8
| text
stringlengths 25
67.1M
| package_name
stringlengths 2
41
| repo
stringlengths 33
86
|
---|---|---|---|---|---|---|---|---|
[
"MIT"
] | 0.8.0 | 2e8ff74c4b7ff2c2bacfcfe24c00aadfd3527f95 | code | 8138 | export fem2d, FEM2D, fem2d_solve
" abstract type FEM2D end"
abstract type FEM2D end
" fem2d_solve(::Type{T}=Float64;rest...) where {T} = amg_solve(T;method=FEM2D,rest...)"
fem2d_solve(::Type{T}=Float64;rest...) where {T} = amg_solve(T;method=FEM2D,rest...)
" amg_dim(::Type{FEM2D}) = 2"
amg_dim(::Type{FEM2D}) = 2
" amg_construct(::Type{T},::Type{FEM2D};rest...) where {T} = fem2d(T;rest...)"
amg_construct(::Type{T},::Type{FEM2D};rest...) where {T} = fem2d(T;rest...)
function reference_triangle(::Type{T}) where {T}
K = sparse(T[6 0 0
3 3 0
0 6 0
0 3 3
0 0 6
3 0 3
2 2 2]./6)
w = T[3,8,3,8,3,8,27]./60
dx = sparse(T[ 36 0 0 0 12 -48 0
3 60 -9 12 3 12 -81
-12 48 0 -48 12 0 0
-3 -12 9 -60 -3 -12 81
-12 0 0 0 -36 48 0
12 0 0 0 -12 0 0
4 16 0 -16 -4 0 0]./12)
dy = sparse(T[ 0 48 -12 0 12 -48 0
-9 60 3 12 3 12 -81
0 0 36 -48 12 0 0
0 0 12 0 -12 0 0
0 0 -12 48 -36 0 0
9 -12 -3 -12 -3 -60 81
0 16 4 0 -4 -16 0]./12)
coarsen = sparse([6, 1, 2, 2, 3, 4, 4, 5, 6, 2, 4, 6, 7], [1, 3, 5, 8, 10, 12, 15, 17, 19, 22, 24, 26, 28], T[1, 3, 1, 1, 3, 1, 1, 3, 1, 1, 1, 1, 3]./3, 7, 28)
refine = sparse([2, 3, 4, 6, 7, 9, 13, 14, 18, 20, 21, 23, 25, 27, 4, 5, 6, 7, 8, 9, 13, 14, 20, 21, 22, 23, 25, 27, 4, 6, 7, 9, 10, 11, 13, 14, 16, 20, 21, 23, 25, 27, 6, 7, 11, 12, 13, 14, 15, 16, 20, 21, 23, 24, 25, 27, 2, 6, 7, 11, 13, 14, 16, 17, 18, 20, 21, 23, 25, 27, 1, 2, 6, 7, 13, 14, 18, 19, 20, 21, 23, 25, 26, 27, 6, 7, 13, 14, 20, 21, 23, 25, 27, 28], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7], T[243, 648, 243, 61, 180, -81, -20, -36, -81, -20, -36, -20, -20, 61, 486, 648, 80, 144, 648, 486, 80, 144, -82, -72, 648, 80, -82, 80, -81, -20, -36, 243, 648, 243, 61, 180, -81, -20, -36, 61, -20, -20, -82, -72, 486, 648, 80, 144, 648, 486, 80, 144, 80, 648, 80, -82, -81, -20, -36, -81, -20, -36, 243, 648, 243, 61, 180, -20, 61, -20, 648, 486, 80, 144, -82, -72, 486, 648, 80, 144, -82, 80, 648, 80, 549, 324, 549, 324, 549, 324, 549, 549, 549, 648]./648, 28, 7)
return (K=K,w=w,dx=dx,dy=dy,coarsen=coarsen,refine=refine)
end
function continuous(x::Matrix{T};
tol=maximum(abs.(x))*10*eps(T)) where {T}
n = size(x)[1]
a = 1
u = randn(T,2)
u = u/norm(u)
p = x*u
P = sortperm(p)
labels = zeros(Int,n)
count = 0
while a<=n
if labels[P[a]]==0
count += 1
labels[P[a]] = count
b = a+1
while b<=n && p[P[b]]<=p[P[a]]+tol
b+=1
end
for k=a+1:b-1
if norm(x[P[a],:]-x[P[k],:])<=tol
labels[P[k]] = count
x[P[k],:] = x[P[a],:]
end
end
end
a+=1
end
t = reshape(labels,(7,:))
e = hcat(t[1:2,:],t[2:3,:],t[3:4,:],t[4:5,:],t[5:6,:],t[[6,1],:])'
e = sort(e,dims=2)
P = sortperm(1:size(e,1),lt=(j,k)->e[j,:]<e[k,:])
w = e[P,:]
J = cumsum(vcat(1,(w[1:end-1,1].!=w[2:end,1]) .|| (w[1:end-1,2].!=w[2:end,2])))
J = J[invperm(P)]
ne = maximum(J)
ec = zeros(Int,ne)
for k=1:length(J)
ec[J[k]] += 1
end
idx = findall(ec[J] .== 1)
e = e[idx,:]
boundary = unique(reshape(e,(length(e),)))
interior = setdiff(1:count,boundary)
C = sparse(1:n,labels,ones(T,n),n,count)
# W = spdiagm(0=>1 ./ reshape(sum(C,dims=(1,)),(count,)))
# C = C*W
C[:,interior]
end
"""
function fem2d(::Type{T}, L::Int, K::Matrix{T};
state_variables = [:u :dirichlet
:s :full],
D = [:u :id
:u :dx
:u :dy
:s :id],
generate_feasibility=true) where {T}
Construct an `AMG` object for a 2d finite element grid on the domain `K` with piecewise quadratic elements.
Parameters are:
* `K`: a triangular mesh. If there are `n` triangles, then `K` should be a 3n by 2 matrix of vertices. The first column of `K` represents `x` coordinates, the second column represents `y` coordinates.
* `L`: divide the interval into 2^L subintervals (L for Levels).
* `state_variables`: the "state vector" consists of functions, by default this is `u(x)` and `s(x)`, on the finite element grid.
* `D`: the set of differential operator. The barrier function `F` will eventually be called with the parameters `F(x,y,Dz)`, where `z` is the state vector. By default, this results in `F(x,y,u,ux,uy,s)`, where `(ux,uy)` is the gradient of `u`.
* `generate_feasibility`: if `true`, returns a pair `M` of `AMG` objects. `M[1]` is the `AMG` object for the main problem, and `M[2]` is for the feasibility subproblem.
"""
function fem2d(::Type{T}=Float64; L::Int=2, n=nothing,
K=T[-1 -1;1 -1;-1 1;1 -1;1 1;-1 1],
state_variables = [:u :dirichlet
:s :full],
D = [:u :id
:u :dx
:u :dy
:s :id],
generate_feasibility=true) where {T}
K = if isnothing(K) T[-1 -1;1 -1;-1 1;1 -1;1 1;-1 1] else K end
R = reference_triangle(T)
x = Array{Array{T,2},1}(undef,(L,))
nn = Int(size(K,1)/3)
x[1] = blockdiag([R.K for k=1:nn]...)*K
dirichlet = Array{SparseMatrixCSC{T,Int},1}(undef,(L,))
full = Array{SparseMatrixCSC{T,Int},1}(undef,(L,))
uniform = Array{SparseMatrixCSC{T,Int},1}(undef,(L,))
refine = Array{SparseMatrixCSC{T,Int},1}(undef,(L,))
coarsen = Array{SparseMatrixCSC{T,Int},1}(undef,(L,))
for l=1:L-1
refine[l] = blockdiag([R.refine for k=1:nn*4^(l-1)]...)
coarsen[l] = blockdiag([R.coarsen for k=1:nn*4^(l-1)]...)
x[l+1] = refine[l]*x[l]
end
n = size(x[L])[1]
id = spdiagm(0=>ones(T,n))
N = Int(n/7)
dx = Array{SparseMatrixCSC{T,Int},1}(undef,(N,))
dy = Array{SparseMatrixCSC{T,Int},1}(undef,(N,))
w = Array{Vector{T},1}(undef,(N,))
xL = reshape(x[L]',(2,7,N))
for k=1:N
u = xL[:,1,k]-xL[:,5,k]
v = xL[:,3,k]-xL[:,5,k]
A = hcat(u,v)
invA = inv(A)'
dx[k] = invA[1,1]*R.dx+invA[1,2]*R.dy
dy[k] = invA[2,1]*R.dx+invA[2,2]*R.dy
w[k] = abs(det(A))*R.w
end
dx = blockdiag(dx...)
dy = blockdiag(dy...)
w = vcat(w...)
refine[L] = id
coarsen[L] = id
for l=1:L
dirichlet[l] = continuous(x[l])
full[l] = spdiagm(0=>ones(T,size(x[l],1)))
uniform[l] = sparse(ones(T,(N,1)))
end
subspaces = Dict(:dirichlet => dirichlet, :full => full, :uniform => uniform)
operators = Dict(:id => id, :dx => dx, :dy => dy)
return amg(FEM2D,x=x[L],w=w,state_variables=state_variables,
D=D,subspaces=subspaces,operators=operators,refine=refine,coarsen=coarsen,
generate_feasibility=generate_feasibility)
end
"""
function amg_plot(M::AMG{T, Mat,FEM2D}, z::Array{T}) where {T,Mat}
Plot a piecewise quadratic (plus cubic "bubble") solution `z` on the given mesh. Note that the solution is drawn as (linear) triangles, even though the underlying solution is piecewise cubic. To obtain a more accurate depiction, especially when the mesh is coarse, it would be preferable to apply a few levels of additional subdivision, so as to capture the curve of the quadratic basis functions.
"""
function amg_plot(M::AMG{T, Mat,FEM2D}, z::Array{T}) where {T,Mat}
x = M.x[:,1]
y = M.x[:,2]
S = [1 2 7
2 3 7
3 4 7
4 5 7
5 6 7
6 1 7]
N = Int(size(x,1)/7)
S = vcat([S.+(7*k) for k=0:N-1]...)
plot_trisurf(x,y,z,triangles=S .- 1)
end
| MultiGridBarrier | https://github.com/sloisel/MultiGridBarrier.jl.git |
|
[
"MIT"
] | 0.8.0 | 2e8ff74c4b7ff2c2bacfcfe24c00aadfd3527f95 | code | 5996 | export spectral1d, SPECTRAL1D, spectral1d_solve
" abstract type SPECTRAL1D end"
abstract type SPECTRAL1D end
" amg_dim(::Type{SPECTRAL1D}) = 1"
amg_dim(::Type{SPECTRAL1D}) = 1
" amg_construct(::Type{T},::Type{SPECTRAL1D};rest...) where {T} = spectral1d(T;rest...)"
amg_construct(::Type{T},::Type{SPECTRAL1D};rest...) where {T} = spectral1d(T;rest...)
" spectral1d_solve(::Type{T}=Float64;rest...) where {T} = amg_solve(T;method=SPECTRAL1D,rest...)"
spectral1d_solve(::Type{T}=Float64;rest...) where {T} = amg_solve(T;method=SPECTRAL1D,rest...)
function chebfun(c::Array{T,2}, x::T) where {T}
n = size(c,1)-1
m = size(c,2)
if x>1
return c'*cosh.((0:n).*acosh(x))
elseif x>=-1
return c'*cos.((0:n).*acos(x))
end
s = ones(T,n)
s[2:2:n] .= T(-1)
return c'*(s.*cosh.((0:n).*acosh(-x)))
end
function chebfun(c::Array{T}, x::Array{T}) where {T}
sc = size(c)
sx = size(x)
c = reshape(c,(sc[1],:))
m = size(c,2)
n = prod(sx)
x = reshape(x,n)
y = zeros(T,n,m)
for k=1:n
y[k,:] = chebfun(c,x[k])
end
if length(sc)==1
return reshape(y,sx)
end
return reshape(y,(sx...,sc[2:end]...))
end
chebfun(c::Array{T,1}, x::T) where {T} = chebfun(c,[x])[1]
function derivative(::Type{T},n::Integer) where {T}
D = zeros(T,(n,n))
for j=1:n-1
for k=j+1:2:n
D[j,k] = 2*(k-1)
end
end
D[1,:]/=2
D
end
derivative(n::Integer) = derivative(Float64,n)
function evaluation(xs::Array{T},n::Integer) where {T}
m = size(xs,1)
n = n-1
M = zeros(T,(m,n+1))
for j=1:m
x = xs[j]
if x>1
M[j,:] = cosh.((0:n).*acosh(x))
elseif x>=-1
M[j,:] = cos.((0:n).*acos(x))
else
s = ones(T,n+1)
s[2:2:n+1] .= T(-1)
M[j,:] = s.*cosh.((0:n).*acosh(-x))
end
end
M
end
function spectral1d_(::Type{T}, n::Integer;
state_variables = [:u :dirichlet
:s :full],
D = [:u :id
:u :dx
:s :id],
generate_feasibility=true) where {T}
L = Int(ceil(log2(n)))
ls = [min(n,2^k) for k=1:L]
x = Array{Array{T,2},1}(undef,(L,))
w = 0
dirichlet = Array{Array{T,2},1}(undef,(L,))
full = Array{Array{T,2},1}(undef,(L,))
uniform = Array{Array{T,2},1}(undef,(L,))
refine = Array{Array{T,2},1}(undef,(L,))
coarsen = Array{Array{T,2},1}(undef,(L,))
M = "hi"
for l=1:L
Q = ClenshawCurtisQuadrature(T,ls[l])
nodes,weights = Q.nodes,Q.weights
# nodes,weights = gausslegendre(T,ls[l])
w = 2 .* weights
x[l] = reshape(2 .* nodes .- 1,(length(w),1))
M = evaluation(x[l],ls[l])
@assert size(M,1)==size(M,2)
CI = M[:,3:end]
for k=1:2:size(CI,2)
CI[:,k] -= M[:,1]
end
for k=2:2:size(CI,2)
CI[:,k] -= M[:,2]
end
dirichlet[l] = CI
full[l] = M
uniform[l] = ones(T,(size(x[l],1),1))
end
D0 = derivative(T,ls[L])
@assert size(D0,1)==size(D0,2)
dx = M*D0/M
id = Matrix{T}(I,ls[L],ls[L])
refine[L] = id
coarsen[L] = id
for l=1:L-1
refine[l] = evaluation(x[l+1],ls[l])/full[l]
coarsen[l] = evaluation(x[l],ls[l+1])/full[l+1]
end
subspaces = Dict{Symbol,Array{Array{T,2},1}}(:dirichlet => dirichlet, :full => full, :uniform => uniform)
operators = Dict{Symbol,Array{T,2}}(:id => id, :dx => dx)
return (x=x[L],w=w,state_variables=state_variables,
D=D,subspaces=subspaces,operators=operators,refine=refine,coarsen=coarsen,
generate_feasibility=generate_feasibility)
end
"""
function spectral1d(::Type{T}=Float64; n::Integer=5,
state_variables = [:u :dirichlet
:s :full],
D = [:u :id
:u :dx
:s :id],
generate_feasibility=true) where {T}
Construct an `AlgebraicMultiGridBarrier.AMG` object for a 1d spectral grid of polynomials of degree `n-1`. See also `fem1d` for a description of the parameters `state_variables` and `D`.
"""
function spectral1d(::Type{T}=Float64; n=nothing, L::Integer=2,
K=nothing,
state_variables = [:u :dirichlet
:s :full],
D = [:u :id
:u :dx
:s :id],
generate_feasibility=true) where {T}
n = if isnothing(n) 2^L else n end
return amg(SPECTRAL1D;spectral1d_(T,n,state_variables=state_variables,D=D,generate_feasibility=generate_feasibility)...)
end
"""
function spectral1d_interp(MM::AMG{T,Mat,SPECTRAL1D}, y::Array{T,1},x) where {T,Mat}
A function to interpolate a solution `y` at some point(s) `x`.
* `MM` the mesh of the solution.
* `y` the solution.
* `x` point(s) at which the solution should be evaluated.
"""
function spectral1d_interp(MM::AMG{T,Mat,SPECTRAL1D}, y::Array{T,1},x) where {T,Mat}
n = length(MM.w)
M = evaluation(MM.x,n)
m1 = size(M,1)
@assert m1==size(M,2)
sz = size(y)
y1 = reshape(y,(m1,:))
z = chebfun(M\y1,x)
if length(sz)==1
ret = z
else
ret = reshape(z,(size(x)...,sz[2:end]...))
end
ret
end
"""
function amg_plot(M::AMG{T,Mat,SPECTRAL1D},y;x=Array(-1:T(0.01):1),rest...) where {T,Mat}
Plot a solution using `pyplot`.
* `M`: a mesh.
* `x`: x values where the solution should be evaluated and plotted.
* `y`: the solution, to be interpolated at the given `x` values via `spectral1d_interp`.
* `rest...` parameters are passed directly to `pyplot.plot`.
"""
function amg_plot(M::AMG{T,Mat,SPECTRAL1D},y;x=Array(-1:T(0.01):1),rest...) where {T,Mat}
plot(Float64.(x),Float64.(spectral1d_interp(M,y,x)),rest...)
end
| MultiGridBarrier | https://github.com/sloisel/MultiGridBarrier.jl.git |
|
[
"MIT"
] | 0.8.0 | 2e8ff74c4b7ff2c2bacfcfe24c00aadfd3527f95 | code | 4928 | export spectral2d, SPECTRAL2D, spectral2d_solve
" abstract type SPECTRAL2D end"
abstract type SPECTRAL2D end
" spectral2d_solve(::Type{T}=Float64;rest...) where {T} = amg_solve(T;method=SPECTRAL2D,rest...)"
spectral2d_solve(::Type{T}=Float64;rest...) where {T} = amg_solve(T;method=SPECTRAL2D,rest...)
" amg_dim(::Type{SPECTRAL2D}) = 2"
amg_dim(::Type{SPECTRAL2D}) = 2
" amg_construct(::Type{T},::Type{SPECTRAL2D},L,n,K) where {T} = spectral2d(T,n=n,L=L)"
amg_construct(::Type{T},::Type{SPECTRAL2D};rest...) where {T} = spectral2d(T;rest...)
"""
function spectral2d(::Type{T}=Float64; n=5::Integer,
state_variables = [:u :dirichlet
:s :full],
D = [:u :id
:u :dx
:u :dy
:s :id],
generate_feasibility=true) where {T}
Construct an `AMG` object for a 2d spectral grid of degree `n-1`. See also `fem2d` for a description of `state_variables` and `D`.
"""
function spectral2d(::Type{T}=Float64; n=nothing,
L::Integer=2,
K=nothing,
state_variables = [:u :dirichlet
:s :full],
D = [:u :id
:u :dx
:u :dy
:s :id],
generate_feasibility=true) where {T}
if isnothing(n)
n = 2^L
end
M = spectral1d_(T,n,state_variables=state_variables,D=D)
L = Int(ceil(log2(n)))
ls = [min(n,2^k) for k=1:L]
w = M.w
N = length(w)
w = reshape(w,(N,1))
w = w*(w')
w = reshape(w,(N*N,))
dirichlet = Array{Array{T,2},1}(undef,(L,))
full = Array{Array{T,2},1}(undef,(L,))
uniform = Array{Array{T,2},1}(undef,(L,))
refine = Array{Array{T,2},1}(undef,(L,))
coarsen = Array{Array{T,2},1}(undef,(L,))
for l=1:L
S = M.subspaces
dirichlet[l] = kron(S[:dirichlet][l],S[:dirichlet][l])
full[l] = kron(S[:full][l],S[:full][l])
uniform[l] = kron(S[:uniform][l],S[:uniform][l])
refine[l] = kron(M.refine[l],M.refine[l])
coarsen[l] = kron(M.coarsen[l],M.coarsen[l])
end
xl = M.x
N = size(xl)[1]
y = reshape(repeat(xl,outer=(1,N)),(N*N,1))
z = reshape(repeat(xl,outer=(1,N))',(N*N,1))
x = hcat(y,z)
ID = M.operators[:id]
DX = M.operators[:dx]
id = kron(ID,ID)
dx = kron(DX,ID)
dy = kron(ID,DX)
subspaces = Dict{Symbol,Array{Array{T,2},1}}(:dirichlet => dirichlet, :full => full, :uniform=>uniform)
operators = Dict{Symbol,Array{T,2}}(:id => id, :dx => dx, :dy => dy)
return amg(SPECTRAL2D,x=x,w=w,state_variables=state_variables,
D=D,subspaces=subspaces,operators=operators,refine=refine,coarsen=coarsen,
generate_feasibility=generate_feasibility)
end
"""
function spectral2d_interp(MM::AMG{T,Mat,SPECTRAL2D},z::Array{T,1},x::Array{T,2}) where {T,Mat}
Interpolate a solution `z` at point(s) `x`, given the mesh `MM`. See also
`spectral1d_interp`.
"""
function spectral2d_interp(MM::AMG{T,Mat,SPECTRAL2D},z::Array{T,1},x::Array{T,2}) where {T,Mat}
# n = MM.n
# M = spectralmesh(T,n)
m1 = Int(sqrt(size(MM.x,1)))
M = spectral1d(T, n=m1)
Z0 = zeros(T,m1)
function interp0(z::Array{T,1},x::T,y::T)
ZW = reshape(z,(m1,m1))
for k=1:m1
Z0[k] = spectral1d_interp(M[1],ZW[:,k],x)[1]
end
spectral1d_interp(M[1],Z0,y)[1]
end
function interp1(z::Array{T,1},x::T,y::T)
ZZ = reshape(z,(m1*m1,:))
ret1 = zeros(T,size(ZZ,2))
for k1=1:size(ZZ,2)
ret1[k1] = interp0(ZZ[:,k1],x,y)
end
ret1
end
function interp(z::Array{T,1},x::Array{T,2})
m = Int(size(z,1)/(m1*m1))
ret2 = zeros(T,(size(x,1),m))
for k2=1:size(x,1)
foo = interp1(z,x[k2,1],x[k2,2])
ret2[k2,:] = foo
end
ret2[:]
end
interp(z,x)
end
"""
function amg_plot(M::AMG{T,Mat,SPECTRAL2D},z::Array{T,1};x=-1:T(0.01):1,y=-1:T(0.01):1,rest...) where {T,Mat}
Plot a 2d solution.
* `M` a 2d mesh.
* `x`, `y` should be ranges like -1:0.01:1.
* `z` the solution to plot.
"""
function amg_plot(M::AMG{T,Mat,SPECTRAL2D},z::Array{T,1};x=-1:T(0.01):1,y=-1:T(0.01):1,rest...) where {T,Mat}
X = repeat(x,1,length(y))
Y = repeat(y,1,length(x))'
sz = (length(x),length(y))
Z = reshape(spectral2d_interp(M,z,hcat(X[:],Y[:])),(length(x),length(y)))
gcf().add_subplot(projection="3d")
dx = maximum(x)-minimum(x)
dy = maximum(y)-minimum(y)
lw = max(dx,dy)*0.002
plot_surface(Float64.(x), Float64.(y), Float64.(Z); rcount=50, ccount=50, antialiased=false, edgecolor=:black, linewidth=Float64(lw), rest...)
# plot_wireframe(x,y,Z; rcount=10, ccount=10, color=:white, edgecolor=:black)
end
| MultiGridBarrier | https://github.com/sloisel/MultiGridBarrier.jl.git |
|
[
"MIT"
] | 0.8.0 | 2e8ff74c4b7ff2c2bacfcfe24c00aadfd3527f95 | code | 2189 | using MultiGridBarrier
using Test
using LinearAlgebra
Base.show(x, ::MIME{Symbol("text/html")}, ::String) = nothing
@testset "MultiGridBarrier.jl" begin
z = reshape(Float64[-1,-1,-1,1,0,0,2,2],(:,2))
@test norm(fem1d_solve(L=1,p=1.0)-z)<1e-6
z = reshape([2.0,1.0,2.0,1.0,2.0,1.0,0.9629629615502254,2.0,1.0,2.0,1.0,2.0,1.0,0.9629629615502254,2.8284271303696036,0.0,2.0,0.0,2.0,0.0,0.0,2.0,0.0,2.8284271303696036,0.0,2.0,0.0,0.0],(:,2))
@test norm(fem2d_solve(L=1,p=1.0)-z)<1e-6
z = reshape([-1.0,-0.9937184291481691,-1.0606601198186663,-0.28661158923558694,1.0,5.3340857286533046e-8,6.270131188059596e-8,1.0297480733710706e-7,2.999999898325467,5.999999681130596],(:,2))
@test norm(spectral1d_solve(n=5,p=1.0)-z)<1e-6
z = reshape([2.0,1.5,1.0,1.5,2.0,1.5,1.3293564567737008,1.000000018263945,1.3293564567737008,1.5,1.0,1.000000018263945,0.9999999999999992,1.000000018263945,1.0,1.5,1.3293564567737008,1.000000018263945,1.3293564567737006,1.5,2.0,1.5,1.0,1.5,2.0,2.8284271380814046,1.4605935026827006,1.6292452074881896e-7,1.460593502682701,2.8284271380814046,1.4605935026827004,0.9999999768073243,5.33408572865331e-8,0.9999999768073249,1.4605935026827008,1.6292452092368193e-7,5.33408572865331e-8,5.3340857286533106e-8,5.33408572865331e-8,1.6292452052399464e-7,1.4605935026827006,0.9999999768073246,5.334085728653312e-8,0.9999999768073247,1.460593502682701,2.8284271380814046,1.4605935026827008,1.6292452069885802e-7,1.4605935026827015,2.8284271380814046],(:,2))
@test norm(spectral2d_solve(n=5,p=1.0)-z)<1e-6
z = [-1.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0; 1.0 0.0 0.0;;; -1.0 1.0000000112468264 0.7500000142459804; -0.24999999700084627 0.06250000974724965 0.7500000142459804; -0.24999999700084627 0.06250000974724965 1.2500000082476728; 1.0 1.0000000112468264 1.2500000082476728;;; -1.0 1.00000002 0.5000000363324867; -0.4999999836675137 0.2500000036675139 0.5000000363324867; -0.4999999836675137 0.2500000036675139 1.5000000036675138; 1.0 1.00000002 1.5000000036675138]
@test norm(parabolic_solve(method=FEM1D,L=1,h=0.5,p=1.0)-z)<1e-6
@test (MultiGridBarrier.amg_precompile(); true)
@test (MultiGridBarrier.parabolic_precompile(); true)
end
| MultiGridBarrier | https://github.com/sloisel/MultiGridBarrier.jl.git |
|
[
"MIT"
] | 0.8.0 | 2e8ff74c4b7ff2c2bacfcfe24c00aadfd3527f95 | docs | 907 | # MultiGridBarrier
# Author: Sébastien Loisel
[](https://sloisel.github.io/MultiGridBarrier.jl/stable/)
[](https://sloisel.github.io/MultiGridBarrier.jl/dev/)
[](https://github.com/sloisel/MultiGridBarrier.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://codecov.io/gh/sloisel/MultiGridBarrier.jl)
This package solves convex variational problems, e.g. nonlinear PDEs and BVPs, using the MultiGrid Barrier method (with either finite elements or spectral elements), which is theoretically optimal for some problem classes.
See the documentation for more information and examples.
| MultiGridBarrier | https://github.com/sloisel/MultiGridBarrier.jl.git |
|
[
"MIT"
] | 0.8.0 | 2e8ff74c4b7ff2c2bacfcfe24c00aadfd3527f95 | docs | 1912 | ```@meta
CurrentModule = MultiGridBarrier
```
```@eval
using Markdown
using Pkg
using MultiGridBarrier
v = string(pkgversion(MultiGridBarrier))
md"# MultiGridBarrier $v"
```
[MultiGridBarrier](https://github.com/sloisel/MultiGridBarrier.jl) is a Julia module for solving nonlinear convex optimization problems in function spaces, such as p-Laplace problems. When regularity conditions are satisfied, the solvers are quasi-optimal.
The `MultiGridBarrier` module features finite element and spectral discretizations in 1d and 2d.
## Finite elements
After installing `MultiGridBarrier` with the Julia package manager, in a Jupyter notebook, one solves a 1d p-Laplace problem as follows:
```@example 1
using PyPlot # hide
using MultiGridBarrier
fem1d_solve(L=5,p=1.0,verbose=false);
savefig("fem1d.svg"); nothing # hide
close() #hide
```

A 2d p-Laplace problem:
```@example 1
fem2d_solve(L=3,p=1.0,verbose=false);
savefig("fem2d.svg"); nothing # hide
close() #hide
```

## Spectral elements
Solve a 1d p-Laplace problem as follows:
```@example 1
spectral1d_solve(n=40,p=1.0,verbose=false);
savefig("spectral1d.svg"); nothing # hide
close() #hide
```

A 2d p-Laplace problem:
```@example 1
spectral2d_solve(n=5,p=1.5,verbose=false);
savefig("spectral2d.svg"); nothing # hide
close() #hide
```

## Parabolic problems
A time-dependent problem:
```@example 1
parabolic_solve(h=0.1,L=3,printer=anim->anim.save("parabolic.mp4"),verbose=false);
close() #hide
```
```@raw html
<video src="parabolic.mp4" width="600" controls autoplay loop></video>
```
# Module reference
```@autodocs
Modules = [MultiGridBarrier]
Order = [:module]
```
# Types reference
```@autodocs
Modules = [MultiGridBarrier]
Order = [:type]
```
# Functions reference
```@autodocs
Modules = [MultiGridBarrier]
Order = [:function]
```
# Index
```@index
```
| MultiGridBarrier | https://github.com/sloisel/MultiGridBarrier.jl.git |
|
[
"MIT"
] | 0.1.0 | 417689435f51c0ffeac31e372f8bb9fcbfe79cbf | code | 1683 | module Wikidata
using HTTP, JSON
struct WikidataEntity
code::String
dataDict::Dict
end
function WikidataEntity(name::String)
resp = HTTP.get("https://www.wikidata.org/wiki/Special:EntityData/$(name).json")
#resp = HTTP.request("get", "www.google.com")
str = String(resp.body)
jobj = JSON.Parser.parse(str)["entities"][name]
#descriptions = jobj["descriptions"]
WikidataEntity(name, jobj)
end
function label(x::WikidataEntity)
x.dataDict["labels"]["en"]["value"]
end
function hasproperty(x::WikidataEntity, property::String)
return haskey(x.dataDict["claims"], property)
end
"""
returns a list of properties of different type.
Supported properties: item
"""
function getproperty(x::WikidataEntity, property::String)
if (!hasproperty(x, property))
throw(ArgumentError("Entity does not have property $(property)"))
end
propertylist = x.dataDict["claims"][property]
returnlist = Any[]
for p in propertylist
datatype = p["mainsnak"]["datavalue"]["type"]
#item type
if(datatype == "wikibase-entityid")
itemcode = p["mainsnak"]["datavalue"]["value"]["id"]
push!(returnlist, WikidataEntity(itemcode))
#coordinates type
elseif(datatype == "globecoordinate")
latlontuple = (p["mainsnak"]["datavalue"]["value"]["latitude"], p["mainsnak"]["datavalue"]["value"]["longitude"])
push!(returnlist, latlontuple)
end
end
return returnlist
end
end # module
| Wikidata | https://github.com/KimBue/Wikidata.jl.git |
|
[
"MIT"
] | 0.1.0 | 417689435f51c0ffeac31e372f8bb9fcbfe79cbf | code | 798 | using Wikidata
using Test
using HTTP
@testset "Wikidata.jl" begin
entity = Wikidata.WikidataEntity("Q42")
@test Wikidata.label(entity)=="Douglas Adams"
@test_throws HTTP.ExceptionRequest.StatusError Wikidata.WikidataEntity("Douglas Adams")
@test Wikidata.hasproperty(entity, "P31")== true
@test Wikidata.hasproperty(entity, "P38")== false
@test_throws ArgumentError Wikidata.getproperty(entity, "P38")
propList = Wikidata.getproperty(entity, "P31")
@test size(propList, 1) == 1
@test Wikidata.label(propList[1]) == "human"
cambridge = Wikidata.getproperty(entity, "P19")[1]
@test Wikidata.label(cambridge) == "Cambridge"
latlon = Wikidata.getproperty(cambridge, "P625")[1]
@test latlon[1] == 52.208055555556
@test latlon[2] == 0.1225
end
| Wikidata | https://github.com/KimBue/Wikidata.jl.git |
|
[
"MIT"
] | 0.1.0 | 417689435f51c0ffeac31e372f8bb9fcbfe79cbf | docs | 2062 | # Wikidata
[](https://travis-ci.com/KimBue/Wikidata.jl)
[](https://ci.appveyor.com/project/KimBue/Wikidata-jl)
[](https://codecov.io/gh/KimBue/Wikidata.jl)
[](https://coveralls.io/github/KimBue/Wikidata.jl?branch=master)
This is a project to implement a Wikidata Client in Julia. For the moment, I am using this project to get used to Julia.
## Usage
```julia
#load a Wikidata-Entity (Douglas Adams)
adams = Wikidata.WikidataEntity("Q42")
println(Wikidata.label(adams))
#check if place of bith exists for this entity:
if(Wikidata.hasproperty("P31")
placeofbirth = Wikidata.getproperty(adams, "P31")
println(Wikidata.label(placeofbirth)
end
```
## Example
How to extract birthplaces and their coordinates for all presidents (head of governement) of the US (or any other country)
```julia
function getPresidentsBirthPlaces(x::String)
df = DataFrame(Name = String[], birthplace= String[], geb_lat = BigFloat[], geb_lot = BigFloat[])
country = Wikidata.WikidataEntity(x)
#head of government is found under Property P6
presidents_Entities = Wikidata.getproperty(country, "P6")
for president in presidents_Entities
try
#P19 is the place-of-birth property
birthplace_Entity = Wikidata.getproperty(president, "P19")
#P625 is the coordinate location property
birthplace_latlon = Wikidata.getproperty(birthplace_Entity[1], "P625")[1]
push!(df, (Wikidata.label(president), Wikidata.label(birthplace_Entity[1]),birthplace_latlon[1], birthplace_latlon[2]))
catch
println("Data not found")
end
end
df
end
df = getPresidentsBirthPlaces("Q30") #Q30 is the identifier for the US, Q183 is the identifier of Germany etc.
```
| Wikidata | https://github.com/KimBue/Wikidata.jl.git |
|
[
"MIT"
] | 0.0.5 | 072cdf20c9b0507fdd977d7d246d90030609674b | code | 173 | module PlutoHooks
include("./notebook.jl")
export @use_state, @use_effect, @use_memo, @use_ref, @use_deps
export @use_is_pluto_cell, @only_as_script, @skip_as_script
end
| PlutoHooks | https://github.com/JuliaPluto/PlutoHooks.jl.git |
|
[
"MIT"
] | 0.0.5 | 072cdf20c9b0507fdd977d7d246d90030609674b | code | 22798 | ### A Pluto.jl notebook ###
# v0.18.1
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
end
end
# ╔═╡ 49cb409b-e564-47aa-9dae-9bc5bffa991d
using UUIDs
# ╔═╡ 729ae3bb-79c2-4fcd-8645-7e0071365537
md"""
# PlutoHooks.jl
Bring your notebook to life! This is an abstraction based on [React.js Hooks](https://reactjs.org/docs/hooks-intro.html) to implement "react-like" features in [Pluto.jl](https://plutojl.org). It allows cells to carry information and processes between updates, and even update itself.
There is a lot you can do with this, but some examples:
- Run a process and relay it's output to the rest of your notebook.
- Watch a file and reload the content when it changes.
- Do a computation on separate thread while the rest of notebook continue running.
You need to use Pluto version >= 0.17.2.
"""
# ╔═╡ bc0e4219-a40b-46f5-adb2-f164d8a9bbdb
"""
@use_memo(deps::Vector{Any}) do
# Expensive computation/loading
end
Does a computation only when the deps array has changed.
This is useful for heavy computations as well as resource fetches like file reading or fetching from the network.
```julia
# Only read a file once
@use_memo([filename]) do
read(filename)
end
```
```julia
@use_memo([a, b]) do
a + b # But they're like really big numbers
end
```
"""
macro use_memo(f, deps)
quote
ref = @use_ref(nothing)
if @use_did_deps_change($(esc(deps)))
ref[] = $(esc(f))()
end
ref[]
end
end
# ╔═╡ 0f632b57-ea01-482b-b93e-d69f962a6d92
md"""
## Not really hooks but internally very hook-ish
These are all for making sure you have some level of Pluto-ness active. These are made to work outside of Pluto as well, but obviously give you the opposite results :P
"""
# ╔═╡ 8c2e9cad-eb63-4af5-8b52-629e8d3439bd
"""
is_running_in_pluto_process()
This doesn't mean we're in a Pluto cell, e.g. can use @bind and hooks goodies.
It only means PlutoRunner is available (and at a version that technically supports hooks)
"""
function is_running_in_pluto_process()
isdefined(Main, :PlutoRunner) &&
# Also making sure my favorite goodies are present
isdefined(Main.PlutoRunner, :GiveMeCellID) &&
isdefined(Main.PlutoRunner, :GiveMeRerunCellFunction) &&
isdefined(Main.PlutoRunner, :GiveMeRegisterCleanupFunction)
end
# ╔═╡ df0645b5-094a-45b9-b72a-ab7ef9901fa1
"""
is_inside_pluto(mod::Module)
This can be useful to implement the behavior for when the hook is called outside Pluto but in the case where Pluto **can** be loaded.
"""
function is_inside_pluto(mod::Module)
# Note: this could be moved to AbstractPlutoDingejtes
startswith(string(nameof(mod)), "workspace#") &&
isdefined(mod, Symbol("@bind"))
end
# ╔═╡ c82c8aa9-46a9-4110-88af-8638625222e3
"""
@use_ref(initial_value::Any)::Ref{Any}
Creates a Ref that is stable over multiple **implicit** runs of the cell. Implicit run meaning a variable (or a bond) used in this cell is updated, causing this cell to re-run. When you press shift+enter in Pluto however, this ref will reset.
This is useful to keep state around between runs.
"""
macro use_ref(initial_value=nothing)
if !is_inside_pluto(__module__)
ref = Ref{Any}()
return quote
ref = $(ref)
ref[] = $(esc(initial_value))
ref
end
end
ref_ref = Ref(Ref{Any}())
quote
# use_did_deps_change with empty array so it only refreshes
# initially and on cell refresh.
# You might wonder: But Michiel, this already refreshes on cell refresh,
# because the macro will rerun!
# I hear you. But I have bigger plans..... 😈
if @use_did_deps_change([])
$ref_ref[] = Ref{Any}($(esc(initial_value)))
end
$ref_ref[]
end
end
# ╔═╡ 1df0a586-3692-11ec-0171-0b48a4a1c4bd
"""
state, set_state = @use_state(initial_value::Any)
Returns a tuple for an update-able value. `state` will be whatever value you put in, and `set_state` is a function that you can call with a value, and it will set `state` to that value, and re-run the cell. Useful in combination with [`@use_effect`](@ref):
```julia
web_response = let
state, set_state = @use_state(nothing)
@use_effect([]) do
schedule(Task() do
response = HTTP.fetch("idk-what-api-HTTP.jl-has")
set_state(response)
end)
end
state
end
```
Be careful to have your [`@use_effect`](@ref) not rely on `state`, because it will most likely not have a reference to the latest state, but to the `state` at the moment that the [`@use_effect`](@ref) first ran.
To circumvent the most common case where this is a problem, you can pass a function to `set_state` that recieves the previous state as an argument:
```julia
counter = begin
state, set_state = @use_state(0)
@use_effect([]) do
schedule(Task() do
while true
sleep(1)
set_state(function(previous_state)
previous_state + 1
end)
end
end)
# In the real world this should also return a cleanup function,
# More on that in the docs for @use_effect
end
state
end
```
"""
macro use_state(initial_value)
if !is_inside_pluto(__module__)
return quote
($(esc(initial_value)), x -> nothing)
end
end
quote
rerun_cell_fn = @give_me_rerun_cell_function()
state_ref = @use_ref($(esc(initial_value)))
# But there are no deps! True, but this takes care of initialization,
# and the case that @use_deps creates, where we switch the cell_id around.
# if @use_did_deps_change([])
# state_ref[] = $(esc(initial_value))
# end
# TODO Make set_state throw when used after a cell is disposed
# .... (so this would require @use_effect)
# .... Reason I want this is because it will help a bunch in spotting
# .... tasks that don't get killed, stuff like that.
set_state = (new) -> begin
new_value = if hasmethod(new, Tuple{typeof(new)})
new(state_ref[])
else
new
end
state_ref[] = new_value
rerun_cell_fn()
end
(state_ref[], set_state)
end
end
# ╔═╡ cd048a16-37f5-455e-8b6a-c098d5f83b96
"""
@use_deps(deps::Vector) do
# ... others hooks ...
end
Experimental function to wrap a bunch of macros in a fake cell that fully refreshes when the deps provided change. This is useful if you make a macro that wraps a bunch of Pluto Hooks, and you just want to refresh the whole block when something changes. This also clears [`@use_ref`](@ref)'s and [`@use_state`](@ref)'s, even though these don't even have a deps argument.
Not entirely sure how much this is necessary (or if I'm missing something obvious that doesn't make it necessary).
Also, this name does **not** spark joy.
"""
macro use_deps(fn_expr, deps)
if !is_inside_pluto(__module__)
return quote
$(esc(deps))
$(esc(fn_expr))()
end
end
cell_id_ref = Ref{UUID}(uuid4())
quote
if @use_did_deps_change($(esc(deps)))
$cell_id_ref[] = uuid4()
end
with_cell_id($(esc(fn_expr)), $cell_id_ref[])
end
end
# ╔═╡ 89b3f807-2e24-4454-8f4c-b2a98aee571e
"""
@use_effect(deps::Vector{Any}) do
# Side effect
return function()
# Cleanup
end
end
Used to run a side effects that can create long running processes. A good example of this would be a HTTP server, or a task that runs an async process. Maybe it's a veeeery long running HTTP request, possibly a websocket connection to an API. 🌈
Likely to be used with [`@use_state`](@ref), as without it it's kinda useless. You want to get the values you fetch in the `@use_effect` back into the notebook, and that is what `@use_state` is for.
The function returned from `@use_effect` is called whenever the process is supposed to be stopped. This is either when the deps change, the cell is explicitly re-run or the cell is deleted. Make sure you write good cleanup functions! It's often seen as an afterthought, but it can make your notebook experience so much better.
```julia
# Ping me if you have a better real world example that uses deps
# Also don't copy this verbatim, we'll have `@use_task` that is smarter
# with it's cleanup and returns the task state!
@use_effect([log_prefix])
task = schedule(Task() do
while true
sleep(1)
@info "
end
end)
return function()
Base.schedule(task, InterruptException(), error=true)
end
end
```
"""
macro use_effect(f, deps)
if !is_inside_pluto(__module__)
return quote
$(esc(deps))
$(esc(f))()
end
end
# For some reason the `cleanup_ref` using @use_ref or assigned outside the
# `register_cleanup_fn() do ... end` (and not interpolated directly into it)
# is `nothing` when the cleanup function actually ran...
# Honestly, no idea how that works, like... `cleanup_ref[]` can be nothing sure,
# but `cleanup_ref` self can be `nothing`???
cleanup_ref = Ref{Function}(() -> nothing)
quote
cleanup_ref = $(cleanup_ref)
register_cleanup_fn = @give_me_register_cleanup_function()
register_cleanup_fn() do
$(cleanup_ref)[]()
end
if @use_did_deps_change($(esc(deps)))
cleanup_ref[]()
local cleanup_func = $(esc(f))()
if cleanup_func isa Function
cleanup_ref[] = cleanup_func
end
end
nothing
end
end
# ╔═╡ 3f632c14-5f25-4426-8bff-fd315db55db5
export @use_ref, @use_state, @use_memo, @use_effect, @use_deps
# ╔═╡ c461f6da-a252-4cb4-b510-a4df5ab85065
"""
@use_did_deps_change(deps::Vector{Any})
The most base-level `use_xxx` macro that we have, and I hope we can make it so you don't actually need this in your own code. It will, when called with deps, return `true` if the deps imply a refresh.
It will always return `true` when run the first time.
After that it will.
1. `deps=nothing` will return `true`
2. `deps=[]` will return `false`
3. `deps=[something_else...]` will return true when the deps are different than they were before
"""
macro use_did_deps_change(deps)
if !is_inside_pluto(__module__)
return quote
$(esc(deps))
true # Simulates the first run
end
end
# Can't use @use_ref because this is used by @use_ref
initialized_ref = Ref(false)
last_deps_ref = Ref{Any}(nothing)
last_cell_id_ref = Ref{Any}(nothing)
quote
initialized_ref = $(initialized_ref)
last_deps_ref = $(last_deps_ref)
last_cell_id_ref = $(last_cell_id_ref)
current_deps = $(esc(deps))
current_cell_id = @give_me_the_pluto_cell_id()
if initialized_ref[] == false
initialized_ref[] = true
last_deps_ref[] = current_deps
last_cell_id_ref[] = current_cell_id
true
else
# No dependencies? Always re-render!
if current_deps === nothing
true
elseif (
# There is a problem here with either cell_id or one of the deps
# being missing... >_> Not sure what would be good here,
# === would fix missing, but would also make all comparisons strict.
# Explicitly checking for missing... ? 🤮
last_deps_ref[] == current_deps &&
last_cell_id_ref[] == current_cell_id
)
false
else
last_deps_ref[] = current_deps
last_cell_id_ref[] = current_cell_id
true
end
end
end
end
# ╔═╡ 84736507-7ea9-4b4b-9b70-b1e9b4b33cde
md"""
### Until I get the PlutoTest PR out
"""
# ╔═╡ 118991d7-f470-4775-ac44-4638f4989d58
md"""
## PlutoRunner-based internals
These are, I hope, the only parts that need to explicitly reference PlutoRunner.
Each of these inserts a reference to a special PlutoRunner object into the resulting expression, and that special object will be caught by PlutoRunner while evaluating the cell, and replaced with the actual value.
It seems a bit over-engineered, and I guess it is, BUT, this makes it possible to have a very strict sense of what cell is actually running what function. Also it allows other macros (specifically [`@use_deps`](@ref)) to insert it's own values instead of Plutos, thus kinda creating a cell-in-a-cell 😏
"""
# ╔═╡ 405fb702-cf4a-4d34-b8ed-d3258a61256b
const overwritten_cell_id = Ref{Union{Nothing,UUID}}(nothing)
# ╔═╡ 39aa6082-40ca-40c3-a2c0-4b6221edda32
"""
@give_me_the_pluto_cell_id()
> ⚠️ Don't use this directly!! if you think you need it, you might actually need [`@use_did_deps_change([])`](@ref) but even that is unlikely.
Used inside a Pluto cell this will resolve to the current cell UUID.
Outside a Pluto cell it will throw an error.
"""
macro give_me_the_pluto_cell_id()
if is_running_in_pluto_process()
:(something(overwritten_cell_id[], dont_be_pluto_special_value($(Main.PlutoRunner.GiveMeCellID()))))
else
:(throw(NotRunningInPlutoCellException()))
end
end
# ╔═╡ d9d14e60-0c91-4eec-ba28-82cf1ebc115f
"""
@use_is_pluto_cell()
Returns whether or not this expression is running inside a Pluto cell.
This goes further than checking if the process we're running in is started using Pluto, this actually checks if this code is part of the code that gets evaluated within a cell. Meant to be used directly in a Pluto cell, or returned from a macro.
This is nestable, so you can use `@use_is_pluto_cell()` inside your macro own and, as long as that macro is used in a Pluto cell directly, it will return true.
Using this inside a function will return whether or not that function is defined in a Pluto cell. If you then call that function from a script, it will still return true:
```julia
# 49cb409b-e564-47aa-9dae-9bc5bffa991d
function wrong_use_of_use_is_pluto_cell()
return @use_is_pluto_cell()
end
# 49cb409b-e564-47aa-9dae-9bc5bffa991d
# eval circumvents Pluto-ness
eval(quote
@use_is_pluto_cell() // false
wrong_use_of_use_is_pluto_cell() // true
end)
```
"""
macro use_is_pluto_cell()
# Normally you don't need this,
# but for some reason skip_as_script seems to want it still
var"@give_me_the_pluto_cell_id"
give_me_cell_id = is_running_in_pluto_process() ?
Main.PlutoRunner.GiveMeCellID() :
nothing
quote
if (
is_running_in_pluto_process() &&
$(give_me_cell_id) != Main.PlutoRunner.GiveMeCellID()
)
true
else
false
end
end
end
# ╔═╡ cce13aec-7cf0-450c-bc93-bcc4e2a70dfe
"""
@skip_as_script expr
Only run the expression if you're running inside a pluto cell. Small wrapper around [`@use_is_pluto_cell`](@ref).
"""
macro skip_as_script(expr)
var"@use_is_pluto_cell"
quote
if @use_is_pluto_cell()
$(esc(expr))
else
nothing
end
end
end
# ╔═╡ 71963fa5-82f0-4c8d-9368-0d6ba317f59e
# Notice that even though we run it in this cell's module,
# that doesn't count as "being in Pluto" enough.
@skip_as_script let
is_pluto_cell = eval(quote
@use_is_pluto_cell()
end)
if is_pluto_cell
error("❌ eval() thinks it is a Pluto cell! What!!")
else
md"✅ Nice, eval() is indeed not the Pluto cell"
end
end
# ╔═╡ ec74d9b7-b2ff-4758-a305-c3f30509a786
"""
@only_as_script expr
Only run the expression if you're **not** running inside a pluto cell. Small wrapper around [`@use_is_pluto_cell`](@ref).
"""
macro only_as_script(expr)
var"@use_is_pluto_cell"
quote
if @use_is_pluto_cell()
nothing
else
$(esc(expr))
end
end
end
# ╔═╡ 92cfc989-5862-4314-ae1b-9cbfc4b42b40
export @use_is_pluto_cell, @skip_as_script, @only_as_script
# ╔═╡ 014d0172-3425-4429-b8d6-1d195bc60a66
@skip_as_script let
if @use_is_pluto_cell()
md"✅ Nice, we are indeed running in Pluto"
else
error("❌ Uhhhhhh")
end
end
# ╔═╡ 3d2516f8-569e-40e4-b1dd-9f024f9266e4
"""
@give_me_rerun_cell_function()
> ⚠️ Don't use this directly!! if you think you need it, you need [`@use_state`](@ref).
Used inside a Pluto cell this will resolve to a function that, when called, will cause the cell to be re-run (in turn re-running all dependent cells).
Outside a Pluto cell it will throw an error.
"""
macro give_me_rerun_cell_function()
if is_running_in_pluto_process()
:(dont_be_pluto_special_value($(Main.PlutoRunner.GiveMeRerunCellFunction())))
else
:(throw(NotRunningInPlutoCellException()))
end
end
# ╔═╡ cf55239c-526b-48fe-933e-9e8d56161fd6
"""
@give_me_register_cleanup_function()
> ⚠️ Don't use this directly!! if you think you need it, you need [`@use_effect`](@ref).
Used inside a Pluto cell this will resolve to a function that call be called with yet another function, and then will call that function when the cell gets explicitly re-run. ("Explicitly re-run" meaning all `@use_ref`s get cleared, for example).
Outside a Pluto cell it will throw an error.
"""
macro give_me_register_cleanup_function()
if is_running_in_pluto_process()
:(dont_be_pluto_special_value(
$(Main.PlutoRunner.GiveMeRegisterCleanupFunction())
))
else
:(throw(NotRunningInPlutoCellException()))
end
end
# ╔═╡ 86a2f051-c554-4a1c-baee-8d01653c15be
"""
with_cell_id(f, cell_id)
> ⚠️ Don't use this directly!! if you think you need it, you need [`@use_deps`](@ref).
Used inside a cell to get the "proxy" cell id. This could be the real one but also a fake one in case your hook is called from another hook.
"""
function with_cell_id(f::Function, cell_id)
previous_cell_id = overwritten_cell_id[]
overwritten_cell_id[] = cell_id
try
f()
finally
overwritten_cell_id[] = previous_cell_id
nothing
end
end
# ╔═╡ b36e130e-578b-42cb-8e3a-763f6b97108d
md"""
### Very cool small helpers
These are just to make [`@give_me_the_pluto_cell_id`](@ref), [`@give_me_rerun_cell_function`](@ref) and [`@give_me_register_cleanup_function`](@ref) throw whenever you're not in Pluto.
One more reason to not call these directly.
"""
# ╔═╡ ff97bcce-1d29-469e-a4be-5dc902676057
Base.@kwdef struct NotRunningInPlutoCellException <: Exception end
# ╔═╡ 78d28d07-5912-4306-ad95-ad245797889f
function Base.showerror(io::IO, expr::NotRunningInPlutoCellException)
print(io, "NotRunningInPlutoCell: Expected to run in a Pluto cell, but wasn't! We'll try to get these hooks to work transparently when switching from Pluto to a script.. but not yet, so just as a precaution: this error!")
end
# ╔═╡ 1b8d6be4-5ba4-42a8-9276-9ef687a8a7a3
if is_running_in_pluto_process()
function dont_be_pluto_special_value(x::Main.PlutoRunner.SpecialPlutoExprValue)
throw(NotRunningInPlutoCellException())
end
end
# ╔═╡ f168c077-59c7-413b-a0ac-c0fd72781b72
dont_be_pluto_special_value(x::Any) = x
# ╔═╡ 9ec6b9c5-6bc1-4033-ab93-072f783184e9
md"""
### Until I get the PlutoTest PR out
"""
# ╔═╡ fd653af3-be53-4ddd-b69d-3967ef6d588a
md"#### `@give_me_the_pluto_cell_id()`"
# ╔═╡ b25ccaf1-cf46-4eea-a4d9-16c68cf56fad
@skip_as_script try
eval(quote
@give_me_the_pluto_cell_id()
end)
error("❌ This should throw a NotRunningInPlutoCellException.. but didn't!")
catch e
if e isa NotRunningInPlutoCellException
md"✅ Nice, we got an exception like we should"
else
rethrow(e)
end
end
# ╔═╡ e5905d1e-33ec-47fb-9f98-ead82eb03be8
@skip_as_script begin
cell_id = @give_me_the_pluto_cell_id()
if cell_id isa UUID
md"✅ Nice, we got the cell UUID"
else
error("❌ What the? Got a typeof($(typeof(cell_id)))")
end
end
# ╔═╡ 274c2be6-6075-45cf-b28a-862c8bf64bd4
md"""
## Examples/Experiments
Ideally, these functions would be in their own package (so they can update without PlutoHooks updating), but for now we keep them here to show of and test the stuff above.
"""
# ╔═╡ 90f051be-4384-4383-9a56-2aa584687dc3
macro use_reducer(fn, deps=nothing)
quote
ref = @use_ref(nothing)
current_value = ref[]
if @use_did_deps_change($(esc(deps)))
next_value = $(esc(fn))(current_value)
ref[] = next_value
end
ref[]
end
end
# ╔═╡ c8c560bf-3ef6-492f-933e-21c898fb2db6
md"### `@use_task`"
# ╔═╡ 9ec99592-955a-41bd-935a-b34f37bb5977
macro use_task(f, deps)
quote
error("@use_task was moved to PlutoLinks.jl")
end
end
# ╔═╡ 56f2ff19-c6e8-4858-8e6a-3b790fae7ecb
md"### `@use_file(filename)`"
# ╔═╡ e240b167-560c-4dd7-9801-30467d8758be
macro use_file_change(filename)
quote
error("@use_file_change was moved to PlutoLinks.jl")
end
end
# ╔═╡ 461231e8-4958-46b9-88cb-538f9151a4b0
macro use_file(filename)
quote
error("@use_file was moved to PlutoLinks.jl")
end
end
# ╔═╡ 9af74baf-6571-4a0c-b0c0-989472f18f7a
md"### `@ingredients(julia_file_path)`"
# ╔═╡ d84f47ba-7c18-4d6c-952c-c9a5748a51f8
macro ingredients(filename)
quote
error("@ingredients was moved to PlutoLinks.jl")
end
end
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
[[Random]]
deps = ["SHA", "Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
"""
# ╔═╡ Cell order:
# ╟─729ae3bb-79c2-4fcd-8645-7e0071365537
# ╠═49cb409b-e564-47aa-9dae-9bc5bffa991d
# ╠═3f632c14-5f25-4426-8bff-fd315db55db5
# ╠═92cfc989-5862-4314-ae1b-9cbfc4b42b40
# ╟─c82c8aa9-46a9-4110-88af-8638625222e3
# ╟─1df0a586-3692-11ec-0171-0b48a4a1c4bd
# ╟─cd048a16-37f5-455e-8b6a-c098d5f83b96
# ╟─89b3f807-2e24-4454-8f4c-b2a98aee571e
# ╟─bc0e4219-a40b-46f5-adb2-f164d8a9bbdb
# ╟─c461f6da-a252-4cb4-b510-a4df5ab85065
# ╟─0f632b57-ea01-482b-b93e-d69f962a6d92
# ╟─d9d14e60-0c91-4eec-ba28-82cf1ebc115f
# ╟─cce13aec-7cf0-450c-bc93-bcc4e2a70dfe
# ╟─ec74d9b7-b2ff-4758-a305-c3f30509a786
# ╟─8c2e9cad-eb63-4af5-8b52-629e8d3439bd
# ╟─df0645b5-094a-45b9-b72a-ab7ef9901fa1
# ╟─84736507-7ea9-4b4b-9b70-b1e9b4b33cde
# ╟─014d0172-3425-4429-b8d6-1d195bc60a66
# ╟─71963fa5-82f0-4c8d-9368-0d6ba317f59e
# ╟─118991d7-f470-4775-ac44-4638f4989d58
# ╟─405fb702-cf4a-4d34-b8ed-d3258a61256b
# ╟─39aa6082-40ca-40c3-a2c0-4b6221edda32
# ╟─3d2516f8-569e-40e4-b1dd-9f024f9266e4
# ╟─cf55239c-526b-48fe-933e-9e8d56161fd6
# ╟─86a2f051-c554-4a1c-baee-8d01653c15be
# ╟─b36e130e-578b-42cb-8e3a-763f6b97108d
# ╠═ff97bcce-1d29-469e-a4be-5dc902676057
# ╟─78d28d07-5912-4306-ad95-ad245797889f
# ╟─1b8d6be4-5ba4-42a8-9276-9ef687a8a7a3
# ╟─f168c077-59c7-413b-a0ac-c0fd72781b72
# ╟─9ec6b9c5-6bc1-4033-ab93-072f783184e9
# ╟─fd653af3-be53-4ddd-b69d-3967ef6d588a
# ╟─b25ccaf1-cf46-4eea-a4d9-16c68cf56fad
# ╟─e5905d1e-33ec-47fb-9f98-ead82eb03be8
# ╟─274c2be6-6075-45cf-b28a-862c8bf64bd4
# ╟─90f051be-4384-4383-9a56-2aa584687dc3
# ╟─c8c560bf-3ef6-492f-933e-21c898fb2db6
# ╠═9ec99592-955a-41bd-935a-b34f37bb5977
# ╟─56f2ff19-c6e8-4858-8e6a-3b790fae7ecb
# ╠═e240b167-560c-4dd7-9801-30467d8758be
# ╠═461231e8-4958-46b9-88cb-538f9151a4b0
# ╟─9af74baf-6571-4a0c-b0c0-989472f18f7a
# ╠═d84f47ba-7c18-4d6c-952c-c9a5748a51f8
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002
| PlutoHooks | https://github.com/JuliaPluto/PlutoHooks.jl.git |
|
[
"MIT"
] | 0.0.5 | 072cdf20c9b0507fdd977d7d246d90030609674b | code | 407 | test_env = mktempdir()
function with_test_env()
hooks_path = joinpath(@__DIR__, "..") |> normpath
"""
begin
import Pkg
Pkg.activate("$test_env")
Pkg.develop(path="$hooks_path")
end
"""
end
function noerror(cell)
errored = cell.errored
if errored
@show cell.output
end
!errored
end
function setcode(cell, code)
cell.code = code
end
| PlutoHooks | https://github.com/JuliaPluto/PlutoHooks.jl.git |
|
[
"MIT"
] | 0.0.5 | 072cdf20c9b0507fdd977d7d246d90030609674b | code | 333 | using Test
using PlutoHooks
include("./helpers.jl")
#=
We run the tests without Pluto twice:
1. Without Main.PlutoRunner defined (No Pluto in sight)
2. With Main.PlutoRunner defined (Pluto is defined but the macro is not run in Pluto)
=#
include("./without_pluto.jl")
include("./with_pluto.jl")
include("./without_pluto.jl")
| PlutoHooks | https://github.com/JuliaPluto/PlutoHooks.jl.git |
|
[
"MIT"
] | 0.0.5 | 072cdf20c9b0507fdd977d7d246d90030609674b | code | 5940 | import Pluto
import Pluto: PlutoRunner, Notebook, WorkspaceManager, Cell, ServerSession, ClientSession, update_run!
🍭 = ServerSession()
🍭.options.evaluation.workspace_use_distributed = false
fakeclient = ClientSession(:fake, nothing)
🍭.connected_clients[fakeclient.id] = fakeclient
@testset "Use ref" begin
@testset "Implicit & explicit runs" begin
notebook = Notebook(Cell.([
"using PlutoHooks",
"x = 1",
"""
begin
x;
ref = @use_ref(1)
ref[] += 1
end
""",
]))
cell(idx) = notebook.cells[idx]
update_run!(🍭, notebook, notebook.cells)
@test cell(1) |> noerror
@test cell(2) |> noerror
@test cell(3) |> noerror
@test cell(3).output.body == "2"
update_run!(🍭, notebook, cell(2))
@test cell(3).output.body == "3"
for _ in 1:3
update_run!(🍭, notebook, cell(2))
end
@test cell(3).output.body == "6"
update_run!(🍭, notebook, cell(3))
@test cell(3).output.body == "2"
end
end
@testset "Use Effect" begin
@testset "Implicit runs with dependencies" begin
notebook = Notebook(Cell.([
"using PlutoHooks",
"x = 1",
"y = 1",
"""
begin
y
ref = @use_ref(1)
@use_effect([x]) do
ref[] += 1
end
ref[]
end
""",
]))
cell(idx) = notebook.cells[idx]
update_run!(🍭, notebook, notebook.cells)
@test cell(4) |> noerror
@test cell(4).output.body == "2"
update_run!(🍭, notebook, cell(3))
@test cell(4).output.body == "2"
update_run!(🍭, notebook, cell(2)) # Not changing the value of x
@test cell(4).output.body == "2"
setcode(cell(2), "x = 2")
update_run!(🍭, notebook, cell(2)) # Changing the value of x
@test cell(4).output.body == "3"
end
@testset "Cleanups" begin
notebook = Notebook(Cell.([
"using PlutoHooks",
"cleanup_ref = @use_ref(1)",
"ref = @use_ref(1)",
"x = 1",
"""
begin
@use_effect([x]) do
ref[] += 1
() -> (cleanup_ref[] += 1)
end
end
""",
"cleanup_ref[]",
]))
cell(idx) = notebook.cells[idx]
update_run!(🍭, notebook, notebook.cells)
@test all(noerror, notebook.cells)
@test cell(6).output.body == "1"
update_run!(🍭, notebook, [cell(4), cell(6)])
@test cell(6).output.body == "1"
setcode(cell(4), "x = 2")
update_run!(🍭, notebook, [cell(4), cell(6)])
@test cell(6).output.body == "2"
update_run!(🍭, notebook, [cell(5), cell(6)])
@test cell(6).output.body == "3"
end
end
@testset "Use state" begin
@testset "Trigger reactive run" begin
# Use state tests are distributed because the self run relaying is not closed for non-distributed notebooks
🍭.options.evaluation.workspace_use_distributed = true
notebook = Notebook(Cell.([
"using PlutoHooks",
"state, setstate = @use_state(1)",
"trigger = false",
"""
if trigger
setstate(10)
end
""",
with_test_env(),
"state",
]))
cell(idx) = notebook.cells[idx]
update_run!(🍭, notebook, notebook.cells)
@test all(noerror, notebook.cells)
@test notebook.cells[end].output.body == "1"
setcode(cell(3), "trigger = true")
update_run!(🍭, notebook, cell(3))
sleep(.3) # Reactive run is async
@test notebook.cells[end].output.body == "10"
setcode(cell(3), "trigger = false")
update_run!(🍭, notebook, cell(3))
update_run!(🍭, notebook, cell(2))
@test notebook.cells[end].output.body == "1"
WorkspaceManager.unmake_workspace((🍭, notebook))
🍭.options.evaluation.workspace_use_distributed = false
end
@testset "use state with ref" begin
🍭.options.evaluation.workspace_use_distributed = true
notebook = Notebook(Cell.([
"using PlutoHooks",
"""
begin
state, setstate = @use_state(1)
ref = @use_ref(1)
end
""",
"ref[] += 1",
"state",
"setstate",
with_test_env(),
]))
cell(idx) = notebook.cells[idx]
update_run!(🍭, notebook, notebook.cells)
@test all(noerror, notebook.cells)
update_run!(🍭, notebook, cell(3))
update_run!(🍭, notebook, cell(3))
update_run!(🍭, notebook, cell(3))
@test cell(3).output.body == "5"
setcode(cell(5), """
if state == 1
setstate(2)
end
""")
update_run!(🍭, notebook, cell(5))
sleep(2.)
@test cell(3).output.body == "6"
WorkspaceManager.unmake_workspace((🍭, notebook))
🍭.options.evaluation.workspace_use_distributed = false
end
end
@testset "Use deps" begin
notebook = Notebook(Cell.([
"using PlutoHooks",
"x = 1",
"""
@use_deps([x]) do
ref = @use_ref(1)
ref[] += 1
end
""",
]))
cell(idx) = notebook.cells[idx]
update_run!(🍭, notebook, notebook.cells)
@test all(noerror, notebook.cells)
@test cell(3).output.body == "2"
update_run!(🍭, notebook, cell(2))
@test cell(3).output.body == "3"
setcode(cell(2), "x = 2")
update_run!(🍭, notebook, cell(2))
@test cell(3).output.body == "2"
end
| PlutoHooks | https://github.com/JuliaPluto/PlutoHooks.jl.git |
|
[
"MIT"
] | 0.0.5 | 072cdf20c9b0507fdd977d7d246d90030609674b | code | 630 | @testset "Without Pluto" begin
using PlutoHooks
ref = @use_ref(1)
@test ref[] == 1
x = 2
@use_effect([x]) do
ref[] = x
() -> (ref[] = 9999)
end
@test ref[] == 2
# cleanup never called without pluto ✓
@test ref[] != 9999
state, setstate = @use_state(5)
@test state == 5
@test_nowarn setstate(99)
# setstate does nothing without pluto ✓
@test state == 5
y = 7
result = @use_deps([y]) do
ref2 = @use_ref(1)
ref2[] = y
end
@test result == 7
result = @use_memo([]) do
result * y
end
@test result == 49
end
| PlutoHooks | https://github.com/JuliaPluto/PlutoHooks.jl.git |
|
[
"MIT"
] | 0.0.5 | 072cdf20c9b0507fdd977d7d246d90030609674b | docs | 925 | # PlutoHooks.jl
Get hooked on Pluto! Bring your notebook to life! This is an abstraction based on [React.js Hooks](https://reactjs.org/docs/hooks-intro.html) to implement "react-like" features in [Pluto.jl](https://plutojl.org).
It allows code cells to carry information and processes between updates, and even update themselves.
This package contains only the low level hooks, the directly usable hooks have been moved in [PlutoLinks.jl](https://github.com/JuliaPluto/PlutoLinks.jl). You can take a look at the [PlutoHooks.jl sources](https://juliapluto.github.io/PlutoHooks.jl/src/notebook.html).
There is a lot you can do with this, but some examples:
- Run a process and relay it's output to the rest of your notebook.
- Watch a file and reload the content when it changes.
- Do a computation on separate thread while the rest of notebook continue running.
This requires using Pluto with a version higher than 0.17.2.
| PlutoHooks | https://github.com/JuliaPluto/PlutoHooks.jl.git |
|
[
"MIT"
] | 0.2.6 | 67ff35a2fe68a89d182b39f632f196507598fec2 | code | 4361 | module SimpleTropical
import Base: isinf, show, (+), (*), inv, (==), isequal, (^)
import Base: convert, zero, one, string, real
export Tropical, TropicalInf, ⊕, ⊗, long_tropical_show
_long_show = true
"""
`Tropical(x::T) where T<:Real` defines a new `Tropical`
number.
"""
struct Tropical{T<:Real} <: Number
val::T
inf_flag::Bool
function Tropical{T}(xx::Real, ii::Bool = false) where {T}
TT = typeof(xx)
if isinf(xx) || ii
return new(zero(TT), true)
end
return new(xx, false)
end
end
Tropical(x::T) where {T<:Real} = Tropical{T}(x)
function Tropical(x::T, i::Bool) where {T<:Real}
if i
return Tropical{T}(zero(T), true)
end
return Tropical(x)
end
"""
`TropicalInf` is a constant that represents infinity in the tropical
semiring.
"""
const TropicalInf = Tropical{Bool}(0, true)
isinf(X::Tropical) = X.inf_flag
Base.promote_rule(::Type{Tropical{T}}, ::Type{S}) where {T<:Real,S<:Real} =
Tropical{promote_type(T, S)}
Base.promote_rule(::Type{Tropical{T}}, ::Type{Tropical{S}}) where {T<:Real,S<:Real} =
Tropical{promote_type(T, S)}
convert(::Type{Tropical}, x::T) where {T<:Real} = Tropical{T}(x)
convert(::Type{Tropical{T}}, x::S) where {T<:Real,S<:Tropical} =
Tropical(convert(T, x.val), x.inf_flag)
function long_tropical_show(t::Bool)::Bool
global _long_show = t
end
"""
`long_tropical_show(t::Bool)` determines the display style for
`Tropical` numbers.
+ When `t` is `true`: display numbers like this: `Tropical(5)` or `Tropical(∞)`.
+ When `t` is `false`: display numbers like this: `5` or `∞`.
`long_tropical_show()` returns the current state (`true` or `false`).
"""
long_tropical_show()::Bool = _long_show
export real
function real(x::Tropical)
if isinf(x)
return Inf
end
return x.val
end
function string(x::Tropical{T})::String where T
val = string(x.val)
if isinf(x)
val = "∞"
end
if _long_show
return "Tropical($val)"
else
return val
end
end
function show(io::IO, t::Tropical)
print(io, string(t))
end
# Calling zero(Tropical) returns Tropical(∞) because that's the identity
# element of addition. Likewise, one(Tropical) returns Tropical(0) because
# that's the identity element of multiplication.
zero(::Tropical{T}) where {T} = TropicalInf
zero(::Type{Tropical}) = TropicalInf
zero(::Type{Tropical{T}}) where {T} = Tropical(zero(T), true)
one(::Tropical{T}) where {T} = Tropical{T}(0)
one(::Type{Tropical}) = Tropical(0)
one(::Type{Tropical{T}}) where {T} = Tropical{T}(0)
function (+)(x::Tropical{T}, y::Tropical{T}) where {T}
if isinf(x)
if isinf(y) # when X,Y both are infinite
return Tropical(zero(T), true) # create common infinite
else
return Tropical(y)
end
end
if isinf(y)
return Tropical(x)
end
return Tropical(min(x.val, y.val))
end
(+)(x::Tropical{T}, y::Tropical{S}) where {T,S} = +(promote(x, y)...)
(+)(x::Tropical{T}, y::Real) where {T} = +(promote(x, y)...)
(+)(x::Real, y::Tropical{T}) where {T} = +(promote(x, y)...)
function (*)(x::Tropical{T}, y::Tropical{T}) where {T}
if isinf(x) || isinf(y)
return Tropical(zero(T), true)
end
return Tropical(x.val + y.val)
end
(*)(x::Tropical{T}, y::Tropical{S}) where {T,S} = *(promote(x, y)...)
(*)(x::Tropical{T}, y::Real) where {T} = *(promote(x, y)...)
(*)(x::Real, y::Tropical{T}) where {T} = *(promote(x, y)...)
(⊕)(x::S, y::T) where {S<:Union{Tropical,Real},T<:Union{Tropical,Real}} =
Tropical(x) + Tropical(y)
(⊗)(x::S, y::T) where {S<:Union{Tropical,Real},T<:Union{Tropical,Real}} =
Tropical(x) * Tropical(y)
function inv(X::Tropical)
@assert !isinf(X) "TropicalInf is not invertible"
return Tropical(-X.val)
end
function (^)(X::Tropical, p::Integer)
if isinf(X)
@assert p > 0 "Cannot raise tropical infinity to a nonpositive power."
return X
end
return Tropical(X.val * p)
end
function isequal(X::Tropical, Y::Tropical)
if !isinf(X) && !isinf(Y)
return isequal(X.val, Y.val)
else
return isinf(X) && isinf(Y)
end
end
function ==(X::Tropical, Y::Tropical)
if !isinf(X) && !isinf(Y)
return X.val == Y.val
else
return isinf(X) && isinf(Y)
end
end
end # end of module
| SimpleTropical | https://github.com/scheinerman/SimpleTropical.jl.git |
|
[
"MIT"
] | 0.2.6 | 67ff35a2fe68a89d182b39f632f196507598fec2 | code | 2073 | using Test
using SimpleTropical
x = Tropical(3.5)
y = Tropical(4)
inf = TropicalInf
@testset "Comparisons" begin
@test x == x
@test x != y
@testset "Infinity" begin
@test x != inf
@test inf != y
@test inf == inf
@test inf != Tropical(0)
@test Tropical(0) != inf
@test !isequal(x, inf)
@test !isequal(inf, y)
@test isequal(inf, inf)
@test !isequal(inf, Tropical(0))
@test !isequal(Tropical(0), inf)
end
@testset "Not-a-number" begin
nan = Tropical(NaN)
@test nan != nan
@test isequal(nan, nan)
end
end
@testset "Sum" begin
@test x + y == Tropical(3.5)
@test x + inf == x
@test inf + y == y
end
@testset "Product" begin
z = Tropical(0)
@test x * y == Tropical(7.5)
@test x * z == x
@test y * z == y
@test inf * x == inf
@test y * inf == inf
end
@testset "Inv and power" begin
@test inv(x) == Tropical(-3.5)
@test y^-1 == inv(y)
@test x^10 == Tropical(35.0)
@test y^0 == Tropical(0)
@test inf^5 == inf
@test_throws AssertionError inf^-3
@test_throws AssertionError inv(inf)
end
@testset "Conversions" begin
@test convert(Tropical, 5) === Tropical(5)
@test convert(Tropical{Float64}, 5) === Tropical(5.0)
@test convert(Tropical, x) === x
@test convert(Tropical{Int}, y) === y
@test convert(Tropical{Float32}, x) === Tropical(convert(Float32, x.val))
@test convert(Tropical{Float64}, inf) === Tropical{Float64}(0.0, true)
end
@testset "Identity elements" begin
a = Tropical(5)
@test a + zero(a) == a
@test a * one(a) == a
x = ones(Tropical{Int}, 5)
y = zeros(Tropical, 5)
@test x + y == x
@test x .* y == y
end
@testset "⊕ and ⊗ notation" begin
@test 3 ⊕ 5 == 3
@test 3 ⊗ 5 == 8
@test Inf ⊕ 5 == 5
@test Inf ⊗ 5 == Tropical(Inf)
@test Inf ⊗ 5 == Inf
end
@testset "Conversion to real" begin
a = Tropical(5)
@test real(a) + 1 == 6
b = TropicalInf
@test 1/real(b) == 0.0
end
nothing | SimpleTropical | https://github.com/scheinerman/SimpleTropical.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 672 | using LibAwsIot
using Documenter
DocMeta.setdocmeta!(LibAwsIot, :DocTestSetup, :(using LibAwsIot); recursive=true)
makedocs(;
modules=[LibAwsIot],
repo="https://github.com/JuliaServices/LibAwsIot.jl/blob/{commit}{path}#{line}",
sitename="LibAwsIot.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://github.com/JuliaServices/LibAwsIot.jl",
assets=String[],
size_threshold=2_000_000, # 2 MB, we generate about 1 MB page
size_threshold_warn=2_000_000,
),
pages=["Home" => "index.md"],
)
deploydocs(; repo="github.com/JuliaServices/LibAwsIot.jl", devbranch="main")
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 3801 | using Clang.Generators
using Clang.JLLEnvs
using JLLPrefixes
import aws_c_cal_jll
import aws_c_common_jll
import aws_c_compression_jll
import aws_c_http_jll
import aws_c_io_jll
import aws_c_iot_jll
import aws_c_mqtt_jll
import aws_c_sdkutils_jll
using LibAwsCal
using LibAwsCommon
using LibAwsCompression
using LibAwsHTTP
using LibAwsIO
using LibAwsMqtt
using LibAwsSdkutils
cd(@__DIR__)
const refs_to_remove = []
# This is called if the docs generated from the extract_c_comment_style method did not generate any lines.
# We need to generate at least some docs so that cross-references work with Documenter.jl.
function get_docs(node, docs)
# The macro node types (except for MacroDefault) seem to not generate code, but they will still emit docs and then
# you end up with docs stacked on top of each other, which is a Julia LoadError.
if node.type isa Generators.AbstractMacroNodeType && !(node.type isa Generators.MacroDefault)
return String[]
end
# don't generate empty docs because it makes Documenter.jl mad
if isempty(docs)
return ["Documentation not found."]
end
# remove references to things which don't exist because it causes Documenter.jl's cross_references check to fail
for ref in refs_to_remove
for doci in eachindex(docs)
docs[doci] = replace(docs[doci], "[`$ref`](@ref)" => "`$ref`")
end
end
return docs
end
function should_skip_target(target)
# aws_c_common_jll does not support i686 windows https://github.com/JuliaPackaging/Yggdrasil/blob/bbab3a916ae5543902b025a4a873cf9ee4a7de68/A/aws_c_common/build_tarballs.jl#L48-L49
return target == "i686-w64-mingw32"
end
const deps_jlls = [
aws_c_cal_jll,
aws_c_common_jll,
aws_c_compression_jll,
aws_c_http_jll,
aws_c_io_jll,
aws_c_mqtt_jll,
aws_c_sdkutils_jll,
]
const deps = [
LibAwsCal,
LibAwsCommon,
LibAwsCompression,
LibAwsHTTP,
LibAwsIO,
LibAwsMqtt,
LibAwsSdkutils,
]
const deps_names = sort(collect(Iterators.flatten(names.(deps))))
# clang can emit code for forward declarations of structs defined in our dependencies. we need to skip those, otherwise
# we'll have duplicate struct definitions.
function skip_nodes_in_dependencies!(dag::ExprDAG)
replace!(get_nodes(dag)) do node
if insorted(node.id, deps_names)
return ExprNode(node.id, Generators.Skip(), node.cursor, Expr[], node.adj)
end
return node
end
end
# download toolchains in parallel
Threads.@threads for target in JLLEnvs.JLL_ENV_TRIPLES
if should_skip_target(target)
continue
end
get_default_args(target) # downloads the toolchain
end
for target in JLLEnvs.JLL_ENV_TRIPLES
if should_skip_target(target)
continue
end
options = load_options(joinpath(@__DIR__, "generator.toml"))
options["general"]["output_file_path"] = joinpath(@__DIR__, "..", "lib", "$target.jl")
options["general"]["callback_documentation"] = get_docs
args = get_default_args(target)
for dep in deps_jlls
inc = JLLEnvs.get_pkg_include_dir(dep, target)
push!(args, "-isystem$inc")
end
header_dirs = []
inc = JLLEnvs.get_pkg_include_dir(aws_c_iot_jll, target)
push!(args, "-I$inc")
push!(header_dirs, inc)
headers = String[]
for header_dir in header_dirs
for (root, dirs, files) in walkdir(header_dir)
for file in files
if endswith(file, ".h")
push!(headers, joinpath(root, file))
end
end
end
end
unique!(headers)
ctx = create_context(headers, args, options)
build!(ctx, BUILDSTAGE_NO_PRINTING)
skip_nodes_in_dependencies!(ctx.dag)
build!(ctx, BUILDSTAGE_PRINTING_ONLY)
end
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47684 | using CEnum
"""
__JL_Ctag_80
Documentation not found.
"""
struct __JL_Ctag_80
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_80}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_80, f::Symbol)
r = Ref{__JL_Ctag_80}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_80}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_80}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47691 | using CEnum
"""
__JL_Ctag_210
Documentation not found.
"""
struct __JL_Ctag_210
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_210}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_210, f::Symbol)
r = Ref{__JL_Ctag_210}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_210}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_210}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47684 | using CEnum
"""
__JL_Ctag_90
Documentation not found.
"""
struct __JL_Ctag_90
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_90}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_90, f::Symbol)
r = Ref{__JL_Ctag_90}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_90}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_90}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47689 | using CEnum
"""
__JL_Ctag_210
Documentation not found.
"""
struct __JL_Ctag_210
data::NTuple{4, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_210}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_210, f::Symbol)
r = Ref{__JL_Ctag_210}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_210}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_210}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{232, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 4)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 16)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 20)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 24)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 28)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 32)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 72)
f === :service_task && return Ptr{aws_task}(x + 96)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 136)
f === :in_service && return Ptr{Bool}(x + 144)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 148)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 152)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 156)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 160)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 164)
f === :received_data && return Ptr{aws_byte_buf}(x + 168)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 184)
f === :reconnect_count && return Ptr{UInt64}(x + 192)
f === :queued_operations && return Ptr{aws_linked_list}(x + 200)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 216)
f === :pending_write_completion && return Ptr{Bool}(x + 220)
f === :next_ping_time && return Ptr{UInt64}(x + 224)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47682 | using CEnum
"""
__JL_Ctag_90
Documentation not found.
"""
struct __JL_Ctag_90
data::NTuple{4, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_90}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_90, f::Symbol)
r = Ref{__JL_Ctag_90}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_90}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_90}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{232, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 4)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 16)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 20)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 24)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 28)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 32)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 72)
f === :service_task && return Ptr{aws_task}(x + 96)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 136)
f === :in_service && return Ptr{Bool}(x + 144)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 148)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 152)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 156)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 160)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 164)
f === :received_data && return Ptr{aws_byte_buf}(x + 168)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 184)
f === :reconnect_count && return Ptr{UInt64}(x + 192)
f === :queued_operations && return Ptr{aws_linked_list}(x + 200)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 216)
f === :pending_write_completion && return Ptr{Bool}(x + 220)
f === :next_ping_time && return Ptr{UInt64}(x + 224)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47689 | using CEnum
"""
__JL_Ctag_205
Documentation not found.
"""
struct __JL_Ctag_205
data::NTuple{4, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_205}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_205, f::Symbol)
r = Ref{__JL_Ctag_205}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_205}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_205}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{220, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 4)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 16)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 20)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 24)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 28)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 32)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 68)
f === :service_task && return Ptr{aws_task}(x + 88)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 124)
f === :in_service && return Ptr{Bool}(x + 132)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 136)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 140)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 144)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 148)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 152)
f === :received_data && return Ptr{aws_byte_buf}(x + 156)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 172)
f === :reconnect_count && return Ptr{UInt64}(x + 180)
f === :queued_operations && return Ptr{aws_linked_list}(x + 188)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 204)
f === :pending_write_completion && return Ptr{Bool}(x + 208)
f === :next_ping_time && return Ptr{UInt64}(x + 212)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47682 | using CEnum
"""
__JL_Ctag_90
Documentation not found.
"""
struct __JL_Ctag_90
data::NTuple{4, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_90}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_90, f::Symbol)
r = Ref{__JL_Ctag_90}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_90}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_90}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{220, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 4)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 16)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 20)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 24)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 28)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 32)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 68)
f === :service_task && return Ptr{aws_task}(x + 88)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 124)
f === :in_service && return Ptr{Bool}(x + 132)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 136)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 140)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 144)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 148)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 152)
f === :received_data && return Ptr{aws_byte_buf}(x + 156)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 172)
f === :reconnect_count && return Ptr{UInt64}(x + 180)
f === :queued_operations && return Ptr{aws_linked_list}(x + 188)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 204)
f === :pending_write_completion && return Ptr{Bool}(x + 208)
f === :next_ping_time && return Ptr{UInt64}(x + 212)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47691 | using CEnum
"""
__JL_Ctag_205
Documentation not found.
"""
struct __JL_Ctag_205
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_205}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_205, f::Symbol)
r = Ref{__JL_Ctag_205}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_205}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_205}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47684 | using CEnum
"""
__JL_Ctag_80
Documentation not found.
"""
struct __JL_Ctag_80
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_80}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_80, f::Symbol)
r = Ref{__JL_Ctag_80}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_80}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_80}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47691 | using CEnum
"""
__JL_Ctag_205
Documentation not found.
"""
struct __JL_Ctag_205
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_205}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_205, f::Symbol)
r = Ref{__JL_Ctag_205}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_205}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_205}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47684 | using CEnum
"""
__JL_Ctag_90
Documentation not found.
"""
struct __JL_Ctag_90
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_90}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_90, f::Symbol)
r = Ref{__JL_Ctag_90}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_90}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_90}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47684 | using CEnum
"""
__JL_Ctag_70
Documentation not found.
"""
struct __JL_Ctag_70
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_70}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_70, f::Symbol)
r = Ref{__JL_Ctag_70}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_70}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_70}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 47684 | using CEnum
"""
__JL_Ctag_60
Documentation not found.
"""
struct __JL_Ctag_60
data::NTuple{8, UInt8}
end
function Base.getproperty(x::Ptr{__JL_Ctag_60}, f::Symbol)
f === :scheduled && return Ptr{Bool}(x + 0)
f === :reserved && return Ptr{Csize_t}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::__JL_Ctag_60, f::Symbol)
r = Ref{__JL_Ctag_60}(x)
ptr = Base.unsafe_convert(Ptr{__JL_Ctag_60}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{__JL_Ctag_60}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
# typedef int ( aws_iotdevice_defender_publish_fn ) ( struct aws_byte_cursor report , void * userdata )
"""
Callback to invoke when the defender task needs to "publish" a report. Useful to override default MQTT publish behavior, for testing report outputs
Notes: * This function should not perform blocking IO. * This function should copy the report if it needs to hold on to the memory for an IO operation
returns: AWS\\_OP\\_SUCCESS if the user callback wants to consider the publish failed.
"""
const aws_iotdevice_defender_publish_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_failure_fn ) ( bool is_task_stopped , int error_code , void * userdata )
"""
General callback handler for the task to report that an error occurred while running the DeviceDefender task. Error codes can only go so far in describing where/when and how the failure occur so the errors here may best communicate where/when and the how of the underlying call should be found in log output
# Arguments
* `is_task_stopped`:\\[in\\] flag indicating whether or not the task is unable to continue running
* `error_code`:\\[in\\] error code describing the nature of the failure
"""
const aws_iotdevice_defender_task_failure_fn = Cvoid
# typedef void ( aws_iotdevice_defender_task_canceled_fn ) ( void * userdata )
"""
User callback type invoked when DeviceDefender task has completed cancellation. After a request to stop the task, this signals the completion of the cancellation and no further user callbacks will be invoked.
# Arguments
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_task_canceled_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_rejected_fn ) ( const struct aws_byte_cursor * rejected_message_payload , void * userdata )
"""
User callback type invoked when a report fails to submit.
There are two possibilities for failed submission: 1. The MQTT client fails to publish the message and returns an error code. In this scenario, the client\\_error\\_code will be a value other than AWS\\_ERROR\\_SUCCESS. The rejected\\_message\\_payload parameter will be NULL. 2. After a successful publish, a reply is received on the respective MQTT rejected topic with a message. In this scenario, the client\\_error\\_code will be AWS\\_ERROR\\_SUCCESS, and rejected\\_message\\_payload will contain the payload of the rejected message received.
# Arguments
* `rejected_message_payload`:\\[in\\] response payload recieved from rejection topic
* `userdata`:\\[in\\] callback userdata
"""
const aws_iotdevice_defender_report_rejected_fn = Cvoid
# typedef void ( aws_iotdevice_defender_report_accepted_fn ) ( const struct aws_byte_cursor * accepted_message_payload , void * userdata )
"""
User callback type invoked when the subscribed device defender topic for accepted reports receives a message.
"""
const aws_iotdevice_defender_report_accepted_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_fn ) ( double * value , void * userdata )
"""
User callback type invoked to retrieve a number type custom metric.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_number_list_fn ) ( struct aws_array_list * number_list , void * userdata )
"""
User callback type invoked to retrieve a number list custom metric
List provided will already be initialized and caller must push items into the list of type double.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_number_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_string_list_fn ) ( struct aws_array_list * string_list , void * userdata )
"""
User callback type invoked to retrieve a string list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_string_list_fn = Cvoid
# typedef int ( aws_iotdevice_defender_get_ip_list_fn ) ( struct aws_array_list * ip_list , void * userdata )
"""
User callback type invoked to retrieve an ip list custom metric
List provided will already be initialized and caller must push items into the list of type (struct [`aws_string`](@ref) *). String allocated that are placed into the list are destroyed by the defender task after it is done with the list.
returns: AWS\\_OP\\_SUCCESS if the custom metric was successfully added to the task config
"""
const aws_iotdevice_defender_get_ip_list_fn = Cvoid
"""
aws_iotdevice_defender_report_format
Documentation not found.
"""
@cenum aws_iotdevice_defender_report_format::UInt32 begin
AWS_IDDRF_JSON = 0
AWS_IDDRF_SHORT_JSON = 1
AWS_IDDRF_CBOR = 2
end
"""
defender_custom_metric_type
Change name if this needs external exposure. Needed to keep track of how to interpret instantiated metrics, and cast the supplier\\_fn correctly.
"""
@cenum defender_custom_metric_type::UInt32 begin
DD_METRIC_UNKNOWN = 0
DD_METRIC_NUMBER = 1
DD_METRIC_NUMBER_LIST = 2
DD_METRIC_STRING_LIST = 3
DD_METRIC_IP_LIST = 4
end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task end
"""
Documentation not found.
"""
mutable struct aws_iotdevice_defender_task_config end
"""
aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
Creates a new reporting task config for Device Defender metrics collection
# Arguments
* `config_out`:\\[in\\] output to write a pointer to a task configuration. Will write non-NULL if successful in creating the the task configuration. Will write NULL if there is an error during creation
* `allocator`:\\[in\\] allocator to use for the task configuration's internal data, and the task itself when started
* `thing_name`:\\[in\\] thing name the task config is reporting for
* `report_format`:\\[in\\] report format to produce when publishing to IoT
# Returns
AWS\\_OP\\_SUCCESS and config\\_out will be non-NULL. Returns an error code otherwise
### Prototype
```c
int aws_iotdevice_defender_config_create( struct aws_iotdevice_defender_task_config **config_out, struct aws_allocator *allocator, const struct aws_byte_cursor *thing_name, enum aws_iotdevice_defender_report_format report_format);
```
"""
function aws_iotdevice_defender_config_create(config_out, allocator, thing_name, report_format)
ccall((:aws_iotdevice_defender_config_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task_config}}, Ptr{aws_allocator}, Ptr{aws_byte_cursor}, aws_iotdevice_defender_report_format), config_out, allocator, thing_name, report_format)
end
"""
aws_iotdevice_defender_config_clean_up(config)
Destroys a new reporting task for Device Defender metrics
# Arguments
* `config`:\\[in\\] defender task configuration
### Prototype
```c
void aws_iotdevice_defender_config_clean_up(struct aws_iotdevice_defender_task_config *config);
```
"""
function aws_iotdevice_defender_config_clean_up(config)
ccall((:aws_iotdevice_defender_config_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config},), config)
end
"""
aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
Sets the task failure callback function to invoke when the running of the task encounters a failure. Though this is optional to specify, it is important to register a handler to at least monitor failure that stops the task from running
The most likely scenario for task not being able to continue is failure to reschedule the task
# Arguments
* `config`:\\[in\\] defender task configuration
* `failure_fn`:\\[in\\] failure callback function
# Returns
AWS\\_OP\\_SUCCESS when the task failure callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_failure_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_failure_fn *failure_fn);
```
"""
function aws_iotdevice_defender_config_set_task_failure_fn(config, failure_fn)
ccall((:aws_iotdevice_defender_config_set_task_failure_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_failure_fn}), config, failure_fn)
end
"""
aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
Sets the task cancelation callback function to invoke when the task is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `cancel_fn`:\\[in\\] cancelation callback function
# Returns
AWS\\_OP\\_SUCCESS when the task cancelation callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_task_cancelation_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_task_canceled_fn *cancel_fn);
```
"""
function aws_iotdevice_defender_config_set_task_cancelation_fn(config, cancel_fn)
ccall((:aws_iotdevice_defender_config_set_task_cancelation_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_task_canceled_fn}), config, cancel_fn)
end
"""
aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `accepted_fn`:\\[in\\] accepted report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report accepted callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_accepted_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_accepted_fn *accepted_fn);
```
"""
function aws_iotdevice_defender_config_set_report_accepted_fn(config, accepted_fn)
ccall((:aws_iotdevice_defender_config_set_report_accepted_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_accepted_fn}), config, accepted_fn)
end
"""
aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
Sets the report rejected callback function to invoke when is canceled and not going to be scheduled to run. This is a suggestion of when it is OK to close or free resources kept around while the task is running.
# Arguments
* `config`:\\[in\\] defender task configuration
* `rejected_fn`:\\[in\\] rejected report callback function
# Returns
AWS\\_OP\\_SUCCESS when the report rejected callback has been set. Returns an error if the callback was not set
### Prototype
```c
int aws_iotdevice_defender_config_set_report_rejected_fn( struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_report_rejected_fn *rejected_fn);
```
"""
function aws_iotdevice_defender_config_set_report_rejected_fn(config, rejected_fn)
ccall((:aws_iotdevice_defender_config_set_report_rejected_fn, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_report_rejected_fn}), config, rejected_fn)
end
"""
aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
Sets the period of the device defender task
# Arguments
* `config`:\\[in\\] defender task configuration
* `task_period_ns`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set.
### Prototype
```c
int aws_iotdevice_defender_config_set_task_period_ns( struct aws_iotdevice_defender_task_config *config, uint64_t task_period_ns);
```
"""
function aws_iotdevice_defender_config_set_task_period_ns(config, task_period_ns)
ccall((:aws_iotdevice_defender_config_set_task_period_ns, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, UInt64), config, task_period_ns)
end
"""
aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
Sets the userdata for the device defender task's callback functions
# Arguments
* `config`:\\[in\\] defender task configuration
* `userdata`:\\[in\\] how much time in nanoseconds between defender task runs
# Returns
AWS\\_OP\\_SUCCESS when the property has been set properly. Returns an error code if the value was not able to be set
### Prototype
```c
int aws_iotdevice_defender_config_set_callback_userdata( struct aws_iotdevice_defender_task_config *config, void *userdata);
```
"""
function aws_iotdevice_defender_config_set_callback_userdata(config, userdata)
ccall((:aws_iotdevice_defender_config_set_callback_userdata, libaws_c_iot), Cint, (Ptr{aws_iotdevice_defender_task_config}, Ptr{Cvoid}), config, userdata)
end
"""
aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
Adds number custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
Adds number list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_number_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_number_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_number_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_number_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_number_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
Adds string list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_string_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_string_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_string_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_string_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_string_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
Adds IP list custom metric to the Device Defender task configuration. Has no impact on a defender task already started using the configuration.
# Arguments
* `task_config`:\\[in\\] the defender task configuration to register the metric to
* `metric_name`:\\[in\\] UTF8 byte string of the metric name
* `supplier`:\\[in\\] callback function to produce the metric value when requested at report generation time
* `userdata`:\\[in\\] specific callback data for the supplier callback function
### Prototype
```c
void aws_iotdevice_defender_config_register_ip_list_metric( struct aws_iotdevice_defender_task_config *task_config, const struct aws_byte_cursor *metric_name, aws_iotdevice_defender_get_ip_list_fn *supplier, void *userdata);
```
"""
function aws_iotdevice_defender_config_register_ip_list_metric(task_config, metric_name, supplier, userdata)
ccall((:aws_iotdevice_defender_config_register_ip_list_metric, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_byte_cursor}, Ptr{aws_iotdevice_defender_get_ip_list_fn}, Ptr{Cvoid}), task_config, metric_name, supplier, userdata)
end
"""
aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
Creates and starts a new Device Defender reporting task
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `connection`:\\[in\\] mqtt connection to use to publish reports to
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, struct aws_mqtt_client_connection *connection, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create(task_out, config, connection, event_loop)
ccall((:aws_iotdevice_defender_task_create, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_mqtt_client_connection}, Ptr{aws_event_loop}), task_out, config, connection, event_loop)
end
"""
aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
Creates and starts a new Device Defender reporting task with the ability to define a function to accept/handle each report when the task needs to publish.
# Arguments
* `task_out`:\\[out\\] output parameter to set to point to the defender task
* `config`:\\[in\\] defender task configuration to use to start the task
* `publish_fn`:\\[in\\] callback to handle reports generated by the task. The userdata comes from the task config
* `event_loop`:\\[in\\] IoT device thing name used to determine the MQTT topic to publish the report to and listen for accepted or rejected responses
# Returns
AWS\\_OP\\_SUCCESS if the task has been created successfully and is scheduled to run
### Prototype
```c
int aws_iotdevice_defender_task_create_ex( struct aws_iotdevice_defender_task **task_out, const struct aws_iotdevice_defender_task_config *config, aws_iotdevice_defender_publish_fn *publish_fn, struct aws_event_loop *event_loop);
```
"""
function aws_iotdevice_defender_task_create_ex(task_out, config, publish_fn, event_loop)
ccall((:aws_iotdevice_defender_task_create_ex, libaws_c_iot), Cint, (Ptr{Ptr{aws_iotdevice_defender_task}}, Ptr{aws_iotdevice_defender_task_config}, Ptr{aws_iotdevice_defender_publish_fn}, Ptr{aws_event_loop}), task_out, config, publish_fn, event_loop)
end
"""
aws_iotdevice_defender_task_clean_up(defender_task)
Cancels the running task reporting Device Defender metrics and cleans up. If the task is currently running, it will block until the task has been canceled and cleaned up successfully
# Arguments
* `defender_task`:\\[in\\] running task to stop and clean up
### Prototype
```c
void aws_iotdevice_defender_task_clean_up(struct aws_iotdevice_defender_task *defender_task);
```
"""
function aws_iotdevice_defender_task_clean_up(defender_task)
ccall((:aws_iotdevice_defender_task_clean_up, libaws_c_iot), Cvoid, (Ptr{aws_iotdevice_defender_task},), defender_task)
end
"""
aws_iotdevice_error
Documentation not found.
"""
@cenum aws_iotdevice_error::UInt32 begin
AWS_ERROR_IOTDEVICE_INVALID_RESERVED_BITS = 13312
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_REPORT_INTERVAL = 13313
AWS_ERROR_IOTDEVICE_DEFENDER_UNSUPPORTED_REPORT_FORMAT = 13314
AWS_ERROR_IOTDEVICE_DEFENDER_REPORT_SERIALIZATION_FAILURE = 13315
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE = 13316
AWS_ERROR_IOTDEVICE_DEFENDER_INVALID_TASK_CONFIG = 13317
AWS_ERROR_IOTDEVICE_DEFENDER_PUBLISH_FAILURE = 13318
AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_TASK_STATUS = 13319
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_STREAM_ID = 13320
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_CONNECTION_ID = 13321
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INVALID_SERVICE_ID = 13322
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INCORRECT_MODE = 13323
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_BAD_SERVICE_ID = 13324
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_OPTIONS_VALIDATION = 13325
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_STREAM_OPTIONS_VALIDATION = 13326
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_SECURE_TUNNEL_TERMINATED = 13327
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_WEBSOCKET_TIMEOUT = 13328
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PING_RESPONSE_TIMEOUT = 13329
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_DISCONNECTION = 13330
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_PROCESSING_FAILURE = 13331
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY = 13332
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP = 13333
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP = 13334
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH = 13335
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED = 13336
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE = 13337
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION = 13338
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH = 13339
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID = 13340
AWS_ERROR_END_IOTDEVICE_RANGE = 14335
end
"""
aws_iotdevice_log_subject
Documentation not found.
"""
@cenum aws_iotdevice_log_subject::UInt32 begin
AWS_LS_IOTDEVICE_DEFENDER_TASK = 13312
AWS_LS_IOTDEVICE_DEFENDER_TASK_CONFIG = 13313
AWS_LS_IOTDEVICE_NETWORK_CONFIG = 13314
AWS_LS_IOTDEVICE_SECURE_TUNNELING = 13315
end
"""
aws_iotdevice_library_init(allocator)
Initializes internal datastructures used by aws-c-iot. Must be called before using any functionality in aws-c-iot.
### Prototype
```c
void aws_iotdevice_library_init(struct aws_allocator *allocator);
```
"""
function aws_iotdevice_library_init(allocator)
ccall((:aws_iotdevice_library_init, libaws_c_iot), Cvoid, (Ptr{aws_allocator},), allocator)
end
"""
aws_iotdevice_library_clean_up()
Shuts down the internal datastructures used by aws-c-iot
### Prototype
```c
void aws_iotdevice_library_clean_up(void);
```
"""
function aws_iotdevice_library_clean_up()
ccall((:aws_iotdevice_library_clean_up, libaws_c_iot), Cvoid, ())
end
"""
aws_secure_tunneling_local_proxy_mode
Documentation not found.
"""
@cenum aws_secure_tunneling_local_proxy_mode::UInt32 begin
AWS_SECURE_TUNNELING_SOURCE_MODE = 0
AWS_SECURE_TUNNELING_DESTINATION_MODE = 1
end
"""
aws_secure_tunnel_message_type
Type of IoT Secure Tunnel message. Enum values match IoT Secure Tunneling Local Proxy V3 Websocket Protocol Guide values.
https://github.com/aws-samples/aws-iot-securetunneling-localproxy/blob/main/V3WebSocketProtocolGuide.md
"""
@cenum aws_secure_tunnel_message_type::UInt32 begin
AWS_SECURE_TUNNEL_MT_UNKNOWN = 0
AWS_SECURE_TUNNEL_MT_DATA = 1
AWS_SECURE_TUNNEL_MT_STREAM_START = 2
AWS_SECURE_TUNNEL_MT_STREAM_RESET = 3
AWS_SECURE_TUNNEL_MT_SESSION_RESET = 4
AWS_SECURE_TUNNEL_MT_SERVICE_IDS = 5
AWS_SECURE_TUNNEL_MT_CONNECTION_START = 6
AWS_SECURE_TUNNEL_MT_CONNECTION_RESET = 7
end
"""
aws_secure_tunnel_message_view
Read-only snapshot of a Secure Tunnel Message
"""
struct aws_secure_tunnel_message_view
type::aws_secure_tunnel_message_type
ignorable::Bool
stream_id::Int32
connection_id::UInt32
service_id::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
payload::Ptr{aws_byte_cursor}
end
"""
aws_secure_tunnel_connection_view
Read-only snapshot of a Secure Tunnel Connection Completion Data
"""
struct aws_secure_tunnel_connection_view
service_id_1::Ptr{aws_byte_cursor}
service_id_2::Ptr{aws_byte_cursor}
service_id_3::Ptr{aws_byte_cursor}
end
# typedef void ( aws_secure_tunnel_message_received_fn ) ( const struct aws_secure_tunnel_message_view * message , void * user_data )
"""
Signature of callback to invoke on received messages
"""
const aws_secure_tunnel_message_received_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_complete_fn ) ( const struct aws_secure_tunnel_connection_view * connection_view , int error_code , void * user_data )
"""
Signature of callback to invoke on fully established connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_shutdown_fn ) ( int error_code , void * user_data )
"""
Signature of callback to invoke on shutdown of connection to Secure Tunnel Service
"""
const aws_secure_tunneling_on_connection_shutdown_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_send_message_complete_fn ( enum aws_secure_tunnel_message_type type , int error_code , void * user_data ) )
"""
Signature of callback to invoke on completion of an outbound message
"""
const aws_secure_tunneling_on_send_message_complete_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on the start of a stream
"""
const aws_secure_tunneling_on_stream_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stream_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a stream being reset
"""
const aws_secure_tunneling_on_stream_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_start_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on start of a connection id stream
"""
const aws_secure_tunneling_on_connection_start_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_connection_reset_fn ) ( const struct aws_secure_tunnel_message_view * message , int error_code , void * user_data )
"""
Signature of callback to invoke on a connection id stream being reset
"""
const aws_secure_tunneling_on_connection_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_session_reset_fn ) ( void * user_data )
"""
Signature of callback to invoke on session reset recieved from the Secure Tunnel Service
"""
const aws_secure_tunneling_on_session_reset_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_stopped_fn ) ( void * user_data )
"""
Signature of callback to invoke on Secure Tunnel reaching a STOPPED state
"""
const aws_secure_tunneling_on_stopped_fn = Cvoid
# typedef void ( aws_secure_tunneling_on_termination_complete_fn ) ( void * user_data )
"""
Signature of callback to invoke on termination completion of the Native Secure Tunnel Client
"""
const aws_secure_tunneling_on_termination_complete_fn = Cvoid
"""
aws_secure_tunnel_options
Basic Secure Tunnel configuration struct.
Contains connection properties for the creation of a Secure Tunnel
"""
struct aws_secure_tunnel_options
endpoint_host::aws_byte_cursor
bootstrap::Ptr{aws_client_bootstrap}
socket_options::Ptr{aws_socket_options}
tls_options::Ptr{aws_tls_connection_options}
http_proxy_options::Ptr{aws_http_proxy_options}
access_token::aws_byte_cursor
client_token::aws_byte_cursor
root_ca::Ptr{Cchar}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_vtable
Documentation not found.
"""
struct aws_secure_tunnel_vtable
get_current_time_fn::Ptr{Cvoid}
aws_websocket_client_connect_fn::Ptr{Cvoid}
aws_websocket_send_frame_fn::Ptr{Cvoid}
aws_websocket_release_fn::Ptr{Cvoid}
aws_websocket_close_fn::Ptr{Cvoid}
vtable_user_data::Ptr{Cvoid}
end
"""
aws_secure_tunnel_options_storage
Documentation not found.
"""
struct aws_secure_tunnel_options_storage
allocator::Ptr{aws_allocator}
bootstrap::Ptr{aws_client_bootstrap}
socket_options::aws_socket_options
http_proxy_options::aws_http_proxy_options
http_proxy_config::Ptr{aws_http_proxy_config}
access_token::Ptr{aws_string}
client_token::Ptr{aws_string}
endpoint_host::Ptr{aws_string}
on_message_received::Ptr{aws_secure_tunnel_message_received_fn}
on_connection_complete::Ptr{aws_secure_tunneling_on_connection_complete_fn}
on_connection_shutdown::Ptr{aws_secure_tunneling_on_connection_shutdown_fn}
on_stream_start::Ptr{aws_secure_tunneling_on_stream_start_fn}
on_stream_reset::Ptr{aws_secure_tunneling_on_stream_reset_fn}
on_connection_start::Ptr{aws_secure_tunneling_on_connection_start_fn}
on_connection_reset::Ptr{aws_secure_tunneling_on_connection_reset_fn}
on_session_reset::Ptr{aws_secure_tunneling_on_session_reset_fn}
on_stopped::Ptr{aws_secure_tunneling_on_stopped_fn}
on_send_message_complete::Ptr{aws_secure_tunneling_on_send_message_complete_fn}
on_termination_complete::Ptr{aws_secure_tunneling_on_termination_complete_fn}
secure_tunnel_on_termination_user_data::Ptr{Cvoid}
user_data::Ptr{Cvoid}
local_proxy_mode::aws_secure_tunneling_local_proxy_mode
end
"""
aws_secure_tunnel_message_storage
Documentation not found.
"""
struct aws_secure_tunnel_message_storage
allocator::Ptr{aws_allocator}
storage_view::aws_secure_tunnel_message_view
service_id::aws_byte_cursor
payload::aws_byte_cursor
storage::aws_byte_buf
end
"""
aws_secure_tunnel_connections
Documentation not found.
"""
struct aws_secure_tunnel_connections
allocator::Ptr{aws_allocator}
protocol_version::UInt8
stream_id::Int32
connection_ids::aws_hash_table
service_ids::aws_hash_table
restore_stream_message_view::Ptr{aws_secure_tunnel_message_storage}
restore_stream_message::aws_secure_tunnel_message_storage
end
"""
aws_secure_tunnel_state
The various states that the secure tunnel can be in. A secure tunnel has both a current state and a desired state. Desired state is only allowed to be one of {STOPPED, CONNECTED, TERMINATED}. The secure tunnel transitions states based on either (1) changes in desired state, or (2) external events.
Most states are interruptible (in the sense of a change in desired state causing an immediate change in state) but CONNECTING cannot be interrupted due to waiting for an asynchronous callback (that has no cancel) to complete.
"""
@cenum aws_secure_tunnel_state::UInt32 begin
AWS_STS_STOPPED = 0
AWS_STS_CONNECTING = 1
AWS_STS_CONNECTED = 2
AWS_STS_CLEAN_DISCONNECT = 3
AWS_STS_WEBSOCKET_SHUTDOWN = 4
AWS_STS_PENDING_RECONNECT = 5
AWS_STS_TERMINATED = 6
end
"""
Documentation not found.
"""
mutable struct aws_secure_tunnel_operation end
"""
aws_secure_tunnel
Documentation not found.
"""
struct aws_secure_tunnel
data::NTuple{376, UInt8}
end
function Base.getproperty(x::Ptr{aws_secure_tunnel}, f::Symbol)
f === :allocator && return Ptr{Ptr{aws_allocator}}(x + 0)
f === :ref_count && return Ptr{aws_ref_count}(x + 8)
f === :vtable && return Ptr{Ptr{aws_secure_tunnel_vtable}}(x + 32)
f === :config && return Ptr{Ptr{aws_secure_tunnel_options_storage}}(x + 40)
f === :connections && return Ptr{Ptr{aws_secure_tunnel_connections}}(x + 48)
f === :tls_ctx && return Ptr{Ptr{aws_tls_ctx}}(x + 56)
f === :tls_con_opt && return Ptr{aws_tls_connection_options}(x + 64)
f === :host_resolution_config && return Ptr{aws_host_resolution_config}(x + 128)
f === :service_task && return Ptr{aws_task}(x + 160)
f === :next_service_task_run_time && return Ptr{UInt64}(x + 224)
f === :in_service && return Ptr{Bool}(x + 232)
f === :loop && return Ptr{Ptr{aws_event_loop}}(x + 240)
f === :desired_state && return Ptr{aws_secure_tunnel_state}(x + 248)
f === :current_state && return Ptr{aws_secure_tunnel_state}(x + 252)
f === :handshake_request && return Ptr{Ptr{aws_http_message}}(x + 256)
f === :websocket && return Ptr{Ptr{aws_websocket}}(x + 264)
f === :received_data && return Ptr{aws_byte_buf}(x + 272)
f === :next_reconnect_time_ns && return Ptr{UInt64}(x + 304)
f === :reconnect_count && return Ptr{UInt64}(x + 312)
f === :queued_operations && return Ptr{aws_linked_list}(x + 320)
f === :current_operation && return Ptr{Ptr{aws_secure_tunnel_operation}}(x + 352)
f === :pending_write_completion && return Ptr{Bool}(x + 360)
f === :next_ping_time && return Ptr{UInt64}(x + 368)
return getfield(x, f)
end
function Base.getproperty(x::aws_secure_tunnel, f::Symbol)
r = Ref{aws_secure_tunnel}(x)
ptr = Base.unsafe_convert(Ptr{aws_secure_tunnel}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{aws_secure_tunnel}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
"""
aws_secure_tunnel_new(allocator, options)
Creates a new secure tunnel
# Arguments
* `options`: secure tunnel configuration
# Returns
a new secure tunnel or NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_new( struct aws_allocator *allocator, const struct aws_secure_tunnel_options *options);
```
"""
function aws_secure_tunnel_new(allocator, options)
ccall((:aws_secure_tunnel_new, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_allocator}, Ptr{aws_secure_tunnel_options}), allocator, options)
end
"""
aws_secure_tunnel_acquire(secure_tunnel)
Acquires a reference to a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to acquire a reference to. May be NULL
# Returns
what was passed in as the secure tunnel (a client or NULL)
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_acquire(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_acquire(secure_tunnel)
ccall((:aws_secure_tunnel_acquire, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_release(secure_tunnel)
Release a reference to a secure tunnel. When the secure tunnel ref count drops to zero, the secure tunnel will automatically trigger a stop and once the stop completes, the secure tunnel will delete itself.
# Arguments
* `secure_tunnel`: secure tunnel to release a reference to. May be NULL
# Returns
NULL
### Prototype
```c
struct aws_secure_tunnel *aws_secure_tunnel_release(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_release(secure_tunnel)
ccall((:aws_secure_tunnel_release, libaws_c_iot), Ptr{aws_secure_tunnel}, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_start(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to attempt to connect. The secure tunnel will attempt to stay connected.
# Arguments
* `secure_tunnel`: secure tunnel to start
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_start(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_start(secure_tunnel)
ccall((:aws_secure_tunnel_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_stop(secure_tunnel)
Asynchronous notify to the secure tunnel that you want it to transition to the stopped state. When the secure tunnel reaches the stopped state, all session state is erased.
# Arguments
* `secure_tunnel`: secure tunnel to stop
# Returns
success/failure in the synchronous logic that kicks off the start process
### Prototype
```c
int aws_secure_tunnel_stop(struct aws_secure_tunnel *secure_tunnel);
```
"""
function aws_secure_tunnel_stop(secure_tunnel)
ccall((:aws_secure_tunnel_stop, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel},), secure_tunnel)
end
"""
aws_secure_tunnel_send_message(secure_tunnel, message_options)
Queues a message operation in a secure tunnel
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_send_message( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_send_message(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_send_message, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_message_type_to_c_string(message_type)
Get the const char description of a message type
# Arguments
* `message_type`: message type used by a secure tunnel message
# Returns
const char translation of the message type
### Prototype
```c
const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_message_type message_type);
```
"""
function aws_secure_tunnel_message_type_to_c_string(message_type)
ccall((:aws_secure_tunnel_message_type_to_c_string, libaws_c_iot), Ptr{Cchar}, (aws_secure_tunnel_message_type,), message_type)
end
"""
aws_secure_tunnel_stream_start(secure_tunnel, message_options)
Queue a STREAM\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_connection_start(secure_tunnel, message_options)
Queue a CONNECTION\\_START message in a secure tunnel
!!! note
This function should only be used from source mode.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_connection_start( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_start(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_start, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
Queue a STREAM\\_RESET message in a secure tunnel
!!! compat "Deprecated"
This function should not be used.
# Arguments
* `secure_tunnel`: secure tunnel to queue a message for
* `message_options`: configuration options for the message operation
# Returns
success/failure in the synchronous logic that kicks off the message operation
### Prototype
```c
int aws_secure_tunnel_stream_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_stream_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_stream_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
data_tunnel_pair
Documentation not found.
"""
struct data_tunnel_pair
allocator::Ptr{aws_allocator}
buf::aws_byte_buf
cur::aws_byte_cursor
type::aws_secure_tunnel_message_type
secure_tunnel::Ptr{aws_secure_tunnel}
length_prefix_written::Bool
end
"""
aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
Documentation not found.
### Prototype
```c
void aws_secure_tunnel_set_vtable( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_vtable *vtable);
```
"""
function aws_secure_tunnel_set_vtable(secure_tunnel, vtable)
ccall((:aws_secure_tunnel_set_vtable, libaws_c_iot), Cvoid, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_vtable}), secure_tunnel, vtable)
end
"""
aws_secure_tunnel_get_default_vtable()
Documentation not found.
### Prototype
```c
const struct aws_secure_tunnel_vtable *aws_secure_tunnel_get_default_vtable(void);
```
"""
function aws_secure_tunnel_get_default_vtable()
ccall((:aws_secure_tunnel_get_default_vtable, libaws_c_iot), Ptr{aws_secure_tunnel_vtable}, ())
end
"""
aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_connection_reset( struct aws_secure_tunnel *secure_tunnel, const struct aws_secure_tunnel_message_view *message_options);
```
"""
function aws_secure_tunnel_connection_reset(secure_tunnel, message_options)
ccall((:aws_secure_tunnel_connection_reset, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_secure_tunnel_message_view}), secure_tunnel, message_options)
end
"""
aws_secure_tunnel_field_number
Documentation not found.
"""
@cenum aws_secure_tunnel_field_number::UInt32 begin
AWS_SECURE_TUNNEL_FN_TYPE = 1
AWS_SECURE_TUNNEL_FN_STREAM_ID = 2
AWS_SECURE_TUNNEL_FN_IGNORABLE = 3
AWS_SECURE_TUNNEL_FN_PAYLOAD = 4
AWS_SECURE_TUNNEL_FN_SERVICE_ID = 5
AWS_SECURE_TUNNEL_FN_AVAILABLE_SERVICE_IDS = 6
AWS_SECURE_TUNNEL_FN_CONNECTION_ID = 7
end
"""
aws_secure_tunnel_protocol_buffer_wire_type
Documentation not found.
"""
@cenum aws_secure_tunnel_protocol_buffer_wire_type::UInt32 begin
AWS_SECURE_TUNNEL_PBWT_VARINT = 0
AWS_SECURE_TUNNEL_PBWT_64_BIT = 1
AWS_SECURE_TUNNEL_PBWT_LENGTH_DELIMITED = 2
AWS_SECURE_TUNNEL_PBWT_START_GROUP = 3
AWS_SECURE_TUNNEL_PBWT_END_GROUP = 4
AWS_SECURE_TUNNEL_PBWT_32_BIT = 5
end
# typedef void ( aws_secure_tunnel_on_message_received_fn ) ( struct aws_secure_tunnel * secure_tunnel , struct aws_secure_tunnel_message_view * message_view )
"""
Documentation not found.
"""
const aws_secure_tunnel_on_message_received_fn = Cvoid
"""
aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
Documentation not found.
### Prototype
```c
int aws_iot_st_msg_serialize_from_view( struct aws_byte_buf *buffer, struct aws_allocator *allocator, const struct aws_secure_tunnel_message_view *message_view);
```
"""
function aws_iot_st_msg_serialize_from_view(buffer, allocator, message_view)
ccall((:aws_iot_st_msg_serialize_from_view, libaws_c_iot), Cint, (Ptr{aws_byte_buf}, Ptr{aws_allocator}, Ptr{aws_secure_tunnel_message_view}), buffer, allocator, message_view)
end
"""
aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
Documentation not found.
### Prototype
```c
int aws_secure_tunnel_deserialize_message_from_cursor( struct aws_secure_tunnel *secure_tunnel, struct aws_byte_cursor *cursor, aws_secure_tunnel_on_message_received_fn *on_message_received);
```
"""
function aws_secure_tunnel_deserialize_message_from_cursor(secure_tunnel, cursor, on_message_received)
ccall((:aws_secure_tunnel_deserialize_message_from_cursor, libaws_c_iot), Cint, (Ptr{aws_secure_tunnel}, Ptr{aws_byte_cursor}, Ptr{aws_secure_tunnel_on_message_received_fn}), secure_tunnel, cursor, on_message_received)
end
"""
Documentation not found.
"""
const AWS_C_IOTDEVICE_PACKAGE_ID = 13
"""
Documentation not found.
"""
const AWS_IOT_ST_SPLIT_MESSAGE_SIZE = 15000
"""
Documentation not found.
"""
const AWS_IOT_ST_FIELD_NUMBER_SHIFT = 3
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_VARINT = 268435455
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_1_BYTE_VARINT_VALUE = 128
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_2_BYTE_VARINT_VALUE = 16384
"""
Documentation not found.
"""
const AWS_IOT_ST_MAXIMUM_3_BYTE_VARINT_VALUE = 2097152
"""
Documentation not found.
"""
const AWS_IOT_ST_MAX_PAYLOAD_SIZE = 63 * 1024
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 2033 | module LibAwsIot
using aws_c_iot_jll
using LibAwsCal
using LibAwsCommon
using LibAwsCompression
using LibAwsHTTP
using LibAwsIO
using LibAwsMqtt
using LibAwsSdkutils
const IS_LIBC_MUSL = occursin("musl", Base.BUILD_TRIPLET)
if Sys.isapple() && Sys.ARCH === :aarch64
include("../lib/aarch64-apple-darwin20.jl")
elseif Sys.islinux() && Sys.ARCH === :aarch64 && !IS_LIBC_MUSL
include("../lib/aarch64-linux-gnu.jl")
elseif Sys.islinux() && Sys.ARCH === :aarch64 && IS_LIBC_MUSL
include("../lib/aarch64-linux-musl.jl")
elseif Sys.islinux() && startswith(string(Sys.ARCH), "arm") && !IS_LIBC_MUSL
include("../lib/armv7l-linux-gnueabihf.jl")
elseif Sys.islinux() && startswith(string(Sys.ARCH), "arm") && IS_LIBC_MUSL
include("../lib/armv7l-linux-musleabihf.jl")
elseif Sys.islinux() && Sys.ARCH === :i686 && !IS_LIBC_MUSL
include("../lib/i686-linux-gnu.jl")
elseif Sys.islinux() && Sys.ARCH === :i686 && IS_LIBC_MUSL
include("../lib/i686-linux-musl.jl")
elseif Sys.iswindows() && Sys.ARCH === :i686
error("LibAwsCommon.jl does not support i686 windows https://github.com/JuliaPackaging/Yggdrasil/blob/bbab3a916ae5543902b025a4a873cf9ee4a7de68/A/aws_c_common/build_tarballs.jl#L48-L49")
elseif Sys.islinux() && Sys.ARCH === :powerpc64le
include("../lib/powerpc64le-linux-gnu.jl")
elseif Sys.isapple() && Sys.ARCH === :x86_64
include("../lib/x86_64-apple-darwin14.jl")
elseif Sys.islinux() && Sys.ARCH === :x86_64 && !IS_LIBC_MUSL
include("../lib/x86_64-linux-gnu.jl")
elseif Sys.islinux() && Sys.ARCH === :x86_64 && IS_LIBC_MUSL
include("../lib/x86_64-linux-musl.jl")
elseif Sys.isbsd() && !Sys.isapple()
include("../lib/x86_64-unknown-freebsd13.2.jl")
elseif Sys.iswindows() && Sys.ARCH === :x86_64
include("../lib/x86_64-w64-mingw32.jl")
else
error("Unknown platform: $(Base.BUILD_TRIPLET)")
end
# exports
for name in names(@__MODULE__; all=true)
if name == :eval || name == :include || contains(string(name), "#")
continue
end
@eval export $name
end
end
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | code | 463 | using Test, Aqua, LibAwsIot, LibAwsCommon
@testset "LibAwsIot" begin
@testset "aqua" begin
Aqua.test_all(LibAwsIot, ambiguities=false)
Aqua.test_ambiguities(LibAwsIot)
end
@testset "basic usage to test the library loads" begin
alloc = aws_default_allocator() # important! this shouldn't need to be qualified! if we generate a definition for it in LibAwsIot that is a bug.
aws_iotdevice_library_init(alloc)
end
end
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | docs | 475 | [](https://JuliaServices.github.io/LibAwsIot.jl/stable)
[](https://JuliaServices.github.io/LibAwsIot.jl/dev)
[](https://github.com/JuliaServices/LibAwsIot.jl/actions/workflows/ci.yml)
# LibAwsIot.jl
Julia bindings for the [aws-c-iot](https://github.com/awslabs/aws-c-iot) library.
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 1.0.0 | 086e1af93ee6a90d45be4f61fb2f3928ba2bec43 | docs | 186 | ```@meta
CurrentModule = LibAwsIot
```
# LibAwsIot
Documentation for [LibAwsIot](https://github.com/JuliaServices/LibAwsIot.jl).
```@index
```
```@autodocs
Modules = [LibAwsIot]
```
| LibAwsIot | https://github.com/JuliaServices/LibAwsIot.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 351 | module ValueHistories
using DataStructures
using RecipesBase
export
ValueHistory,
UnivalueHistory,
History,
QHistory,
MultivalueHistory,
MVHistory,
increment!,
@trace
include("abstract.jl")
include("history.jl")
include("qhistory.jl")
include("mvhistory.jl")
include("recipes.jl")
end # module
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 480 | abstract type ValueHistory end
abstract type UnivalueHistory{I} <: ValueHistory end
abstract type MultivalueHistory <: ValueHistory end
Base.push!(history::UnivalueHistory, iteration, value) =
throw(ArgumentError("The specified arguments are of incompatible type"))
# length(history::ValueHistory) = error()
# enumerate(history::ValueHistory) = error()
# get(history::ValueHistory) = error()
# first(history::ValueHistory) = error()
# last(history::ValueHistory) = error()
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 2144 | mutable struct History{I,V} <: UnivalueHistory{I}
lastiter::I
iterations::Vector{I}
values::Vector{V}
function History(::Type{V}, ::Type{I} = Int) where {I,V}
new{I,V}(typemin(I), Array{I}(undef, 0), Array{V}(undef, 0))
end
end
Base.length(history::History) = length(history.iterations)
Base.enumerate(history::History) = zip(history.iterations, history.values)
Base.first(history::History) = history.iterations[1], history.values[1]
Base.last(history::History) = history.iterations[end], history.values[end]
Base.get(history::History) = history.iterations, history.values
function Base.push!(
history::History{I,V},
iteration::I,
value::V) where {I,V}
lastiter = history.lastiter
iteration > lastiter || throw(ArgumentError("Iterations must increase over time"))
history.lastiter = iteration
push!(history.iterations, iteration)
push!(history.values, value)
value
end
function Base.push!(
history::History{I,V},
value::V) where {I,V}
lastiter = history.lastiter == typemin(I) ? zero(I) : history.lastiter
iteration = lastiter + one(history.lastiter)
history.lastiter = iteration
push!(history.iterations, iteration)
push!(history.values, value)
value
end
Base.print(io::IO, history::History{I,V}) where {I,V} = print(io, "$(length(history)) elements {$I,$V}")
function Base.show(io::IO, history::History{I,V}) where {I,V}
println(io, "History")
println(io, " * types: $I, $V")
print(io, " * length: $(length(history))")
end
"""
increment!(trace, iter, val)
Increments the value for a given iteration if it exists, otherwise adds the iteration with an ordinary push.
"""
function increment!(trace::History{I,V}, iter::Number, val) where {I,V}
if !isempty(trace.iterations)
if trace.lastiter == iter # Check most common case to make it faster
i = length(trace.iterations)
else
i = findfirst(isequal(iter), trace.iterations)
end
if i != nothing
return (trace.values[i] += val)
end
end
push!(trace, iter, val)
end
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 3089 |
struct MVHistory{H<:UnivalueHistory} <: MultivalueHistory
storage::Dict{Symbol, H}
end
function MVHistory(::Type{H} = History) where {H<:UnivalueHistory}
MVHistory{H}(Dict{Symbol, H}())
end
# ====================================================================
# Functions
Base.length(history::MVHistory, key::Symbol) = length(history.storage[key])
Base.enumerate(history::MVHistory, key::Symbol) = enumerate(history.storage[key])
Base.first(history::MVHistory, key::Symbol) = first(history.storage[key])
Base.last(history::MVHistory, key::Symbol) = last(history.storage[key])
Base.keys(history::MVHistory) = keys(history.storage)
Base.values(history::MVHistory, key::Symbol) = get(history, key)[2]
function Base.push!(
history::MVHistory{H},
key::Symbol,
iteration::I,
value::V) where {I,H<:UnivalueHistory,V}
if !haskey(history.storage, key)
_hist = H(V, I)
push!(_hist, iteration, value)
history.storage[key] = _hist
else
push!(history.storage[key], iteration, value)
end
value
end
function Base.push!(
history::MVHistory{H},
key::Symbol,
value::V) where {H<:UnivalueHistory,V}
if !haskey(history.storage, key)
_hist = H(V, Int)
push!(_hist, value)
history.storage[key] = _hist
else
push!(history.storage[key], value)
end
value
end
function Base.getindex(history::MVHistory, key::Symbol)
history.storage[key]
end
Base.haskey(history::MVHistory, key::Symbol) = haskey(history.storage, key)
function Base.get(history::MVHistory, key::Symbol)
l = length(history, key)
k, v = first(history.storage[key])
karray = Array{typeof(k)}(undef, l)
varray = Array{typeof(v)}(undef, l)
i = 1
for (k, v) in enumerate(history, key)
karray[i] = k
varray[i] = v
i += 1
end
karray, varray
end
function Base.show(io::IO, history::MVHistory{H}) where {H}
print(io, "MVHistory{$H}")
for (key, val) in history.storage
print(io, "\n", " :$(key) => $(val)")
end
end
using Base.Meta
"""
Easily add to a MVHistory object `tr`.
Example:
```julia
using ValueHistories, OnlineStats
v = Variance(BoundedEqualWeight(30))
tr = MVHistory()
for i=1:100
r = rand()
fit!(v,r)
μ,σ = mean(v),std(v)
# add entries for :r, :μ, and :σ using their current values
@trace tr i r μ σ
end
```
"""
macro trace(tr, i, vars...)
block = Expr(:block)
for v in vars
push!(block.args, :(push!($(esc(tr)), $(quot(Symbol(v))), $(esc(i)), $(esc(v)))))
end
block
end
"""
increment!(trace, key, iter, val)
Increments the value for a given key and iteration if it exists, otherwise adds the key/iteration pair with an ordinary push.
"""
function increment!(trace::MVHistory{<:History}, key::Symbol, iter::Number, val)
if haskey(trace, key)
i = findfirst(isequal(iter), trace.storage[key].iterations)
if i != nothing
return trace[key].values[i] += val
end
end
push!(trace, key, iter, val)
end
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 1738 | mutable struct QHistory{I,V} <: UnivalueHistory{I}
lastiter::I
storage::Deque{Tuple{I,V}}
function QHistory(::Type{V}, ::Type{I} = Int) where {I,V}
new{I,V}(typemin(I), Deque{Tuple{I,V}}())
end
end
# ====================================================================
Base.length(history::QHistory) = length(history.storage)
Base.enumerate(history::QHistory) = history.storage
Base.first(history::QHistory) = first(history.storage)
Base.last(history::QHistory) = last(history.storage)
function Base.push!(
history::QHistory{I,V},
iteration::I,
value::V) where {I,V}
lastiter = history.lastiter
iteration > lastiter || throw(ArgumentError("Iterations must increase over time"))
history.lastiter = iteration
push!(history.storage, (iteration, value))
value
end
function Base.push!(
history::QHistory{I,V},
value::V) where {I,V}
lastiter = history.lastiter == typemin(I) ? zero(I) : history.lastiter
iteration = lastiter + one(history.lastiter)
history.lastiter = iteration
push!(history.storage, (iteration, value))
value
end
function Base.get(history::QHistory{I,V}) where {I,V}
l = length(history)
k, v = first(history.storage)
karray = Array{I}(undef, l)
varray = Array{V}(undef, l)
i = 1
for (k, v) in enumerate(history)
karray[i] = k
varray[i] = v
i += 1
end
karray, varray
end
Base.print(io::IO, history::QHistory{I,V}) where {I,V} = print(io, "$(length(history)) elements {$I,$V}")
function Base.show(io::IO, history::QHistory{I,V}) where {I,V}
println(io, "QHistory")
println(io, " types: $I, $V")
print(io, " length: $(length(history))")
end
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 1275 | _is_plotable_history(::UnivalueHistory) = false
_is_plotable_history(::QHistory{I,V}) where {I,V<:Real} = true
_is_plotable_history(::History{I,V}) where {I,V<:Real} = true
_filter_plotable_histories(h::MVHistory) =
filter(p -> _is_plotable_history(p.second), h.storage)
@recipe function plot(h::Union{History,QHistory})
markershape --> :ellipse
title --> "Value History"
get(h)
end
@recipe function plot(h::MVHistory)
filtered = _filter_plotable_histories(h)
k_vec = [k for (k, v) in filtered]
v_vec = [v for (k, v) in filtered]
if length(v_vec) > 0
markershape --> :ellipse
label --> reshape(map(string, k_vec), (1,length(k_vec)))
if get(plotattributes, :layout, nothing) != nothing
title --> plotattributes[:label]
legend --> false
else
title --> "Multivalue History"
end
get_vec = map(get, v_vec)
[x for (x, y) in get_vec], [y for (x, y) in get_vec]
else
throw(ArgumentError("Can't plot an empty history, nor a history with strange types"))
end
end
@recipe function plot(hs::AbstractVector{T}) where {T<:ValueHistories.UnivalueHistory}
for h in hs
@series begin
h
end
end
end
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 1436 | using ValueHistories
function msg(args...; newline = true)
print(" --> ", args...)
newline && println()
end
n = 100 # increase to match benchmark
msg("Baseline: $n loops that accumulates a Float64")
function f(n)
tmp = 0.
for i=1:n
tmp += i * 3.
end
tmp
end
@time f(n)
@time f(n)
#-----------------------------------------------------------
for T in [History, QHistory]
msg("$(T): $n loops tracking accumulator as Float64")
function g(_history,n)
tmp = 0.
for i=1:n
tmp += i * 3.
push!(_history, i, tmp)
end
tmp
end
_history = T(Float64)
@time g(_history,n)
_history = T(Float64)
@time g(_history,n)
msg("$(T): Converting result into arrays")
@time x,y = get(_history)
@time x,y = get(_history)
end
#-----------------------------------------------------------
msg("MVHistory: $n loops tracking accumulator as Float64 and String")
function g(_history,n)
tmp = 0.
for i=1:n
tmp += i * 3.
push!(_history, :myint, i, tmp)
push!(_history, :mystr, i, string(tmp))
end
tmp
end
_history = MVHistory(History)
@time g(_history,n)
_history = MVHistory(History)
@time g(_history,n)
msg("MVHistory: Converting result into arrays")
@time x,y = get(_history, :mystr)
@time x,y = get(_history, :mystr)
@assert length(y) == n
@assert typeof(y) <: Vector{String}
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 272 | using ValueHistories
using Test
tests = [
"tst_history.jl"
"tst_mvhistory.jl"
]
perf = [
"bm_history.jl"
]
for t in tests
@testset "[->] $t" begin
include(t)
end
end
for p in perf
@testset "[->] $p" begin
include(p)
end
end
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 2278 | for T in [History, QHistory]
@testset "$(T): Basic functions" begin
_history = T(Float64)
@test push!(_history, 1, 10.) == Float64(10.)
@test push!(_history, 2, Float64(21.)) == Float64(21.)
@test_throws ArgumentError push!(_history, 1, Float64(11.))
@test_throws ArgumentError push!(_history, 2, 10)
@test_throws ArgumentError push!(_history, 3, Float32(10))
_history = T(Float64)
numbers = collect(1:100)
push!(_history, 10, Float64(5))
for i = numbers
@test push!(_history, Float64(i + 1)) == Float64(i + 1)
end
@test first(_history) == (10, Float64(5.))
@test last(_history) == (110, Float64(101.))
_history = T(Float64)
numbers = collect(1:2:200)
for i = numbers
@test push!(_history, i, Float64(i + 1)) == Float64(i + 1)
end
println(_history)
show(_history); println()
@test first(_history) == (1, Float64(2.))
@test last(_history) == (199, Float64(200.))
for (i, v) in enumerate(_history)
@test in(i, numbers)
@test Float64(i + 1) == v
end
a1, a2 = get(_history)
@test typeof(a1) <: Vector{Int} && typeof(a2) <: Vector{Float64}
@test length(a1) == length(a2) == length(numbers) == length(_history)
@test convert(Vector{Float64}, a1 .+ 1) == a2
end
@testset "$(T): No explicit iteration" begin
_history = T(Float64)
end
@testset "$(T): Storing arbitrary types" begin
_history = T(String, UInt8)
for i = 1:100
@test push!(_history, i % UInt8, string("i=", i + 1)) == string("i=", i+1)
end
show(_history); println()
a1, a2 = get(_history)
@test typeof(a1) <: Vector{UInt8}
@test typeof(a2) <: Vector{String}
end
end
@testset "History: increment!" begin
_history = History(Float64)
val = 1.
@test increment!(_history, 0, val) == val
@test increment!(_history, 0, val) == 2val
@test increment!(_history, 2, 4val) == 4val
@test increment!(_history, 10, 5val) == 5val
_history2 = QHistory(Float64)
@test_throws MethodError increment!(_history2, 1, val) == val
end
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 3312 | @testset "MVHistory: Basic functions" begin
_history = MVHistory()
function f(i, b; muh=10)
@test b == "yo"
@test muh == .3
i
end
numbers = collect(-10:2:100)
for i = numbers
@test push!(_history, :myf, i, f(i + 1, "yo", muh = .3)) == i + 1
if i % 11 == 0
@test push!(_history, :myint, i, i - 1) == i - 1
@test push!(_history, :myint2, i - 1) == i - 1
end
end
println(_history)
show(_history); println()
@test_throws ArgumentError push!(_history, :myf, 200, "test")
for k in keys(_history)
@test k in [:myf, :myint, :myint2]
end
@test values(_history, :myf) == numbers .+ 1
@test_throws KeyError values(_history, :abc)
@test first(_history, :myf) == (-10, -9)
@test last(_history, :myf) == (100, 101)
@test first(_history, :myint) == (0, -1)
@test last(_history, :myint) == (88, 87)
@test first(_history, :myint2) == (1, -1)
@test last(_history, :myint2) == (5, 87)
for (i, v) in enumerate(_history, :myf)
@test in(i, numbers)
@test i + 1 == v
end
for (i, v) in enumerate(_history, :myint)
@test in(i, numbers)
@test i % 11 == 0
@test i - 1 == v
end
@test typeof(_history[:myf]) <: History
a1, a2 = get(_history, :myf)
@test typeof(a1) <: Vector && typeof(a2) <: Vector
@test length(a1) == length(a2) == length(numbers) == length(_history, :myf)
@test a1 .+ 1 == a2
@test_throws ArgumentError push!(_history, :myf, 10, f(10, "yo", muh = .3))
@test_throws KeyError enumerate(_history, :sign)
@test_throws KeyError length(_history, :sign)
end
@testset "MVHistory: Storing arbitrary types" begin
_history = MVHistory(QHistory)
for i = 1:100
@test push!(_history, :mystring, i % UInt8, string("i=", i + 1)) == string("i=", i+1)
@test push!(_history, :myfloat, i % UInt8, Float32(i + 1)) == Float32(i+1)
end
@test typeof(_history[:mystring]) <: QHistory
a1, a2 = get(_history, :mystring)
@test typeof(a1) <: Vector{UInt8}
@test typeof(a2) <: Vector{String}
a1, a2 = get(_history, :myfloat)
@test typeof(a1) <: Vector{UInt8}
@test typeof(a2) <: Vector{Float32}
end
@testset "MVHistory: @trace" begin
_history = MVHistory()
n = 2
x = [0.0, 1.0]
for i = 1:n
xi = x[i]
@test @trace(_history, i, xi, round(Int,xi)) == round(Int,xi)
end
@test haskey(_history, :xi)
a1, a2 = get(_history, :xi)
@test length(a1) == n
@test length(a2) == n
@test typeof(a1) <: Vector{Int}
@test typeof(a2) <: Vector{Float64}
@test haskey(_history, Symbol("round(Int, xi)"))
a1, a2 = get(_history, Symbol("round(Int, xi)"))
@test length(a1) == n
@test length(a2) == n
@test typeof(a1) <: Vector{Int}
@test typeof(a2) <: Vector{Int}
end
@testset "Increment!" begin
_history = MVHistory()
key = :test
val = 1
@test increment!(_history, key, 1, val) == val
@test increment!(_history, key, 1, val) == 2val
@test increment!(_history, key, 2, 4val) == 4val
@test increment!(_history, key, 10, 5val) == 5val
_history2 = MVHistory(QHistory)
@test_throws MethodError increment!(_history2, key, 1, val) == val
end
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | code | 2113 | # THIS FILE IS DEACTIVATED
using Random
using Plots
using VisualRegressionTests
# run a visual regression test comparing the output to the saved reference png
function dotest(testname, func)
Random.seed!(1)
reffn = joinpath(refdir, "$testname.png")
vtest = VisualTest(func, reffn)
result = test_images(vtest)
@test success(result)
end
# builds a testable function which saves a png to the location `fn`
# use: VisualTest(@plotfunc(plot(rand(10))), "/tmp/tmp.png")
macro plottest(testname, expr)
esc(quote
dotest(string($testname), fn -> begin
$expr
png(fn)
end)
end)
end
# don't let pyplot use a gui... it'll crash
# note: Agg will set gui -> :none in PyPlot
# - This unglyness needs to change
had_mlp = haskey(ENV, "MPLBACKEND")
_old_env = get(ENV, "MPLBACKEND", "")
ENV["MPLBACKEND"] = "Agg"
import PyPlot
info("Matplotlib version: $(PyPlot.matplotlib[:__version__])")
pyplot(size=(200,150), reuse=true)
refdir = joinpath(dirname(@__FILE__), "refimg")
@plottest "dynmv" begin
history = ValueHistories.MVHistory(QHistory)
for i=1:100
x = 0.1i
push!(history, :a, x, sin(x))
push!(history, :wrongtype, x, "$(sin(x))")
if i % 10 == 0
push!(history, :b, x, cos(x))
end
end
plot(history)
end
@plottest "dynmv_sub" begin
history = ValueHistories.MVHistory()
for i=1:100
x = 0.1i
push!(history, :a, x, sin(x))
push!(history, :wrongtype, x, "$(sin(x))")
if i % 10 == 0
push!(history, :b, x, cos(x))
end
end
plot(history, layout=2)
end
@plottest "queueuv" begin
history = ValueHistories.QHistory(Int)
for i = 1:100
push!(history, i, 2i)
end
plot(history)
end
@plottest "vectoruv" begin
history = ValueHistories.History(Int)
for i = 1:100
push!(history, i, 100-i)
end
plot(history)
end
@plottest "uv_vector" begin
history1 = ValueHistories.History(Int)
history2 = ValueHistories.QHistory(Int)
for i = 1:100
push!(history1, i, 2i)
push!(history2, i, 100-i)
end
plot([history1, history2], layout = 2)
end
if had_mlp
ENV["MPLBACKEND"] = _old_env
else
delete!(ENV, "MPLBACKEND")
end
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"MIT"
] | 0.5.4 | 9cc583107e0c09b8986ac10660653fa2e37c0f62 | docs | 6232 | # ValueHistories
*Utility package for efficient tracking of optimization histories,
training curves or other information of arbitrary types and at
arbitrarily spaced sampling times*
| **Package License** | **PkgEval (Nanosoldier)** | **Build Status** |
|:------------------:|:---------------------:|:-----------------:|
| [](LICENSE.md) | [![PkgEval][pkgeval-img]][pkgeval-url] | [](https://travis-ci.org/JuliaML/ValueHistories.jl) [](https://ci.appveyor.com/project/Evizero/valuehistories-jl/branch/master) [](https://coveralls.io/github/JuliaML/ValueHistories.jl?branch=master) |
[pkgeval-img]: https://juliaci.github.io/NanosoldierReports/pkgeval_badges/V/ValueHistories.svg
[pkgeval-url]: https://juliaci.github.io/NanosoldierReports/pkgeval_badges/V/ValueHistories.html
## Installation
This package is registered in `METADATA.jl` and can be installed as usual
```julia
pkg> add ValueHistories
```
## Overview
We provide two basic approaches for logging information over time
or iterations. The sample points do not have to be equally spaced as
long as time/iteration is strictly increasing.
- **Univalue histories**: Intended for tracking the evolution of
a single value over time.
- **Multivalue histories**: Track an arbitrary amount of values over
time, each of which can be of a different type and associated with
a label
*Note that both approaches are typestable.*
### Univalue Histories
This package provide two different concrete implementations
- `QHistory`: Logs the values using a `Dequeue`
- `History`: Logs the values using a `Vector`
Supported operations for univalue histories:
- `push!(history, iteration, value)`: Appends a value to the history
- `get(history)`: Returns all available observations as two vectors. The first vector contains the iterations and the second vector contains the values.
- `enumerate(history)` Returns an enumerator over the observations (as tuples)
- `first(history)`: First stored observation (as tuple)
- `last(history)`: Last stored observation (as tuple)
- `length(history)`: Number of stored observations
- `increment!(history, iteration, value)`: Similar to `push!` but increments the `value` if the `iteration` already exists. Only supported by `History`.
Here is a little example code showing the basic usage:
```julia
using Primes
# Specify the type of value you wish to track
history = QHistory(Float64)
for i = 1:100
# Store some value of the specified type
# Note how the sampling times are not equally spaced
isprime(i) && push!(history, i, sin(.1*i))
end
# Access stored values as arrays
x, y = get(history)
@assert typeof(x) <: Vector{Int}
@assert typeof(y) <: Vector{Float64}
# You can also enumerate over the observations
for (x, y) in enumerate(history)
@assert typeof(x) <: Int
@assert typeof(y) <: Float64
end
# Let's see how this prints to the REPL
history
```
```
QHistory
types: Int64, Float64
length: 25
```
For easy visualisation we also provide recipes for `Plots.jl`.
Note that this is only supported for `Real` types.
```julia
using Plots
plot(history, legend=false)
```

### Multivalue Histories
Multivalue histories are more or less a dynamic collection of a number
of univalue histories. Each individual univalue history is associated
with a symbol `key`. If the user stores a value under a `key` that
has no univalue history associated with it, then a new one is allocated
and specialized for the given type.
Supported operations for multivalue histories:
- `push!(history, key, iteration, value)`: Appends a value to the multivalue history
- `get(history, key)`: Returns all available observations as two vectors. The first vector contains the iterations and the second vector contains the values.
- `enumerate(history, key)` Returns an enumerator over the observations (as tuples)
- `first(history, key)`: First stored observation (as tuple)
- `last(history, key)`: Last stored observation (as tuple)
- `length(history, key)`: Number of stored observations
- `increment!(history, key, iteration, value)`: Similar to `push!` but increments the `value` if the `key` and `iteration` combination already exists.
Here is a little example code showing the basic usage:
```julia
using ValueHistories, Primes
history = MVHistory()
for i=1:100
x = 0.1i
# Store any kind of value without losing type stability
# The first push! to a key defines the tracked type
# push!(history, key, iter, value)
push!(history, :mysin, x, sin(x))
push!(history, :mystring, i, "i=$i")
# Sampling times can be arbitrarily spaced
# Note how we store the sampling time as a Float32 this time
isprime(i) && push!(history, :mycos, Float32(x), cos(x))
end
# Access stored values as arrays
x, y = get(history, :mysin)
@assert length(x) == length(y) == 100
@assert typeof(x) <: Vector{Float64}
@assert typeof(y) <: Vector{Float64}
# Each key can be queried individually
x, y = get(history, :mystring)
@assert length(x) == length(y) == 100
@assert typeof(x) <: Vector{Int64}
@assert typeof(y) <: Vector{String}
@assert y[1] == "i=1"
# You can also enumerate over the observations
for (x, y) in enumerate(history, :mycos)
@assert typeof(x) <: Float32
@assert typeof(y) <: Float64
end
# Let's see how this prints to the REPL
history
```
```
MVHistory{ValueHistories.History{I,V}}
:mysin => 100 elements {Float64,Float64}
:mystring => 100 elements {Int64,String}
:mycos => 25 elements {Float32,Float64}
```
For easy visualisation we also provide recipes for `Plots.jl`.
Note that this is only supported for `Real` types.
```julia
using Plots
plot(history)
```

## License
This code is free to use under the terms of the MIT license.
| ValueHistories | https://github.com/JuliaML/ValueHistories.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 1104 | using Documenter
using PowerSystems
using StorageSystemsSimulations
using DataStructures
pages = OrderedDict(
"Welcome Page" => "index.md",
"Quick Start Guide" => "quick_start_guide.md",
"Tutorials" =>
Any["tutorials/single_stage_model.md", "tutorials/simulation_tutorial.md"],
"Formulation Library" =>
Any["StorageDispatchWithReserves" => "formulation_library/StorageDispatchWithReserves.md",],
"Code Base Developer Guide" => "code_base_developer_guide/developer.md",
"API Reference" => "api/StorageSystemsSimulations.md",
)
makedocs(;
modules=[StorageSystemsSimulations],
format=Documenter.HTML(; prettyurls=haskey(ENV, "GITHUB_ACTIONS")),
warnonly=[:missing_docs],
sitename="StorageSystemsSimulations.jl",
authors="Jose Daniel Lara, Rodrigo Henriquez-Auba, Sourabh Dalvi",
pages=Any[p for p in pages],
)
deploydocs(;
repo="github.com/NREL-Sienna/StorageSystemsSimulations.jl.git",
target="build",
branch="gh-pages",
devbranch="main",
devurl="dev",
push_preview=true,
versions=["stable" => "v^", "v#.#"],
)
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 1145 | using Pkg
Pkg.activate(@__DIR__)
Pkg.instantiate()
using JuliaFormatter
main_paths = [".", "./docs/src"]
for main_path in main_paths
format(
main_path;
whitespace_ops_in_indices=true,
remove_extra_newlines=true,
verbose=true,
always_for_in=true,
whitespace_typedefs=true,
whitespace_in_kwargs=false,
format_docstrings=true,
always_use_return=false, # removed since it has false positives.
)
end
# Documentation Formatter
main_paths = ["./docs/src"]
for main_path in main_paths
for folder in readdir(main_path)
@show folder_path = joinpath(main_path, folder)
if isfile(folder_path)
!occursin(".md", folder_path) && continue
end
format(
folder_path;
format_markdown=true,
whitespace_ops_in_indices=true,
remove_extra_newlines=true,
verbose=true,
always_for_in=true,
whitespace_typedefs=true,
whitespace_in_kwargs=false,
# always_use_return = true # removed since it has false positives.
)
end
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 2455 | isdefined(Base, :__precompile__) && __precompile__()
module StorageSystemsSimulations
######## Storage Formulations ########
export StorageDispatchWithReserves
# variables
export AncillaryServiceVariableDischarge
export AncillaryServiceVariableCharge
export StorageEnergyShortageVariable
export StorageEnergySurplusVariable
export StorageChargeCyclingSlackVariable
export StorageDischargeCyclingSlackVariable
export StorageRegularizationVariableCharge
export StorageRegularizationVariableDischarge
# aux variables
export StorageEnergyOutput
# constraints
export StateofChargeLimitsConstraint
export StorageCyclingCharge
export StorageCyclingDischarge
export ReserveCoverageConstraint
export ReserveCoverageConstraintEndOfPeriod
export ReserveCompleteCoverageConstraint
export ReserveCompleteCoverageConstraintEndOfPeriod
export StorageTotalReserveConstraint
export ReserveDischargeConstraint
export ReserveChargeConstraint
# FF
export EnergyTargetFeedforward
export EnergyLimitFeedforward
#################################################################################
# Modeling Imports
import JuMP
import JuMP: optimizer_with_attributes
import JuMP.Containers: DenseAxisArray, SparseAxisArray
import LinearAlgebra
import InfrastructureSystems
import PowerSystems
import PowerSimulations
import MathOptInterface
import PowerSimulations
import PowerSystems
import JuMP
import Dates
import DataStructures: OrderedDict
const MOI = MathOptInterface
const PSI = PowerSimulations
const PSY = PowerSystems
const PM = PSI.PM
const IS = InfrastructureSystems
const ISOPT = InfrastructureSystems.Optimization
using DocStringExtensions
@template (FUNCTIONS, METHODS) = """
$(TYPEDSIGNATURES)
$(DOCSTRING)
"""
################################################################################
function progress_meter_enabled()
return isa(stderr, Base.TTY) &&
(get(ENV, "CI", nothing) != "true") &&
(get(ENV, "RUNNING_PSI_TESTS", nothing) != "true")
end
# Includes
# Core components
include("core/definitions.jl")
include("core/formulations.jl")
include("core/variables.jl")
include("core/constraints.jl")
include("core/expressions.jl")
include("core/parameters.jl")
include("core/initial_conditions.jl")
include("core/feedforward.jl")
# device models
include("storage_models.jl")
include("storage_constructor.jl")
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 12574 | function _add_ancillary_services!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{T},
::PSI.ArgumentConstructStage,
model::PSI.DeviceModel{T, U},
network_model::PSI.NetworkModel{V},
) where {T <: PSY.Storage, U <: StorageDispatchWithReserves, V <: PM.AbstractPowerModel}
PSI.add_variables!(container, AncillaryServiceVariableDischarge, devices, U())
PSI.add_variables!(container, AncillaryServiceVariableCharge, devices, U())
time_steps = PSI.get_time_steps(container)
for exp in [
ReserveAssignmentBalanceUpDischarge,
ReserveAssignmentBalanceUpCharge,
ReserveAssignmentBalanceDownDischarge,
ReserveAssignmentBalanceDownCharge,
ReserveDeploymentBalanceUpDischarge,
ReserveDeploymentBalanceUpCharge,
ReserveDeploymentBalanceDownDischarge,
ReserveDeploymentBalanceDownCharge,
]
PSI.lazy_container_addition!(
container,
exp(),
T,
PSY.get_name.(devices),
time_steps,
)
end
for exp in [
ReserveAssignmentBalanceUpDischarge,
ReserveAssignmentBalanceDownDischarge,
ReserveDeploymentBalanceUpDischarge,
ReserveDeploymentBalanceDownDischarge,
]
add_to_expression!(
container,
exp,
AncillaryServiceVariableDischarge,
devices,
model,
)
end
for exp in [
ReserveAssignmentBalanceUpCharge,
ReserveAssignmentBalanceDownCharge,
ReserveDeploymentBalanceUpCharge,
ReserveDeploymentBalanceDownCharge,
]
add_to_expression!(container, exp, AncillaryServiceVariableCharge, devices, model)
end
services = Set()
for d in devices
union!(services, PSY.get_services(d))
end
for s in services
PSI.lazy_container_addition!(
container,
TotalReserveOffering(),
T,
PSY.get_name.(devices),
time_steps,
meta="$(typeof(s))_$(PSY.get_name(s))",
)
end
for v in [AncillaryServiceVariableCharge, AncillaryServiceVariableDischarge]
add_to_expression!(container, TotalReserveOffering, v, devices, model)
end
return
end
function _add_ancillary_services!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{T},
::PSI.ModelConstructStage,
model::PSI.DeviceModel{T, U},
network_model::PSI.NetworkModel{V},
) where {T <: PSY.Storage, U <: StorageDispatchWithReserves, V <: PM.AbstractPowerModel}
PSI.add_constraints!(
container,
ReserveCoverageConstraint,
devices,
model,
network_model,
)
PSI.add_constraints!(
container,
ReserveCoverageConstraintEndOfPeriod,
devices,
model,
network_model,
)
PSI.add_constraints!(
container,
ReserveDischargeConstraint,
devices,
model,
network_model,
)
PSI.add_constraints!(container, ReserveChargeConstraint, devices, model, network_model)
PSI.add_constraints!(
container,
StorageTotalReserveConstraint,
devices,
model,
network_model,
)
return
end
function _active_power_variables_and_expressions(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{T},
model::PSI.DeviceModel{T, U},
network_model::PSI.NetworkModel,
) where {T <: PSY.Storage, U <: StorageDispatchWithReserves}
PSI.add_variables!(container, PSI.ActivePowerInVariable, devices, U())
PSI.add_variables!(container, PSI.ActivePowerOutVariable, devices, U())
PSI.add_variables!(container, PSI.EnergyVariable, devices, U())
PSI.add_variables!(container, StorageEnergyOutput, devices, U())
if PSI.get_attribute(model, "reservation")
PSI.add_variables!(container, PSI.ReservationVariable, devices, U())
end
if PSI.get_attribute(model, "energy_target")
PSI.add_variables!(container, StorageEnergyShortageVariable, devices, U())
PSI.add_variables!(container, StorageEnergySurplusVariable, devices, U())
end
if PSI.get_attribute(model, "cycling_limits")
PSI.add_variables!(container, StorageChargeCyclingSlackVariable, devices, U())
PSI.add_variables!(container, StorageDischargeCyclingSlackVariable, devices, U())
end
PSI.initial_conditions!(container, devices, U())
PSI.add_to_expression!(
container,
PSI.ActivePowerBalance,
PSI.ActivePowerInVariable,
devices,
model,
network_model,
)
PSI.add_to_expression!(
container,
PSI.ActivePowerBalance,
PSI.ActivePowerOutVariable,
devices,
model,
network_model,
)
return
end
function _active_power_and_energy_bounds(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{T},
model::PSI.DeviceModel{T, U},
network_model::PSI.NetworkModel,
) where {T <: PSY.Storage, U <: StorageDispatchWithReserves}
if PSI.has_service_model(model)
add_reserve_range_constraint_with_deployment!(
container,
PSI.OutputActivePowerVariableLimitsConstraint,
PSI.ActivePowerOutVariable,
devices,
model,
network_model,
)
add_reserve_range_constraint_with_deployment!(
container,
PSI.InputActivePowerVariableLimitsConstraint,
PSI.ActivePowerInVariable,
devices,
model,
network_model,
)
else
PSI.add_constraints!(
container,
PSI.OutputActivePowerVariableLimitsConstraint,
PSI.ActivePowerOutVariable,
devices,
model,
network_model,
)
PSI.add_constraints!(
container,
PSI.InputActivePowerVariableLimitsConstraint,
PSI.ActivePowerInVariable,
devices,
model,
network_model,
)
end
PSI.add_constraints!(
container,
StateofChargeLimitsConstraint,
PSI.EnergyVariable,
devices,
model,
network_model,
)
return
end
function PSI.construct_device!(
container::PSI.OptimizationContainer,
sys::PSY.System,
stage::PSI.ArgumentConstructStage,
model::PSI.DeviceModel{St, D},
network_model::PSI.NetworkModel{S},
) where {St <: PSY.Storage, D <: StorageDispatchWithReserves, S <: PM.AbstractPowerModel}
devices = PSI.get_available_components(model, sys)
_active_power_variables_and_expressions(container, devices, model, network_model)
PSI.add_variables!(container, PSI.ReactivePowerVariable, devices, D())
if PSI.get_attribute(model, "regularization")
PSI.add_variables!(container, StorageRegularizationVariableCharge, devices, D())
PSI.add_variables!(container, StorageRegularizationVariableDischarge, devices, D())
end
PSI.add_to_expression!(
container,
PSI.ReactivePowerBalance,
PSI.ReactivePowerVariable,
devices,
model,
network_model,
)
if PSI.has_service_model(model)
_add_ancillary_services!(container, devices, stage, model, network_model)
end
PSI.add_feedforward_arguments!(container, model, devices)
return
end
function PSI.construct_device!(
container::PSI.OptimizationContainer,
sys::PSY.System,
::PSI.ModelConstructStage,
model::PSI.DeviceModel{St, D},
network_model::PSI.NetworkModel{S},
) where {St <: PSY.Storage, D <: StorageDispatchWithReserves, S <: PM.AbstractPowerModel}
devices = PSI.get_available_components(model, sys)
_active_power_and_energy_bounds(container, devices, model, network_model)
PSI.add_constraints!(
container,
PSI.ReactivePowerVariableLimitsConstraint,
PSI.ReactivePowerVariable,
devices,
model,
network_model,
)
# Energy Balance limits
PSI.add_constraints!(
container,
PSI.EnergyBalanceConstraint,
devices,
model,
network_model,
)
if PSI.has_service_model(model)
_add_ancillary_services!(container, devices, stage, model, network_model)
end
if PSI.get_attribute(model, "energy_target")
PSI.add_constraints!(
container,
StateofChargeTargetConstraint,
devices,
model,
network_model,
)
end
if PSI.get_attribute(model, "cycling_limits")
PSI.add_constraints!(container, StorageCyclingCharge, devices, model, network_model)
PSI.add_constraints!(
container,
StorageCyclingDischarge,
devices,
model,
network_model,
)
end
if PSI.get_attribute(model, "regularization")
PSI.add_constraints!(container, StorageRegularizationConstraints, devices, D())
end
PSI.add_constraint_dual!(container, sys, model)
PSI.objective_function!(container, devices, model, S)
return
end
function PSI.construct_device!(
container::PSI.OptimizationContainer,
sys::PSY.System,
stage::PSI.ArgumentConstructStage,
model::PSI.DeviceModel{St, D},
network_model::PSI.NetworkModel{S},
) where {
St <: PSY.Storage,
D <: StorageDispatchWithReserves,
S <: PM.AbstractActivePowerModel,
}
devices = PSI.get_available_components(model, sys)
_active_power_variables_and_expressions(container, devices, model, network_model)
if PSI.get_attribute(model, "regularization")
PSI.add_variables!(container, StorageRegularizationVariableCharge, devices, D())
PSI.add_variables!(container, StorageRegularizationVariableDischarge, devices, D())
end
if PSI.has_service_model(model)
_add_ancillary_services!(container, devices, stage, model, network_model)
end
PSI.add_feedforward_arguments!(container, model, devices)
return
end
function PSI.construct_device!(
container::PSI.OptimizationContainer,
sys::PSY.System,
stage::PSI.ModelConstructStage,
model::PSI.DeviceModel{St, D},
network_model::PSI.NetworkModel{S},
) where {
St <: PSY.Storage,
D <: StorageDispatchWithReserves,
S <: PM.AbstractActivePowerModel,
}
devices = PSI.get_available_components(model, sys)
_active_power_and_energy_bounds(container, devices, model, network_model)
# Energy Balanace limits
PSI.add_constraints!(
container,
PSI.EnergyBalanceConstraint,
devices,
model,
network_model,
)
if PSI.has_service_model(model)
_add_ancillary_services!(container, devices, stage, model, network_model)
end
if PSI.get_attribute(model, "energy_target")
PSI.add_constraints!(
container,
StateofChargeTargetConstraint,
devices,
model,
network_model,
)
end
if PSI.get_attribute(model, "cycling_limits")
PSI.add_constraints!(container, StorageCyclingCharge, devices, model, network_model)
PSI.add_constraints!(
container,
StorageCyclingDischarge,
devices,
model,
network_model,
)
end
if PSI.has_service_model(model)
if PSI.get_attribute(model, "complete_coverage")
PSI.add_constraints!(
container,
ReserveCompleteCoverageConstraint,
devices,
model,
network_model,
)
PSI.add_constraints!(
container,
ReserveCompleteCoverageConstraintEndOfPeriod,
devices,
model,
network_model,
)
end
end
if PSI.get_attribute(model, "regularization")
PSI.add_constraints!(
container,
StorageRegularizationConstraintCharge,
devices,
model,
network_model,
)
PSI.add_constraints!(
container,
StorageRegularizationConstraintDischarge,
devices,
model,
network_model,
)
end
PSI.add_feedforward_constraints!(container, model, devices)
PSI.objective_function!(container, devices, model, S)
PSI.add_constraint_dual!(container, sys, model)
return
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 67524 | #! format: off
PSI.requires_initialization(::AbstractStorageFormulation) = false
PSI.get_variable_multiplier(_, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = NaN
########################### ActivePowerInVariable, Storage #################################
PSI.get_variable_binary(::PSI.ActivePowerInVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
PSI.get_variable_lower_bound(::PSI.ActivePowerInVariable, d::PSY.Storage, ::AbstractStorageFormulation) = 0.0
PSI.get_variable_upper_bound(::PSI.ActivePowerInVariable, d::PSY.Storage, ::AbstractStorageFormulation) = PSY.get_input_active_power_limits(d).max
PSI.get_variable_multiplier(::PSI.ActivePowerInVariable, d::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = -1.0
########################### ActivePowerOutVariable, Storage #################################
PSI.get_variable_binary(::PSI.ActivePowerOutVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
PSI.get_variable_lower_bound(::PSI.ActivePowerOutVariable, d::PSY.Storage, ::AbstractStorageFormulation) = 0.0
PSI.get_variable_upper_bound(::PSI.ActivePowerOutVariable, d::PSY.Storage, ::AbstractStorageFormulation) = PSY.get_output_active_power_limits(d).max
PSI.get_variable_multiplier(::PSI.ActivePowerOutVariable, d::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = 1.0
########################### ReactivePowerVariable, Storage #################################
PSI.get_variable_binary(::PSI.ReactivePowerVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
PSI.get_variable_lower_bound(::PSI.ReactivePowerVariable, d::PSY.Storage, ::AbstractStorageFormulation) = PSY.get_reactive_power_limits(d).min
PSI.get_variable_upper_bound(::PSI.ReactivePowerVariable, d::PSY.Storage, ::AbstractStorageFormulation) = PSY.get_reactive_power_limits(d).max
PSI.get_variable_multiplier(::PSI.ReactivePowerVariable, d::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = 1.0
############## EnergyVariable, Storage ####################
PSI.get_variable_binary(::PSI.EnergyVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
PSI.get_variable_upper_bound(::PSI.EnergyVariable, d::PSY.Storage, ::AbstractStorageFormulation) = PSY.get_storage_level_limits(d).max * PSY.get_storage_capacity(d) * PSY.get_conversion_factor(d)
PSI.get_variable_lower_bound(::PSI.EnergyVariable, d::PSY.Storage, ::AbstractStorageFormulation) = PSY.get_storage_level_limits(d).min * PSY.get_storage_capacity(d) * PSY.get_conversion_factor(d)
PSI.get_variable_warm_start_value(::PSI.EnergyVariable, d::PSY.Storage, ::AbstractStorageFormulation) = PSY.get_initial_storage_capacity_level(d) * PSY.get_storage_capacity(d) * PSY.get_conversion_factor(d)
############## ReservationVariable, Storage ####################
PSI.get_variable_binary(::PSI.ReservationVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = true
############## Ancillary Services Variables ####################
PSI.get_variable_binary(::AncillaryServiceVariableDischarge, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
PSI.get_variable_binary(::AncillaryServiceVariableCharge, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
function PSI.get_variable_upper_bound(::AncillaryServiceVariableCharge, r::PSY.Reserve, d::PSY.Storage, ::AbstractStorageFormulation)
return PSY.get_max_output_fraction(r) * PSY.get_input_active_power_limits(d).max
end
function PSI.get_variable_upper_bound(::AncillaryServiceVariableDischarge, r::PSY.Reserve, d::PSY.Storage, ::AbstractStorageFormulation)
return PSY.get_max_output_fraction(r) * PSY.get_output_active_power_limits(d).max
end
function PSI.get_variable_upper_bound(::PSI.ActivePowerReserveVariable, r::PSY.Reserve, d::PSY.Storage, ::PSI.AbstractReservesFormulation)
return PSY.get_max_output_fraction(r) * (PSY.get_output_active_power_limits(d).max + PSY.get_input_active_power_limits(d).max)
end
function PSI.get_variable_upper_bound(::PSI.ActivePowerReserveVariable, r::PSY.ReserveDemandCurve, d::PSY.Storage, ::PSI.AbstractReservesFormulation)
return PSY.get_max_output_fraction(r) * (PSY.get_output_active_power_limits(d).max + PSY.get_input_active_power_limits(d).max)
end
PSI.get_expression_type_for_reserve(::PSI.ActivePowerReserveVariable, ::Type{<:PSY.Storage}, ::Type{<:PSY.Reserve}) = TotalReserveOffering
############### Energy Targets Variables #############
PSI.get_variable_binary(::StorageEnergyShortageVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
PSI.get_variable_binary(::StorageEnergySurplusVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
############### Cycling Limits Variables #############
PSI.get_variable_binary(::StorageChargeCyclingSlackVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
PSI.get_variable_binary(::StorageDischargeCyclingSlackVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
########################Objective Function##################################################
PSI.objective_function_multiplier(::PSI.VariableType, ::AbstractStorageFormulation)=PSI.OBJECTIVE_FUNCTION_POSITIVE
PSI.objective_function_multiplier(::StorageEnergySurplusVariable, ::AbstractStorageFormulation)=PSI.OBJECTIVE_FUNCTION_POSITIVE
PSI.objective_function_multiplier(::StorageEnergyShortageVariable, ::AbstractStorageFormulation)=PSI.OBJECTIVE_FUNCTION_POSITIVE
PSI.proportional_cost(cost::PSY.StorageCost, ::StorageEnergySurplusVariable, ::PSY.EnergyReservoirStorage, ::AbstractStorageFormulation)=PSY.get_energy_surplus_cost(cost)
PSI.proportional_cost(cost::PSY.StorageCost, ::StorageEnergyShortageVariable, ::PSY.EnergyReservoirStorage, ::AbstractStorageFormulation)=PSY.get_energy_shortage_cost(cost)
PSI.proportional_cost(::PSY.StorageCost, ::StorageChargeCyclingSlackVariable, ::PSY.EnergyReservoirStorage, ::AbstractStorageFormulation)=CYCLE_VIOLATION_COST
PSI.proportional_cost(::PSY.StorageCost, ::StorageDischargeCyclingSlackVariable, ::PSY.EnergyReservoirStorage, ::AbstractStorageFormulation)=CYCLE_VIOLATION_COST
PSI.variable_cost(cost::PSY.StorageCost, ::PSI.ActivePowerOutVariable, ::PSY.Storage, ::AbstractStorageFormulation)=PSY.get_discharge_variable_cost(cost)
PSI.variable_cost(cost::PSY.StorageCost, ::PSI.ActivePowerInVariable, ::PSY.Storage, ::AbstractStorageFormulation)=PSY.get_charge_variable_cost(cost)
######################## Parameters ##################################################
PSI.get_parameter_multiplier(::EnergyTargetParameter, ::PSY.Storage, ::AbstractStorageFormulation) = 1.0
PSI.get_parameter_multiplier(::EnergyLimitParameter, ::PSY.Storage, ::AbstractStorageFormulation) = 1.0
############## ReservationVariable, Storage ####################
PSI.get_variable_binary(::StorageRegularizationVariable, ::Type{<:PSY.Storage}, ::AbstractStorageFormulation) = false
PSI.get_variable_upper_bound(::StorageRegularizationVariable, d::PSY.Storage, ::AbstractStorageFormulation) = max(PSY.get_input_active_power_limits(d).max, PSY.get_output_active_power_limits(d).max)
PSI.get_variable_lower_bound(::StorageRegularizationVariable, d::PSY.Storage, ::AbstractStorageFormulation) = 0.0
#! format: on
function PSI.variable_cost(
cost::PSY.StorageCost,
::StorageRegularizationVariable,
::PSY.Storage,
::AbstractStorageFormulation,
)
return PSY.CostCurve(PSY.LinearCurve(REG_COST), PSY.UnitSystem.SYSTEM_BASE)
end
function PSI.get_default_time_series_names(
::Type{D},
::Type{<:Union{PSI.FixedOutput, AbstractStorageFormulation}},
) where {D <: PSY.Storage}
return Dict{Type{<:PSI.TimeSeriesParameter}, String}()
end
function PSI.get_default_attributes(
::Type{PSY.EnergyReservoirStorage},
::Type{T},
) where {T <: AbstractStorageFormulation}
return Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => false,
)
end
######################## Make initial Conditions for a Model ####################
PSI.get_initial_conditions_device_model(
::PSI.OperationModel,
model::PSI.DeviceModel{T, <:AbstractStorageFormulation},
) where {T <: PSY.Storage} = model
PSI.initial_condition_default(
::PSI.InitialEnergyLevel,
d::PSY.Storage,
::AbstractStorageFormulation,
) =
PSY.get_initial_storage_capacity_level(d) *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d)
PSI.initial_condition_variable(
::PSI.InitialEnergyLevel,
d::PSY.Storage,
::AbstractStorageFormulation,
) = PSI.EnergyVariable()
function PSI.initial_conditions!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{St},
formulation::AbstractStorageFormulation,
) where {St <: PSY.Storage}
PSI.add_initial_condition!(container, devices, formulation, PSI.InitialEnergyLevel())
return
end
############################# Power Constraints ###########################
PSI.get_min_max_limits(
device::PSY.Storage,
::Type{<:PSI.ReactivePowerVariableLimitsConstraint},
::Type{<:AbstractStorageFormulation},
) = PSY.get_reactive_power_limits(device)
PSI.get_min_max_limits(
device::PSY.Storage,
::Type{PSI.InputActivePowerVariableLimitsConstraint},
::Type{<:AbstractStorageFormulation},
) = PSY.get_input_active_power_limits(device)
PSI.get_min_max_limits(
device::PSY.Storage,
::Type{PSI.OutputActivePowerVariableLimitsConstraint},
::Type{<:AbstractStorageFormulation},
) = PSY.get_output_active_power_limits(device)
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
::PSI.NetworkModel{X},
) where {
T <: PSI.OutputActivePowerVariableLimitsConstraint,
U <: PSI.ActivePowerOutVariable,
V <: PSY.Storage,
W <: AbstractStorageFormulation,
X <: PM.AbstractPowerModel,
}
if PSI.get_attribute(model, "reservation")
PSI.add_reserve_range_constraints!(container, T, U, devices, model, X)
else
PSI.add_range_constraints!(container, T, U, devices, model, X)
end
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
::PSI.NetworkModel{X},
) where {
T <: PSI.InputActivePowerVariableLimitsConstraint,
U <: PSI.ActivePowerInVariable,
V <: PSY.Storage,
W <: AbstractStorageFormulation,
X <: PM.AbstractPowerModel,
}
if PSI.get_attribute(model, "reservation")
PSI.add_reserve_range_constraints!(container, T, U, devices, model, X)
else
PSI.add_range_constraints!(container, T, U, devices, model, X)
end
end
function add_reserve_range_constraint_with_deployment!(
container::PSI.OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
::PSI.NetworkModel{X},
) where {
T <: PSI.OutputActivePowerVariableLimitsConstraint,
U <: PSI.ActivePowerOutVariable,
V <: PSY.Storage,
W <: AbstractStorageFormulation,
X <: PM.AbstractPowerModel,
}
time_steps = PSI.get_time_steps(container)
names = [PSY.get_name(x) for x in devices]
powerout_var = PSI.get_variable(container, U(), V)
ss_var = PSI.get_variable(container, PSI.ReservationVariable(), V)
r_up_ds = PSI.get_expression(container, ReserveDeploymentBalanceUpDischarge(), V)
r_dn_ds = PSI.get_expression(container, ReserveDeploymentBalanceDownDischarge(), V)
constraint = PSI.add_constraints_container!(container, T(), V, names, time_steps)
for d in devices, t in time_steps
ci_name = PSY.get_name(d)
constraint[ci_name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerout_var[ci_name, t] + r_up_ds[ci_name, t] - r_dn_ds[ci_name, t] <=
ss_var[ci_name, t] * PSY.get_output_active_power_limits(d).max
)
end
end
function add_reserve_range_constraint_with_deployment!(
container::PSI.OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
::PSI.NetworkModel{X},
) where {
T <: PSI.InputActivePowerVariableLimitsConstraint,
U <: PSI.ActivePowerInVariable,
V <: PSY.Storage,
W <: AbstractStorageFormulation,
X <: PM.AbstractPowerModel,
}
time_steps = PSI.get_time_steps(container)
names = [PSY.get_name(x) for x in devices]
powerin_var = PSI.get_variable(container, U(), V)
ss_var = PSI.get_variable(container, PSI.ReservationVariable(), V)
r_up_ch = PSI.get_expression(container, ReserveDeploymentBalanceUpCharge(), V)
r_dn_ch = PSI.get_expression(container, ReserveDeploymentBalanceDownCharge(), V)
constraint = PSI.add_constraints_container!(container, T(), V, names, time_steps)
for d in devices, t in time_steps
ci_name = PSY.get_name(d)
constraint[ci_name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerin_var[ci_name, t] + r_dn_ch[ci_name, t] - r_up_ch[ci_name, t] <=
(1.0 - ss_var[ci_name, t]) * PSY.get_input_active_power_limits(d).max
)
end
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
T::Type{<:PSI.ReactivePowerVariableLimitsConstraint},
U::Type{<:PSI.ReactivePowerVariable},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
::PSI.NetworkModel{X},
) where {V <: PSY.Storage, W <: AbstractStorageFormulation, X <: PM.AbstractPowerModel}
PSI.add_range_constraints!(container, T, U, devices, model, X)
return
end
############################# Energy Constraints ###########################
"""
Min and max limits for Energy Capacity Constraint and AbstractStorageFormulation
"""
function PSI.get_min_max_limits(
d::PSY.Storage,
::Type{StateofChargeLimitsConstraint},
::Type{<:AbstractStorageFormulation},
)
min_max_limits = (
min=PSY.get_storage_level_limits(d).min *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d),
max=PSY.get_storage_level_limits(d).max *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d),
)
return min_max_limits
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{StateofChargeLimitsConstraint},
::Type{PSI.EnergyVariable},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
::PSI.NetworkModel{X},
) where {V <: PSY.Storage, W <: AbstractStorageFormulation, X <: PM.AbstractPowerModel}
PSI.add_range_constraints!(
container,
StateofChargeLimitsConstraint,
PSI.EnergyVariable,
devices,
model,
X,
)
return
end
############################# Add Variable Logic ###########################
function PSI.add_variables!(
container::PSI.OptimizationContainer,
::Type{T},
devices::IS.FlattenIteratorWrapper{U},
formulation::AbstractStorageFormulation,
) where {
T <: Union{AncillaryServiceVariableDischarge, AncillaryServiceVariableCharge},
U <: PSY.Storage,
}
@assert !isempty(devices)
time_steps = PSI.get_time_steps(container)
services = Set()
for d in devices
union!(services, PSY.get_services(d))
end
for service in services
variable = PSI.add_variable_container!(
container,
T(),
U,
PSY.get_name.(devices),
time_steps;
meta="$(typeof(service))_$(PSY.get_name(service))",
)
for d in devices, t in time_steps
name = PSY.get_name(d)
variable[name, t] = JuMP.@variable(
PSI.get_jump_model(container),
base_name = "$(T)_$(PSY.get_name(service))_{$(PSY.get_name(d)), $(t)}",
lower_bound = 0.0,
upper_bound =
PSI.get_variable_upper_bound(T(), service, d, formulation)
)
end
end
return
end
function PSI.add_variables!(
container::PSI.OptimizationContainer,
::Type{T},
devices::IS.FlattenIteratorWrapper{U},
formulation::AbstractStorageFormulation,
) where {
T <: Union{StorageEnergyShortageVariable, StorageEnergySurplusVariable},
U <: PSY.Storage,
}
@assert !isempty(devices)
variable = PSI.add_variable_container!(container, T(), U, PSY.get_name.(devices))
for d in devices
name = PSY.get_name(d)
variable[name] = JuMP.@variable(
PSI.get_jump_model(container),
base_name = "$(T)_{$(PSY.get_name(d))}",
lower_bound = 0.0
)
end
return
end
function PSI.add_variables!(
container::PSI.OptimizationContainer,
::Type{T},
devices::IS.FlattenIteratorWrapper{U},
formulation::AbstractStorageFormulation,
) where {
T <: Union{StorageChargeCyclingSlackVariable, StorageDischargeCyclingSlackVariable},
U <: PSY.Storage,
}
@assert !isempty(devices)
variable = PSI.add_variable_container!(container, T(), U, PSY.get_name.(devices))
for d in devices
name = PSY.get_name(d)
variable[name] = JuMP.@variable(
PSI.get_jump_model(container),
base_name = "$(T)_{$(PSY.get_name(d))}",
lower_bound = 0.0
)
end
return
end
############################# Expression Logic for Ancillary Services ######################
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableCharge},
::Type{ReserveAssignmentBalanceDownCharge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveUp},
) = 0.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableCharge},
::Type{ReserveAssignmentBalanceDownCharge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveDown},
) = 1.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableCharge},
::Type{ReserveAssignmentBalanceUpCharge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveUp},
) = 1.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableCharge},
::Type{ReserveAssignmentBalanceUpCharge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveDown},
) = 0.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableDischarge},
::Type{ReserveAssignmentBalanceDownDischarge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveUp},
) = 0.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableDischarge},
::Type{ReserveAssignmentBalanceDownDischarge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveDown},
) = 1.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableDischarge},
::Type{ReserveAssignmentBalanceUpDischarge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveUp},
) = 1.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableDischarge},
::Type{ReserveAssignmentBalanceUpDischarge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveDown},
) = 0.0
### Deployment ###
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableCharge},
::Type{ReserveDeploymentBalanceDownCharge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveUp},
) = 0.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableCharge},
::Type{ReserveDeploymentBalanceDownCharge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveDown},
) = 1.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableCharge},
::Type{ReserveDeploymentBalanceUpCharge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveUp},
) = 1.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableCharge},
::Type{ReserveDeploymentBalanceUpCharge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveDown},
) = 0.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableDischarge},
::Type{ReserveDeploymentBalanceDownDischarge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveUp},
) = 0.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableDischarge},
::Type{ReserveDeploymentBalanceDownDischarge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveDown},
) = 1.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableDischarge},
::Type{ReserveDeploymentBalanceUpDischarge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveUp},
) = 1.0
PSI.get_variable_multiplier(
::Type{AncillaryServiceVariableDischarge},
::Type{ReserveDeploymentBalanceUpDischarge},
d::PSY.Storage,
::StorageDispatchWithReserves,
::PSY.Reserve{PSY.ReserveDown},
) = 0.0
#! format: off
# Use 1.0 because this is to allow to reuse the code below on add_to_expression
get_fraction(::Type{ReserveAssignmentBalanceUpDischarge}, d::PSY.Reserve) = 1.0
get_fraction(::Type{ReserveAssignmentBalanceUpCharge}, d::PSY.Reserve) = 1.0
get_fraction(::Type{ReserveAssignmentBalanceDownDischarge}, d::PSY.Reserve) = 1.0
get_fraction(::Type{ReserveAssignmentBalanceDownCharge}, d::PSY.Reserve) = 1.0
# Needs to implement served fraction in PSY
get_fraction(::Type{ReserveDeploymentBalanceUpDischarge}, d::PSY.Reserve) = PSY.get_deployed_fraction(d)
get_fraction(::Type{ReserveDeploymentBalanceUpCharge}, d::PSY.Reserve) = PSY.get_deployed_fraction(d)
get_fraction(::Type{ReserveDeploymentBalanceDownDischarge}, d::PSY.Reserve) = PSY.get_deployed_fraction(d)
get_fraction(::Type{ReserveDeploymentBalanceDownCharge}, d::PSY.Reserve) = PSY.get_deployed_fraction(d)
#! format: on
function add_to_expression!(
container::PSI.OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
) where {
T <: StorageReserveChargeExpression,
U <: AncillaryServiceVariableCharge,
V <: PSY.Storage,
W <: StorageDispatchWithReserves,
}
expression = PSI.get_expression(container, T(), V)
for d in devices
name = PSY.get_name(d)
services = PSY.get_services(d)
for s in services
s_name = PSY.get_name(s)
variable = PSI.get_variable(container, U(), V, "$(typeof(s))_$s_name")
mult = PSI.get_variable_multiplier(U, T, d, W(), s) * get_fraction(T, s)
for t in PSI.get_time_steps(container)
PSI._add_to_jump_expression!(expression[name, t], variable[name, t], mult)
end
end
end
return
end
function add_to_expression!(
container::PSI.OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
) where {
T <: StorageReserveDischargeExpression,
U <: AncillaryServiceVariableDischarge,
V <: PSY.Storage,
W <: StorageDispatchWithReserves,
}
expression = PSI.get_expression(container, T(), V)
for d in devices
name = PSY.get_name(d)
services = PSY.get_services(d)
for s in services
s_name = PSY.get_name(s)
variable = PSI.get_variable(container, U(), V, "$(typeof(s))_$s_name")
mult = PSI.get_variable_multiplier(U, T, d, W(), s) * get_fraction(T, s)
for t in PSI.get_time_steps(container)
PSI._add_to_jump_expression!(expression[name, t], variable[name, t], mult)
end
end
end
return
end
function add_to_expression!(
container::PSI.OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, W},
) where {
T <: TotalReserveOffering,
U <: Union{AncillaryServiceVariableDischarge, AncillaryServiceVariableCharge},
V <: PSY.Storage,
W <: StorageDispatchWithReserves,
}
for d in devices
name = PSY.get_name(d)
services = PSY.get_services(d)
for s in services
s_name = PSY.get_name(s)
expression = PSI.get_expression(container, T(), V, "$(typeof(s))_$(s_name)")
variable = PSI.get_variable(container, U(), V, "$(typeof(s))_$s_name")
for t in PSI.get_time_steps(container)
PSI._add_to_jump_expression!(expression[name, t], variable[name, t], 1.0)
end
end
end
return
end
function PSI.add_to_expression!(
container::PSI.OptimizationContainer,
::Type{T},
::Type{U},
devices::Vector{UV},
service_model::PSI.ServiceModel{V, W},
) where {
T <: TotalReserveOffering,
U <: PSI.ActivePowerReserveVariable,
UV <: PSY.Storage,
V <: PSY.Reserve,
W <: PSI.AbstractReservesFormulation,
}
for d in devices
name = PSY.get_name(d)
s_name = PSI.get_service_name(service_model)
expression = PSI.get_expression(container, T(), UV, "$(V)_$(s_name)")
variable = PSI.get_variable(container, U(), V, s_name)
for t in PSI.get_time_steps(container)
PSI._add_to_jump_expression!(expression[name, t], variable[name, t], -1.0)
end
end
return
end
"""
Add Energy Balance Constraints for AbstractStorageFormulation
"""
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{PSI.EnergyBalanceConstraint},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.Storage, X <: PM.AbstractPowerModel}
if PSI.has_service_model(model)
add_energybalance_with_reserves!(container, devices, model, network_model)
else
add_energybalance_without_reserves!(container, devices, model, network_model)
end
end
function add_energybalance_with_reserves!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.Storage, X <: PM.AbstractPowerModel}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
names = [PSY.get_name(x) for x in devices]
initial_conditions = PSI.get_initial_condition(container, PSI.InitialEnergyLevel(), V)
energy_var = PSI.get_variable(container, PSI.EnergyVariable(), V)
powerin_var = PSI.get_variable(container, PSI.ActivePowerInVariable(), V)
powerout_var = PSI.get_variable(container, PSI.ActivePowerOutVariable(), V)
r_up_ds = PSI.get_expression(container, ReserveDeploymentBalanceUpDischarge(), V)
r_up_ch = PSI.get_expression(container, ReserveDeploymentBalanceUpCharge(), V)
r_dn_ds = PSI.get_expression(container, ReserveDeploymentBalanceDownDischarge(), V)
r_dn_ch = PSI.get_expression(container, ReserveDeploymentBalanceDownCharge(), V)
constraint = PSI.add_constraints_container!(
container,
PSI.EnergyBalanceConstraint(),
V,
names,
time_steps,
)
for ic in initial_conditions
device = PSI.get_component(ic)
efficiency = PSY.get_efficiency(device)
name = PSY.get_name(device)
constraint[name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
energy_var[name, 1] ==
PSI.get_value(ic) +
(
(
(powerin_var[name, 1] + r_dn_ch[name, 1] - r_up_ch[name, 1]) *
efficiency.in
) - (
(powerout_var[name, 1] + r_up_ds[name, 1] - r_dn_ds[name, 1]) /
efficiency.out
)
) * fraction_of_hour
)
for t in time_steps[2:end]
constraint[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
energy_var[name, t] ==
energy_var[name, t - 1] +
(
(
(powerin_var[name, t] + r_dn_ch[name, t] - r_up_ch[name, t]) *
efficiency.in
) - (
(powerout_var[name, t] + r_up_ds[name, t] - r_dn_ds[name, t]) /
efficiency.out
)
) * fraction_of_hour
)
end
end
return
end
function add_energybalance_without_reserves!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.Storage, X <: PM.AbstractPowerModel}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
names = [PSY.get_name(x) for x in devices]
initial_conditions = PSI.get_initial_condition(container, PSI.InitialEnergyLevel(), V)
energy_var = PSI.get_variable(container, PSI.EnergyVariable(), V)
powerin_var = PSI.get_variable(container, PSI.ActivePowerInVariable(), V)
powerout_var = PSI.get_variable(container, PSI.ActivePowerOutVariable(), V)
constraint = PSI.add_constraints_container!(
container,
PSI.EnergyBalanceConstraint(),
V,
names,
time_steps,
)
for ic in initial_conditions
device = PSI.get_component(ic)
efficiency = PSY.get_efficiency(device)
name = PSY.get_name(device)
constraint[name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
energy_var[name, 1] ==
PSI.get_value(ic) +
(
(powerin_var[name, 1] * efficiency.in) -
(powerout_var[name, 1] / efficiency.out)
) * fraction_of_hour
)
for t in time_steps[2:end]
constraint[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
energy_var[name, t] ==
energy_var[name, t - 1] +
(
(powerin_var[name, t] * efficiency.in) -
(powerout_var[name, t] / efficiency.out)
) * fraction_of_hour
)
end
end
return
end
"""
Add Energy Balance Constraints for AbstractStorageFormulation
"""
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{ReserveDischargeConstraint},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.Storage, X <: PM.AbstractPowerModel}
names = String[PSY.get_name(x) for x in devices]
time_steps = PSI.get_time_steps(container)
powerout_var = PSI.get_variable(container, PSI.ActivePowerOutVariable(), V)
r_up_ds = PSI.get_expression(container, ReserveAssignmentBalanceUpDischarge(), V)
r_dn_ds = PSI.get_expression(container, ReserveAssignmentBalanceDownDischarge(), V)
constraint_ds_ub = PSI.add_constraints_container!(
container,
ReserveDischargeConstraint(),
V,
names,
time_steps,
meta="ub",
)
constraint_ds_lb = PSI.add_constraints_container!(
container,
ReserveDischargeConstraint(),
V,
names,
time_steps,
meta="lb",
)
for d in devices, t in time_steps
name = PSY.get_name(d)
constraint_ds_ub[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerout_var[name, t] + r_up_ds[name, t] <=
PSY.get_output_active_power_limits(d).max
)
constraint_ds_lb[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerout_var[name, t] - r_dn_ds[name, t] >=
PSY.get_output_active_power_limits(d).min
)
end
return
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{ReserveChargeConstraint},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.Storage, X <: PM.AbstractPowerModel}
names = String[PSY.get_name(x) for x in devices]
time_steps = PSI.get_time_steps(container)
powerin_var = PSI.get_variable(container, PSI.ActivePowerInVariable(), V)
r_up_ch = PSI.get_expression(container, ReserveAssignmentBalanceUpCharge(), V)
r_dn_ch = PSI.get_expression(container, ReserveAssignmentBalanceDownCharge(), V)
constraint_ch_ub = PSI.add_constraints_container!(
container,
ReserveChargeConstraint(),
V,
names,
time_steps,
meta="ub",
)
constraint_ch_lb = PSI.add_constraints_container!(
container,
ReserveChargeConstraint(),
V,
names,
time_steps,
meta="lb",
)
for d in devices, t in PSI.get_time_steps(container)
name = PSY.get_name(d)
constraint_ch_ub[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerin_var[name, t] + r_dn_ch[name, t] <=
PSY.get_input_active_power_limits(d).max
)
constraint_ch_lb[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerin_var[name, t] - r_up_ch[name, t] >=
PSY.get_input_active_power_limits(d).min
)
end
return
end
time_offset(::Type{ReserveCoverageConstraint}) = -1
time_offset(::Type{ReserveCoverageConstraintEndOfPeriod}) = 0
time_offset(::Type{ReserveCompleteCoverageConstraint}) = -1
time_offset(::Type{ReserveCompleteCoverageConstraintEndOfPeriod}) = 0
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{T},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {
T <: Union{ReserveCoverageConstraint, ReserveCoverageConstraintEndOfPeriod},
V <: PSY.Storage,
X <: PM.AbstractPowerModel,
}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
names = [PSY.get_name(x) for x in devices]
initial_conditions = PSI.get_initial_condition(container, PSI.InitialEnergyLevel(), V)
energy_var = PSI.get_variable(container, PSI.EnergyVariable(), V)
services_set = Set()
for ic in initial_conditions
storage = PSI.get_component(ic)
union!(services_set, PSY.get_services(storage))
end
for service in services_set
service_name = PSY.get_name(service)
if typeof(service) <: PSY.Reserve{PSY.ReserveUp}
PSI.add_constraints_container!(
container,
T(),
V,
names,
time_steps,
meta="$(typeof(service))_$(service_name)_discharge",
)
elseif typeof(service) <: PSY.Reserve{PSY.ReserveDown}
PSI.add_constraints_container!(
container,
T(),
V,
names,
time_steps,
meta="$(typeof(service))_$(service_name)_charge",
)
end
end
for ic in initial_conditions
storage = PSI.get_component(ic)
ci_name = PSY.get_name(storage)
inv_efficiency = 1.0 / PSY.get_efficiency(storage).out
eff_in = PSY.get_efficiency(storage).in
soc_limits = (
min=PSY.get_storage_level_limits(storage).min *
PSY.get_storage_capacity(storage) *
PSY.get_conversion_factor(storage),
max=PSY.get_storage_level_limits(storage).max *
PSY.get_storage_capacity(storage) *
PSY.get_conversion_factor(storage),
)
for service in PSY.get_services(storage)
sustained_time = PSY.get_sustained_time(service)
num_periods = sustained_time / Dates.value(Dates.Second(resolution))
sustained_param_discharge = inv_efficiency * fraction_of_hour * num_periods
sustained_param_charge = eff_in * fraction_of_hour * num_periods
service_name = PSY.get_name(service)
reserve_var_discharge = PSI.get_variable(
container,
AncillaryServiceVariableDischarge(),
V,
"$(typeof(service))_$service_name",
)
reserve_var_charge = PSI.get_variable(
container,
AncillaryServiceVariableCharge(),
V,
"$(typeof(service))_$service_name",
)
if typeof(service) <: PSY.Reserve{PSY.ReserveUp}
con_discharge = PSI.get_constraint(
container,
T(),
V,
"$(typeof(service))_$(service_name)_discharge",
)
if time_offset(T) == -1
con_discharge[ci_name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
sustained_param_discharge * reserve_var_discharge[ci_name, 1] <=
PSI.get_value(ic) - soc_limits.min
)
elseif time_offset(T) == 0
con_discharge[ci_name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
sustained_param_discharge * reserve_var_discharge[ci_name, 1] <=
energy_var[ci_name, 1] - soc_limits.min
)
else
@assert false
end
for t in time_steps[2:end]
con_discharge[ci_name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
sustained_param_discharge * reserve_var_discharge[ci_name, t] <=
energy_var[ci_name, t + time_offset(T)] - soc_limits.min
)
end
elseif typeof(service) <: PSY.Reserve{PSY.ReserveDown}
con_charge = PSI.get_constraint(
container,
T(),
V,
"$(typeof(service))_$(service_name)_charge",
)
if time_offset(T) == -1
con_charge[ci_name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
sustained_param_charge * reserve_var_charge[ci_name, 1] <=
soc_limits.max - PSI.get_value(ic)
)
elseif time_offset(T) == 0
con_charge[ci_name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
sustained_param_charge * reserve_var_charge[ci_name, 1] <=
soc_limits.max - energy_var[ci_name, 1]
)
else
@assert false
end
for t in time_steps[2:end]
con_charge[ci_name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
sustained_param_charge * reserve_var_charge[ci_name, t] <=
soc_limits.max - energy_var[ci_name, t + time_offset(T)]
)
end
else
@assert false
end
end
end
return
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{T},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {
T <:
Union{ReserveCompleteCoverageConstraint, ReserveCompleteCoverageConstraintEndOfPeriod},
V <: PSY.Storage,
X <: PM.AbstractPowerModel,
}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
names = [PSY.get_name(x) for x in devices]
initial_conditions = PSI.get_initial_condition(container, PSI.InitialEnergyLevel(), V)
energy_var = PSI.get_variable(container, PSI.EnergyVariable(), V)
services_set = Set()
for ic in initial_conditions
storage = PSI.get_component(ic)
union!(services_set, PSY.get_services(storage))
end
services_types = unique(typeof.(services_set))
for serv_type in services_types
if serv_type <: PSY.Reserve{PSY.ReserveUp}
PSI.add_constraints_container!(
container,
T(),
V,
names,
time_steps,
meta="$(serv_type)_discharge",
)
elseif serv_type <: PSY.Reserve{PSY.ReserveDown}
PSI.add_constraints_container!(
container,
T(),
V,
names,
time_steps,
meta="$(serv_type)_charge",
)
end
end
for ic in initial_conditions
storage = PSI.get_component(ic)
ci_name = PSY.get_name(storage)
inv_efficiency = 1.0 / PSY.get_efficiency(storage).out
eff_in = PSY.get_efficiency(storage).in
soc_limits = (
min=PSY.get_storage_level_limits(storage).min *
PSY.get_storage_capacity(storage) *
PSY.get_conversion_factor(storage),
max=PSY.get_storage_level_limits(storage).max *
PSY.get_storage_capacity(storage) *
PSY.get_conversion_factor(storage),
)
expr_up_discharge = Set()
expr_dn_charge = Set()
for service in PSY.get_services(storage)
sustained_time = PSY.get_sustained_time(service)
num_periods = sustained_time / Dates.value(Dates.Second(resolution))
sustained_param_discharge = inv_efficiency * fraction_of_hour * num_periods
sustained_param_charge = eff_in * fraction_of_hour * num_periods
service_name = PSY.get_name(service)
reserve_var_discharge = PSI.get_variable(
container,
AncillaryServiceVariableDischarge(),
V,
"$(typeof(service))_$service_name",
)
reserve_var_charge = PSI.get_variable(
container,
AncillaryServiceVariableCharge(),
V,
"$(typeof(service))_$service_name",
)
if typeof(service) <: PSY.Reserve{PSY.ReserveUp}
push!(
expr_up_discharge,
sustained_param_discharge * reserve_var_discharge[ci_name, :],
)
elseif typeof(service) <: PSY.Reserve{PSY.ReserveDown}
push!(
expr_dn_charge,
sustained_param_charge * reserve_var_charge[ci_name, :],
)
else
@assert false
end
end
for serv_type in services_types
if serv_type <: PSY.Reserve{PSY.ReserveUp}
con_discharge =
PSI.get_constraint(container, T(), V, "$(serv_type)_discharge")
total_sustained = JuMP.AffExpr()
for vds in expr_up_discharge
JuMP.add_to_expression!(total_sustained, vds[1])
end
if time_offset(T) == -1
con_discharge[ci_name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
total_sustained <= PSI.get_value(ic) - soc_limits.min
)
elseif time_offset(T) == 0
con_discharge[ci_name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
total_sustained <= energy_var[ci_name, 1] - soc_limits.min
)
else
@assert false
end
for t in time_steps[2:end]
total_sustained = JuMP.AffExpr()
for vds in expr_up_discharge
JuMP.add_to_expression!(total_sustained, vds[t])
end
con_discharge[ci_name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
total_sustained <=
energy_var[ci_name, t + time_offset(T)] - soc_limits.min
)
end
elseif serv_type <: PSY.Reserve{PSY.ReserveDown}
con_charge = PSI.get_constraint(container, T(), V, "$(serv_type)_charge")
total_sustained = JuMP.AffExpr()
for vch in expr_dn_charge
JuMP.add_to_expression!(total_sustained, vch[1])
end
if time_offset(T) == -1
con_charge[ci_name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
total_sustained <= soc_limits.max - PSI.get_value(ic)
)
elseif time_offset(T) == 0
con_charge[ci_name, 1] = JuMP.@constraint(
PSI.get_jump_model(container),
total_sustained <= soc_limits.max - energy_var[ci_name, 1]
)
else
@assert false
end
for t in time_steps[2:end]
total_sustained = JuMP.AffExpr()
for vch in expr_dn_charge
JuMP.add_to_expression!(total_sustained, vch[t])
end
con_charge[ci_name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
total_sustained <=
soc_limits.max - energy_var[ci_name, t + time_offset(T)]
)
end
else
@assert false
end
end
end
return
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{StorageTotalReserveConstraint},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.Storage, X <: PM.AbstractPowerModel}
services = Set()
for d in devices
union!(services, PSY.get_services(d))
end
for s in services
s_name = PSY.get_name(s)
expression = PSI.get_expression(
container,
TotalReserveOffering(),
V,
"$(typeof(s))_$(s_name)",
)
device_names, time_steps = axes(expression)
constraint_container = PSI.add_constraints_container!(
container,
StorageTotalReserveConstraint(),
typeof(s),
device_names,
time_steps,
meta="$(s_name)_$V",
)
for name in device_names, t in time_steps
constraint_container[name, t] =
JuMP.@constraint(PSI.get_jump_model(container), expression[name, t] == 0.0)
end
end
return
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{StateofChargeTargetConstraint},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.EnergyReservoirStorage, X <: PM.AbstractPowerModel}
energy_var = PSI.get_variable(container, PSI.EnergyVariable(), V)
surplus_var = PSI.get_variable(container, StorageEnergySurplusVariable(), V)
shortfall_var = PSI.get_variable(container, StorageEnergyShortageVariable(), V)
device_names, time_steps = axes(energy_var)
constraint_container = PSI.add_constraints_container!(
container,
StateofChargeTargetConstraint(),
V,
device_names,
)
for d in devices
name = PSY.get_name(d)
target = PSY.get_storage_target(d)
constraint_container[name] = JuMP.@constraint(
PSI.get_jump_model(container),
energy_var[name, time_steps[end]] - surplus_var[name] + shortfall_var[name] == target
)
end
return
end
function add_cycling_charge_without_reserves!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{V},
::PSI.DeviceModel{V, StorageDispatchWithReserves},
::PSI.NetworkModel{X},
) where {V <: PSY.EnergyReservoirStorage, X <: PM.AbstractPowerModel}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
names = [PSY.get_name(x) for x in devices]
powerin_var = PSI.get_variable(container, PSI.ActivePowerInVariable(), V)
slack_var = PSI.get_variable(container, StorageChargeCyclingSlackVariable(), V)
constraint = PSI.add_constraints_container!(container, StorageCyclingCharge(), V, names)
for d in devices
name = PSY.get_name(d)
e_max =
PSY.get_storage_level_limits(d).max *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d)
cycle_count = PSY.get_cycle_limits(d)
efficiency = PSY.get_efficiency(d)
constraint[name] = JuMP.@constraint(
PSI.get_jump_model(container),
sum((
powerin_var[name, t] * efficiency.in * fraction_of_hour for t in time_steps
)) - slack_var[name] <= e_max * cycle_count
)
end
return
end
function add_cycling_charge_with_reserves!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{V},
::PSI.DeviceModel{V, StorageDispatchWithReserves},
::PSI.NetworkModel{X},
) where {V <: PSY.EnergyReservoirStorage, X <: PM.AbstractPowerModel}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
names = [PSY.get_name(x) for x in devices]
powerin_var = PSI.get_variable(container, PSI.ActivePowerInVariable(), V)
slack_var = PSI.get_variable(container, StorageChargeCyclingSlackVariable(), V)
r_dn_ch = PSI.get_expression(container, ReserveDeploymentBalanceDownCharge(), V)
constraint = PSI.add_constraints_container!(container, StorageCyclingCharge(), V, names)
for d in devices
name = PSY.get_name(d)
e_max =
PSY.get_storage_level_limits(d).max *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d)
cycle_count = PSY.get_cycle_limits(d)
efficiency = PSY.get_efficiency(d)
constraint[name] = JuMP.@constraint(
PSI.get_jump_model(container),
sum((
(powerin_var[name, t] + r_dn_ch[name, t]) *
efficiency.in *
fraction_of_hour for t in time_steps
)) - slack_var[name] <= e_max * cycle_count
)
end
return
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{StorageCyclingCharge},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.EnergyReservoirStorage, X <: PM.AbstractPowerModel}
if PSI.has_service_model(model)
add_cycling_charge_with_reserves!(container, devices, model, network_model)
else
add_cycling_charge_without_reserves!(container, devices, model, network_model)
end
return
end
function add_cycling_discharge_without_reserves!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{V},
::PSI.DeviceModel{V, StorageDispatchWithReserves},
::PSI.NetworkModel{X},
) where {V <: PSY.EnergyReservoirStorage, X <: PM.AbstractPowerModel}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
names = [PSY.get_name(x) for x in devices]
powerout_var = PSI.get_variable(container, PSI.ActivePowerOutVariable(), V)
slack_var = PSI.get_variable(container, StorageDischargeCyclingSlackVariable(), V)
constraint =
PSI.add_constraints_container!(container, StorageCyclingDischarge(), V, names)
for d in devices
name = PSY.get_name(d)
e_max =
PSY.get_storage_level_limits(d).max *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d)
cycle_count = PSY.get_cycle_limits(d)
efficiency = PSY.get_efficiency(d)
constraint[name] = JuMP.@constraint(
PSI.get_jump_model(container),
sum(
(powerout_var[name, t] / efficiency.out) * fraction_of_hour for
t in time_steps
) - slack_var[name] <= e_max * cycle_count
)
end
return
end
function add_cycling_discharge_with_reserves!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{V},
::PSI.DeviceModel{V, StorageDispatchWithReserves},
::PSI.NetworkModel{X},
) where {V <: PSY.EnergyReservoirStorage, X <: PM.AbstractPowerModel}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
names = [PSY.get_name(x) for x in devices]
powerout_var = PSI.get_variable(container, PSI.ActivePowerOutVariable(), V)
slack_var = PSI.get_variable(container, StorageDischargeCyclingSlackVariable(), V)
r_up_ds = PSI.get_expression(container, ReserveDeploymentBalanceUpDischarge(), V)
constraint =
PSI.add_constraints_container!(container, StorageCyclingDischarge(), V, names)
for d in devices
name = PSY.get_name(d)
e_max =
PSY.get_storage_level_limits(d).max *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d)
cycle_count = PSY.get_cycle_limits(d)
efficiency = PSY.get_efficiency(d)
constraint[name] = JuMP.@constraint(
PSI.get_jump_model(container),
sum(
((powerout_var[name, t] + r_up_ds[name, t]) / efficiency.out) *
fraction_of_hour for t in time_steps
) - slack_var[name] <= e_max * cycle_count
)
end
return
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{StorageCyclingDischarge},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.EnergyReservoirStorage, X <: PM.AbstractPowerModel}
if PSI.has_service_model(model)
add_cycling_discharge_with_reserves!(container, devices, model, network_model)
else
add_cycling_discharge_without_reserves!(container, devices, model, network_model)
end
return
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{StorageRegularizationConstraintCharge},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.Storage, X <: PM.AbstractPowerModel}
names = [PSY.get_name(x) for x in devices]
time_steps = PSI.get_time_steps(container)
reg_var = PSI.get_variable(container, StorageRegularizationVariableCharge(), V)
powerin_var = PSI.get_variable(container, PSI.ActivePowerInVariable(), V)
has_services = PSI.has_service_model(model)
if has_services
r_up_ch = PSI.get_expression(container, ReserveDeploymentBalanceUpCharge(), V)
r_dn_ch = PSI.get_expression(container, ReserveDeploymentBalanceDownCharge(), V)
end
constraint_ub = PSI.add_constraints_container!(
container,
StorageRegularizationConstraintCharge(),
V,
names,
time_steps,
meta="ub",
)
constraint_lb = PSI.add_constraints_container!(
container,
StorageRegularizationConstraintCharge(),
V,
names,
time_steps,
meta="lb",
)
for d in devices
name = PSY.get_name(d)
constraint_ub[name, 1] =
JuMP.@constraint(PSI.get_jump_model(container), reg_var[name, 1] == 0)
constraint_lb[name, 1] =
JuMP.@constraint(PSI.get_jump_model(container), reg_var[name, 1] == 0)
for t in time_steps[2:end]
if has_services
constraint_ub[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
(
powerin_var[name, t - 1] + r_dn_ch[name, t - 1] -
r_up_ch[name, t - 1]
) - (powerin_var[name, t] + r_dn_ch[name, t] - r_up_ch[name, t]) <=
reg_var[name, t]
)
constraint_lb[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
(
powerin_var[name, t - 1] + r_dn_ch[name, t - 1] -
r_up_ch[name, t - 1]
) - (powerin_var[name, t] + r_dn_ch[name, t] - r_up_ch[name, t]) >=
-reg_var[name, t]
)
else
constraint_ub[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerin_var[name, t - 1] - powerin_var[name, t] <= reg_var[name, t]
)
constraint_lb[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerin_var[name, t - 1] - powerin_var[name, t] >= -reg_var[name, t]
)
end
end
end
return
end
function PSI.add_constraints!(
container::PSI.OptimizationContainer,
::Type{StorageRegularizationConstraintDischarge},
devices::IS.FlattenIteratorWrapper{V},
model::PSI.DeviceModel{V, StorageDispatchWithReserves},
network_model::PSI.NetworkModel{X},
) where {V <: PSY.Storage, X <: PM.AbstractPowerModel}
names = [PSY.get_name(x) for x in devices]
time_steps = PSI.get_time_steps(container)
reg_var = PSI.get_variable(container, StorageRegularizationVariableDischarge(), V)
powerout_var = PSI.get_variable(container, PSI.ActivePowerOutVariable(), V)
has_services = PSI.has_service_model(model)
if has_services
r_up_ds = PSI.get_expression(container, ReserveDeploymentBalanceUpDischarge(), V)
r_dn_ds = PSI.get_expression(container, ReserveDeploymentBalanceDownDischarge(), V)
end
constraint_ub = PSI.add_constraints_container!(
container,
StorageRegularizationConstraintDischarge(),
V,
names,
time_steps,
meta="ub",
)
constraint_lb = PSI.add_constraints_container!(
container,
StorageRegularizationConstraintDischarge(),
V,
names,
time_steps,
meta="lb",
)
for d in devices
name = PSY.get_name(d)
constraint_ub[name, 1] =
JuMP.@constraint(PSI.get_jump_model(container), reg_var[name, 1] == 0)
constraint_lb[name, 1] =
JuMP.@constraint(PSI.get_jump_model(container), reg_var[name, 1] == 0)
for t in time_steps[2:end]
if has_services
constraint_ub[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
(
powerout_var[name, t - 1] + r_up_ds[name, t - 1] -
r_dn_ds[name, t - 1]
) - (powerout_var[name, t] + r_up_ds[name, t] - r_dn_ds[name, t]) <=
reg_var[name, t]
)
constraint_lb[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
(
powerout_var[name, t - 1] + r_up_ds[name, t - 1] -
r_dn_ds[name, t - 1]
) - (powerout_var[name, t] + r_up_ds[name, t] - r_dn_ds[name, t]) >=
-reg_var[name, t]
)
else
constraint_ub[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerout_var[name, t - 1] - powerout_var[name, t] <= reg_var[name, t]
)
constraint_lb[name, t] = JuMP.@constraint(
PSI.get_jump_model(container),
powerout_var[name, t - 1] - powerout_var[name, t] >= -reg_var[name, t]
)
end
end
end
return
end
########################### Objective Function and Costs ######################
function PSI.objective_function!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{T},
model::PSI.DeviceModel{T, U},
::Type{V},
) where {T <: PSY.Storage, U <: AbstractStorageFormulation, V <: PM.AbstractPowerModel}
PSI.add_variable_cost!(container, PSI.ActivePowerOutVariable(), devices, U())
PSI.add_variable_cost!(container, PSI.ActivePowerInVariable(), devices, U())
if PSI.get_attribute(model, "regularization")
PSI.add_variable_cost!(
container,
StorageRegularizationVariableCharge(),
devices,
U(),
)
PSI.add_variable_cost!(
container,
StorageRegularizationVariableDischarge(),
devices,
U(),
)
end
return
end
function PSI.objective_function!(
container::PSI.OptimizationContainer,
devices::IS.FlattenIteratorWrapper{PSY.EnergyReservoirStorage},
model::PSI.DeviceModel{PSY.EnergyReservoirStorage, T},
::Type{V},
) where {T <: AbstractStorageFormulation, V <: PM.AbstractPowerModel}
PSI.add_variable_cost!(container, PSI.ActivePowerOutVariable(), devices, T())
PSI.add_variable_cost!(container, PSI.ActivePowerInVariable(), devices, T())
if PSI.get_attribute(model, "energy_target")
PSI.add_proportional_cost!(container, StorageEnergySurplusVariable(), devices, T())
PSI.add_proportional_cost!(container, StorageEnergyShortageVariable(), devices, T())
end
if PSI.get_attribute(model, "cycling_limits")
PSI.add_proportional_cost!(
container,
StorageChargeCyclingSlackVariable(),
devices,
T(),
)
PSI.add_proportional_cost!(
container,
StorageDischargeCyclingSlackVariable(),
devices,
T(),
)
end
if PSI.get_attribute(model, "regularization")
PSI.add_variable_cost!(
container,
StorageRegularizationVariableCharge(),
devices,
T(),
)
PSI.add_variable_cost!(
container,
StorageRegularizationVariableDischarge(),
devices,
T(),
)
end
return
end
function PSI.add_proportional_cost!(
container::PSI.OptimizationContainer,
::T,
devices::IS.FlattenIteratorWrapper{U},
formulation::AbstractStorageFormulation,
) where {
T <: Union{StorageChargeCyclingSlackVariable, StorageDischargeCyclingSlackVariable},
U <: PSY.EnergyReservoirStorage,
}
variable = PSI.get_variable(container, T(), U)
for d in devices
name = PSY.get_name(d)
op_cost_data = PSY.get_operation_cost(d)
cost_term = PSI.proportional_cost(op_cost_data, T(), d, formulation)
PSI.add_to_objective_invariant_expression!(container, variable[name] * cost_term)
end
end
function PSI.add_proportional_cost!(
container::PSI.OptimizationContainer,
::T,
devices::IS.FlattenIteratorWrapper{U},
formulation::AbstractStorageFormulation,
) where {
T <: Union{StorageEnergyShortageVariable, StorageEnergySurplusVariable},
U <: PSY.EnergyReservoirStorage,
}
variable = PSI.get_variable(container, T(), U)
for d in devices
name = PSY.get_name(d)
op_cost_data = PSY.get_operation_cost(d)
cost_term = PSI.proportional_cost(op_cost_data, T(), d, formulation)
PSI.add_to_objective_invariant_expression!(container, variable[name] * cost_term)
end
end
########################### Auxiliary Variables ######################
function PSI.update_decision_state!(
state::PSI.SimulationState,
key::PSI.AuxVarKey{StorageEnergyOutput, T},
store_data::PSI.DenseAxisArray{Float64, 2},
simulation_time::Dates.DateTime,
model_params::PSI.ModelStoreParams,
) where {T <: PSY.Component}
state_data = PSI.get_decision_state_data(state, key)
model_resolution = PSI.get_resolution(model_params)
state_resolution = PSI.get_data_resolution(state_data)
resolution_ratio = model_resolution ÷ state_resolution
state_timestamps = state_data.timestamps
IS.@assert_op resolution_ratio >= 1
if simulation_time > PSI.get_end_of_step_timestamp(state_data)
state_data_index = 1
state_data.timestamps[:] .= range(
simulation_time;
step=state_resolution,
length=PSI.get_num_rows(state_data),
)
else
state_data_index = PSI.find_timestamp_index(state_timestamps, simulation_time)
end
offset = resolution_ratio - 1
result_time_index = axes(store_data)[2]
PSI.set_update_timestamp!(state_data, simulation_time)
column_names = axes(state_data.values)[1]
for t in result_time_index
state_range = state_data_index:(state_data_index + offset)
for name in column_names, i in state_range
state_data.values[name, i] = store_data[name, t] / resolution_ratio
end
PSI.set_last_recorded_row!(state_data, state_range[end])
state_data_index += resolution_ratio
end
return
end
function PSI.calculate_aux_variable_value!(
container::PSI.OptimizationContainer,
::PSI.AuxVarKey{StorageEnergyOutput, T},
system::PSY.System,
) where {T <: PSY.Storage}
time_steps = PSI.get_time_steps(container)
resolution = PSI.get_resolution(container)
fraction_of_hour = Dates.value(Dates.Minute(resolution)) / PSI.MINUTES_IN_HOUR
p_variable_results = PSI.get_variable(container, PSI.ActivePowerOutVariable(), T)
aux_variable_container = PSI.get_aux_variable(container, StorageEnergyOutput(), T)
device_names = axes(aux_variable_container, 1)
for name in device_names, t in time_steps
aux_variable_container[name, t] =
PSI.jump_value(p_variable_results[name, t]) * fraction_of_hour
end
return
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 1069 | ### Define Constraints using PSI.ConstraintType ###
# Constraints taken from PSI
# OutputActivePowerVariableLimitsConstraint
# InputActivePowerVariableLimitsConstraint
# EnergyBalanceConstraint
struct StateofChargeTargetConstraint <: PSI.ConstraintType end
struct StateofChargeLimitsConstraint <: PSI.ConstraintType end
struct StorageCyclingCharge <: PSI.ConstraintType end
struct StorageCyclingDischarge <: PSI.ConstraintType end
## AS Provision Energy Constraints
struct ReserveDischargeConstraint <: PSI.ConstraintType end
struct ReserveChargeConstraint <: PSI.ConstraintType end
struct ReserveCoverageConstraint <: PSI.ConstraintType end
struct ReserveCoverageConstraintEndOfPeriod <: PSI.ConstraintType end
struct ReserveCompleteCoverageConstraint <: PSI.ConstraintType end
struct ReserveCompleteCoverageConstraintEndOfPeriod <: PSI.ConstraintType end
struct StorageTotalReserveConstraint <: PSI.ConstraintType end
struct StorageRegularizationConstraintCharge <: PSI.ConstraintType end
struct StorageRegularizationConstraintDischarge <: PSI.ConstraintType end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 56 | const CYCLE_VIOLATION_COST = 5e3
const REG_COST = 0.001
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 1083 | struct TotalReserveOffering <: PSI.ExpressionType end
abstract type StorageReserveDischargeExpression <: PSI.ExpressionType end
abstract type StorageReserveChargeExpression <: PSI.ExpressionType end
# Used for the Power Limits constraints
struct ReserveAssignmentBalanceUpDischarge <: StorageReserveDischargeExpression end
struct ReserveAssignmentBalanceUpCharge <: StorageReserveChargeExpression end
struct ReserveAssignmentBalanceDownDischarge <: StorageReserveDischargeExpression end
struct ReserveAssignmentBalanceDownCharge <: StorageReserveChargeExpression end
# Used for the SoC estimates
struct ReserveDeploymentBalanceUpDischarge <: StorageReserveDischargeExpression end
struct ReserveDeploymentBalanceUpCharge <: StorageReserveChargeExpression end
struct ReserveDeploymentBalanceDownDischarge <: StorageReserveDischargeExpression end
struct ReserveDeploymentBalanceDownCharge <: StorageReserveChargeExpression end
should_write_resulting_value(::Type{StorageReserveDischargeExpression}) = true
should_write_resulting_value(::Type{StorageReserveChargeExpression}) = true
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 13205 | """
Adds a constraint to enforce a minimum energy level target with a slack variable associated witha penalty term.
"""
struct EnergyTargetFeedforward <: PSI.AbstractAffectFeedforward
optimization_container_key::PSI.OptimizationContainerKey
affected_values::Vector{<:PSI.OptimizationContainerKey}
target_period::Int
penalty_cost::Float64
function EnergyTargetFeedforward(;
component_type::Type{<:PSY.Component},
source::Type{T},
affected_values::Vector{DataType},
target_period::Int,
penalty_cost::Float64,
meta=ISOPT.CONTAINER_KEY_EMPTY_META,
) where {T}
values_vector = Vector{PSI.VariableKey}(undef, length(affected_values))
for (ix, v) in enumerate(affected_values)
if v <: PSI.VariableType
values_vector[ix] =
PSI.get_optimization_container_key(v(), component_type, meta)
else
error(
"EnergyTargetFeedforward is only compatible with VariableType or ParamterType affected values",
)
end
end
new(
PSI.get_optimization_container_key(T(), component_type, meta),
values_vector,
target_period,
penalty_cost,
)
end
end
PSI.get_default_parameter_type(::EnergyTargetFeedforward, _) = EnergyTargetParameter
PSI.get_optimization_container_key(ff::EnergyTargetFeedforward) =
ff.optimization_container_key
function PSI._add_feedforward_arguments!(
container::PSI.OptimizationContainer,
model::PSI.DeviceModel,
devices::IS.FlattenIteratorWrapper{T},
ff::EnergyTargetFeedforward,
) where {T <: PSY.Storage}
parameter_type = PSI.get_default_parameter_type(ff, T)
PSI.add_parameters!(container, parameter_type, ff, model, devices)
# Enabling this FF requires the addition of an extra variable
PSI.add_variables!(
container,
StorageEnergyShortageVariable,
devices,
PSI.get_formulation(model)(),
)
return
end
@doc raw"""
add_feedforward_constraints(
container::OptimizationContainer,
::DeviceModel,
devices::IS.FlattenIteratorWrapper{T},
ff::EnergyTargetFeedforward,
) where {T <: PSY.Component}
Constructs a equality constraint to a fix a variable in one model using the variable value from other model results.
``` variable[var_name, t] + slack[var_name, t] >= param[var_name, t] ```
# LaTeX
`` x + slack >= param``
# Arguments
* container::OptimizationContainer : the optimization_container model built in PowerSimulations
* model::DeviceModel : the device model
* devices::IS.FlattenIteratorWrapper{T} : list of devices
* ff::EnergyTargetFeedforward : a instance of the EnergyTarget Feedforward
"""
function PSI.add_feedforward_constraints!(
container::PSI.OptimizationContainer,
::PSI.DeviceModel{T, U},
devices::IS.FlattenIteratorWrapper{T},
ff::EnergyTargetFeedforward,
) where {T <: PSY.Storage, U <: AbstractStorageFormulation}
time_steps = PSI.get_time_steps(container)
parameter_type = PSI.get_default_parameter_type(ff, T)
param = PSI.get_parameter_array(container, parameter_type(), T)
multiplier = PSI.get_parameter_multiplier_array(container, parameter_type(), T)
target_period = ff.target_period
penalty_cost = ff.penalty_cost
for var in PSI.get_affected_values(ff)
variable = PSI.get_variable(container, var)
slack_var = PSI.get_variable(container, StorageEnergyShortageVariable(), T)
set_name, set_time = JuMP.axes(variable)
IS.@assert_op set_name == [PSY.get_name(d) for d in devices]
IS.@assert_op set_time == time_steps
var_type = PSI.get_entry_type(var)
con_ub = PSI.add_constraints_container!(
container,
PSI.FeedforwardEnergyTargetConstraint(),
T,
set_name;
meta="$(var_type)target",
)
for d in devices
name = PSY.get_name(d)
con_ub[name] = JuMP.@constraint(
PSI.get_jump_model(container),
variable[name, target_period] + slack_var[name] >=
param[name, target_period] * multiplier[name, target_period]
)
PSI.add_to_objective_invariant_expression!(
container,
slack_var[name] * penalty_cost,
)
end
end
return
end
"""
Adds a constraint to limit the sum of a variable over the number of periods to the source value
"""
struct EnergyLimitFeedforward <: PSI.AbstractAffectFeedforward
optimization_container_key::PSI.OptimizationContainerKey
affected_values::Vector{<:PSI.OptimizationContainerKey}
number_of_periods::Int
function EnergyLimitFeedforward(;
component_type::Type{<:PSY.Component},
source::Type{T},
affected_values::Vector{DataType},
number_of_periods::Int,
meta=ISOPT.CONTAINER_KEY_EMPTY_META,
) where {T}
values_vector = Vector{PSI.VariableKey}(undef, length(affected_values))
for (ix, v) in enumerate(affected_values)
if v <: PSI.VariableType
values_vector[ix] =
PSI.get_optimization_container_key(v(), component_type, meta)
else
error(
"EnergyLimitFeedforward is only compatible with VariableType or ParamterType affected values",
)
end
end
new(
PSI.get_optimization_container_key(T(), component_type, meta),
values_vector,
number_of_periods,
)
end
end
PSI.get_default_parameter_type(::EnergyLimitFeedforward, _) = EnergyLimitParameter
PSI.get_optimization_container_key(ff) = ff.optimization_container_key
get_number_of_periods(ff) = ff.number_of_periods
@doc raw"""
add_feedforward_constraints(container::OptimizationContainer,
cons_name::Symbol,
param_reference,
var_key::VariableKey)
Constructs a parameterized integral limit constraint to implement feedforward from other models.
The Parameters are initialized using the upper boundary values of the provided variables.
``` sum(variable[var_name, t] for t in 1:affected_periods)/affected_periods <= param_reference[var_name] ```
# LaTeX
`` \sum_{t} x \leq param^{max}``
# Arguments
* container::OptimizationContainer : the optimization_container model built in PowerSimulations
* model::DeviceModel : the device model
* devices::IS.FlattenIteratorWrapper{T} : list of devices
* ff::FixValueFeedforward : a instance of the FixValue Feedforward
"""
function PSI.add_feedforward_constraints!(
container::PSI.OptimizationContainer,
::PSI.DeviceModel,
devices::IS.FlattenIteratorWrapper{T},
ff::EnergyLimitFeedforward,
) where {T <: PSY.Component}
time_steps = PSI.get_time_steps(container)
parameter_type = PSI.get_default_parameter_type(ff, T)
param = PSI.get_parameter_array(container, parameter_type(), T)
multiplier = PSI.get_parameter_multiplier_array(container, parameter_type(), T)
affected_periods = get_number_of_periods(ff)
for var in PSI.get_affected_values(ff)
variable = PSI.get_variable(container, var)
set_name, set_time = JuMP.axes(variable)
IS.@assert_op set_name == [PSY.get_name(d) for d in devices]
IS.@assert_op set_time == time_steps
if affected_periods > set_time[end]
error(
"The number of affected periods $affected_periods is larger than the periods available $(set_time[end])",
)
end
no_trenches = set_time[end] ÷ affected_periods
var_type = PSI.get_entry_type(var)
con_ub = PSI.add_constraints_container!(
container,
PSI.FeedforwardIntegralLimitConstraint(),
T,
set_name,
1:no_trenches;
meta="$(var_type)integral",
)
for name in set_name, i in 1:no_trenches
con_ub[name, i] = JuMP.@constraint(
container.JuMPmodel,
sum(
variable[name, t] for
t in (1 + (i - 1) * affected_periods):(i * affected_periods)
) <= sum(
param[name, t] * multiplier[name, t] for
t in (1 + (i - 1) * affected_periods):(i * affected_periods)
)
)
end
end
return
end
# TODO: It also needs the add parameters code
function PSI.update_parameter_values!(
model::PSI.OperationModel,
key::PSI.ParameterKey{T, U},
input::PSI.DatasetContainer{PSI.InMemoryDataset},
) where {T <: EnergyLimitParameter, U <: PSY.Generator}
# Enable again for detailed debugging
# TimerOutputs.@timeit RUN_SIMULATION_TIMER "$T $U Parameter Update" begin
optimization_container = PSI.get_optimization_container(model)
# Note: Do not instantite a new key here because it might not match the param keys in the container
# if the keys have strings in the meta fields
parameter_array = PSI.get_parameter_array(optimization_container, key)
parameter_attributes = PSI.get_parameter_attributes(optimization_container, key)
internal = PSI.get_internal(model)
execution_count = internal.execution_count
current_time = PSI.get_current_time(model)
state_values =
PSI.get_dataset_values(input, PSI.get_attribute_key(parameter_attributes))
component_names, time = axes(parameter_array)
resolution = PSI.get_resolution(model)
interval_time_steps =
Int(PSI.get_interval(model.internal.store_parameters) / resolution)
state_data = PSI.get_dataset(input, PSI.get_attribute_key(parameter_attributes))
state_timestamps = state_data.timestamps
max_state_index = PSI.get_num_rows(state_data)
state_data_index = PSI.find_timestamp_index(state_timestamps, current_time)
sim_timestamps = range(current_time; step=resolution, length=time[end])
old_parameter_values = jump_value.(parameter_array)
# The current method uses older parameter values because when passing the energy output from one stage
# to the next, the aux variable values gets over-written by the lower level model after its solve.
# This approach is a temporary hack and will be replaced in future versions.
for t in time
timestamp_ix = min(max_state_index, state_data_index + 1)
@debug "parameter horizon is over the step" max_state_index > state_data_index + 1
if state_timestamps[timestamp_ix] <= sim_timestamps[t]
state_data_index = timestamp_ix
end
for name in component_names
# the if statement checks if its the first solve of the model and uses the values stored in the state
# and for subsequent solves uses the state data to update the parameter values for the last set of time periods
# that are equal to the length of the interval i.e. the time periods that dont overlap between each solves.
if execution_count == 0 || t > time[end] - interval_time_steps
# Pass indices in this way since JuMP DenseAxisArray don't support view()
state_value = state_values[name, state_data_index]
if !isfinite(state_value)
error(
"The value for the system state used in $(encode_key_as_string(key)) is not a finite value $(state_value) \
This is commonly caused by referencing a state value at a time when such decision hasn't been made. \
Consider reviewing your models' horizon and interval definitions",
)
end
PSI._set_param_value!(parameter_array, state_value, name, t)
else
# Currently the update method relies on using older parameter values of the EnergyLimitParameter
# to update the parameter for overlapping periods between solves i.e. we ingoring the parameter values
# in the model interval time periods.
state_value = state_values[name, state_data_index]
if !isfinite(state_value)
error(
"The value for the system state used in $(encode_key_as_string(key)) is not a finite value $(state_value) \
This is commonly caused by referencing a state value at a time when such decision hasn't been made. \
Consider reviewing your models' horizon and interval definitions",
)
end
PSI._set_param_value!(
parameter_array,
old_parameter_values[name, t + interval_time_steps],
name,
t,
)
end
end
end
IS.@record :execution PSI.ParameterUpdateEvent(
T,
U,
parameter_attributes,
PSI.get_current_timestamp(model),
PSI.get_name(model),
)
return
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 889 | ############################ Storage Generation Formulations ###############################
abstract type AbstractStorageFormulation <: PSI.AbstractDeviceFormulation end
"""
Formulation type to add storage formulation than can provide ancillary services. If a
storage unit does not contribute to any service, then the variables and constraints related to
services are ignored.
The formulation supports the following attributes. See Documentation for more details.
```julia
DeviceModel(
StorageType, # E.g. EnergyReservoirStorage or GenericStorage
StorageDispatchWithReserves;
attributes=Dict(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => true,
),
use_slacks=false,
)
```
"""
struct StorageDispatchWithReserves <: AbstractStorageFormulation end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 58 | # Initial Conditions Taken from PSI
# InitialEnergyLevel
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 446 | """
Parameter to define energy limit
"""
struct EnergyLimitParameter <: PSI.VariableValueParameter end
# TODO: Check if EnergyTargetParameter and EnergyLimitParameter should be removed
# This affects feedforwards that can break if not defined
struct EnergyTargetParameter <: PSI.VariableValueParameter end
convert_result_to_natural_units(::Type{EnergyLimitParameter}) = true
convert_result_to_natural_units(::Type{EnergyTargetParameter}) = true
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 1640 | # Component Variables
# Variables Taken from PSI
# ActivePowerInVariable
# ActivePowerOutVariable
# EnergyVariable
# ReservationVariable
# Ancillary Service Assignment Variables
struct AncillaryServiceVariableDischarge <: PSI.VariableType end
struct AncillaryServiceVariableCharge <: PSI.VariableType end
"""
Slack variable for energy storage levels < target storage levels
Docs abbreviation: ``e^{st-}``
"""
struct StorageEnergyShortageVariable <: PSI.VariableType end
"""
Slack variable for energy storage levels > target storage levels
Docs abbreviation: ``e^{st+}``
"""
struct StorageEnergySurplusVariable <: PSI.VariableType end
"""
Slack variable for the cycling limits to allow for more charging usage than the allowed limited
Docs nomenclature: ``c^{ch-}``
"""
struct StorageChargeCyclingSlackVariable <: PSI.VariableType end
"""
Slack variable for the cycling limits to allow for more discharging usage than the allowed limited
Docs nomenclature: ``c^{ds-}``
"""
struct StorageDischargeCyclingSlackVariable <: PSI.VariableType end
abstract type StorageRegularizationVariable <: PSI.VariableType end
"""
Slack variable for energy storage levels > target storage levels
Docs nomenclature: ``z^{st, ch}``
"""
struct StorageRegularizationVariableCharge <: StorageRegularizationVariable end
"""
Slack variable for energy storage levels > target storage levels
Docs abbreviation: ``z^{st, ds}``
"""
struct StorageRegularizationVariableDischarge <: StorageRegularizationVariable end
"""
Auxiliary Variable for Storage Models that solve for total energy output
"""
struct StorageEnergyOutput <: PSI.AuxVariableType end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 3938 | using Test
using PowerSystemCaseBuilder
using StorageSystemsSimulations
using HydroPowerSimulations
using Logging
using InfrastructureSystems
using PowerSimulations
using PowerSystems
using JuMP
using HiGHS
using GLPK
const IS = InfrastructureSystems
const PSY = PowerSystems
const PSB = PowerSystemCaseBuilder
const PSI = PowerSimulations
const PM = PSI.PowerModels
const PNM = PSI.PowerNetworkMatrices
const MOI = PSI.MathOptInterface
import Aqua
Aqua.test_unbound_args(StorageSystemsSimulations)
Aqua.test_undefined_exports(StorageSystemsSimulations)
Aqua.test_ambiguities(StorageSystemsSimulations)
Aqua.test_stale_deps(StorageSystemsSimulations)
Aqua.test_deps_compat(StorageSystemsSimulations)
LOG_FILE = "storage-systems-simulations.log"
LOG_LEVELS = Dict(
"Debug" => Logging.Debug,
"Info" => Logging.Info,
"Warn" => Logging.Warn,
"Error" => Logging.Error,
)
include("test_utils/mock_operation_models.jl")
include("test_utils/model_checks.jl")
include("test_utils/operations_problems_templates.jl")
HiGHS_optimizer = JuMP.optimizer_with_attributes(
HiGHS.Optimizer,
"time_limit" => 100.0,
"log_to_console" => false,
)
GLPK_optimizer =
JuMP.optimizer_with_attributes(GLPK.Optimizer, "msg_lev" => GLPK.GLP_MSG_OFF)
"""
Copied @includetests from https://github.com/ssfrr/TestSetExtensions.jl.
Ideally, we could import and use TestSetExtensions. Its functionality was broken by changes
in Julia v0.7. Refer to https://github.com/ssfrr/TestSetExtensions.jl/pull/7.
"""
"""
Includes the given test files, given as a list without their ".jl" extensions.
If none are given it will scan the directory of the calling file and include all
the julia files.
"""
macro includetests(testarg...)
if length(testarg) == 0
tests = []
elseif length(testarg) == 1
tests = testarg[1]
else
error("@includetests takes zero or one argument")
end
quote
tests = $tests
rootfile = @__FILE__
if length(tests) == 0
tests = readdir(dirname(rootfile))
tests = filter(
f ->
startswith(f, "test_") && endswith(f, ".jl") && f != basename(rootfile),
tests,
)
else
tests = map(f -> string(f, ".jl"), tests)
end
println()
for test in tests
print(splitext(test)[1], ": ")
include(test)
println()
end
end
end
function get_logging_level_from_env(env_name::String, default)
level = get(ENV, env_name, default)
return IS.get_logging_level(level)
end
function run_tests()
logging_config_filename = get(ENV, "SIIP_LOGGING_CONFIG", nothing)
if logging_config_filename !== nothing
config = IS.LoggingConfiguration(logging_config_filename)
else
config = IS.LoggingConfiguration(;
filename=LOG_FILE,
file_level=Logging.Info,
console_level=Logging.Error,
)
end
console_logger = ConsoleLogger(config.console_stream, config.console_level)
IS.open_file_logger(config.filename, config.file_level) do file_logger
levels = (Logging.Info, Logging.Warn, Logging.Error)
multi_logger =
IS.MultiLogger([console_logger, file_logger], IS.LogEventTracker(levels))
global_logger(multi_logger)
if !isempty(config.group_levels)
IS.set_group_levels!(multi_logger, config.group_levels)
end
# Testing Topological components of the schema
@time @testset "Begin StorageSystemsSimulations tests" begin
@includetests ARGS
end
@test length(IS.get_log_events(multi_logger.tracker, Logging.Error)) == 0
@info IS.report_log_summary(multi_logger)
end
end
logger = global_logger()
try
run_tests()
finally
# Guarantee that the global logger is reset.
global_logger(logger)
nothing
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 9116 | @testset "Storage Basic Storage With DC - PF" begin
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => false,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => false,
),
)
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat")
model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5_bat)
mock_construct_device!(model, device_model)
moi_tests(model, 72, 0, 72, 72, 24, false)
psi_checkobjfun_test(model, GAEVF)
end
@testset "Storage Basic Storage With AC - PF" begin
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => false,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => false,
),
)
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat")
model = DecisionModel(MockOperationProblem, ACPPowerModel, c_sys5_bat)
mock_construct_device!(model, device_model)
moi_tests(model, 96, 0, 96, 96, 24, false)
psi_checkobjfun_test(model, GAEVF)
end
@testset "Storage with Reservation & DC - PF" begin
device_model = DeviceModel(EnergyReservoirStorage, StorageDispatchWithReserves)
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat")
model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5_bat)
mock_construct_device!(model, device_model)
moi_tests(model, 96, 0, 72, 72, 24, true)
psi_checkobjfun_test(model, GAEVF)
end
@testset "Storage with Reservation & AC - PF" begin
device_model = DeviceModel(EnergyReservoirStorage, StorageDispatchWithReserves)
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat")
model = DecisionModel(MockOperationProblem, ACPPowerModel, c_sys5_bat)
mock_construct_device!(model, device_model)
moi_tests(model, 120, 0, 96, 96, 24, true)
psi_checkobjfun_test(model, GAEVF)
end
@testset "EnergyReservoirStorage with EnergyTarget with DC - PF" begin
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => true,
"complete_coverage" => false,
"regularization" => false,
),
)
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat_ems")
model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5_bat)
mock_construct_device!(model, device_model)
moi_tests(model, 98, 0, 72, 72, 25, true)
psi_checkobjfun_test(model, GAEVF)
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => false,
"cycling_limits" => false,
"energy_target" => true,
"complete_coverage" => false,
"regularization" => false,
),
)
model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5_bat)
mock_construct_device!(model, device_model)
moi_tests(model, 74, 0, 72, 72, 25, false)
psi_checkobjfun_test(model, GAEVF)
end
@testset "EnergyReservoirStorage with EnergyTarget With AC - PF" begin
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => true,
"complete_coverage" => false,
"regularization" => false,
),
)
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat_ems")
model = DecisionModel(MockOperationProblem, ACPPowerModel, c_sys5_bat)
mock_construct_device!(model, device_model)
moi_tests(model, 122, 0, 96, 96, 25, true)
psi_checkobjfun_test(model, GAEVF)
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => false,
"cycling_limits" => false,
"energy_target" => true,
"complete_coverage" => false,
"regularization" => false,
),
)
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat_ems")
model = DecisionModel(MockOperationProblem, ACPPowerModel, c_sys5_bat)
mock_construct_device!(model, device_model)
moi_tests(model, 98, 0, 96, 96, 25, false)
psi_checkobjfun_test(model, GAEVF)
end
### Feedforward Test ###
# TODO: Feedforward debugging
@testset "Test EnergyTargetFeedforward to EnergyReservoirStorage with StorageDispatch model" begin
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => false,
),
)
ff_et = EnergyTargetFeedforward(;
component_type=EnergyReservoirStorage,
source=EnergyVariable,
affected_values=[EnergyVariable],
target_period=12,
penalty_cost=1e5,
)
PSI.attach_feedforward!(device_model, ff_et)
sys = PSB.build_system(PSITestSystems, "c_sys5_bat")
model = DecisionModel(MockOperationProblem, DCPPowerModel, sys)
mock_construct_device!(model, device_model; built_for_recurrent_solves=true)
moi_tests(model, 122, 0, 72, 73, 24, true)
end
@testset "Test EnergyTargetFeedforward to EnergyReservoirStorage with BookKeeping model" begin
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => false,
),
)
ff_et = EnergyTargetFeedforward(;
component_type=EnergyReservoirStorage,
source=EnergyVariable,
affected_values=[EnergyVariable],
target_period=12,
penalty_cost=1e5,
)
PSI.attach_feedforward!(device_model, ff_et)
sys = PSB.build_system(PSITestSystems, "c_sys5_bat_ems")
model = DecisionModel(MockOperationProblem, DCPPowerModel, sys)
mock_construct_device!(model, device_model; built_for_recurrent_solves=true)
moi_tests(model, 122, 0, 72, 73, 24, true)
end
#=
@testset "Test EnergyLimitFeedforward to EnergyReservoirStorage with BookKeeping model" begin
device_model = DeviceModel(EnergyReservoirStorage, BookKeeping)
ff_il = EnergyLimitFeedforward(;
component_type=EnergyReservoirStorage,
source=ActivePowerOutVariable,
affected_values=[ActivePowerOutVariable],
number_of_periods=12,
)
PSI.attach_feedforward!(device_model, ff_il)
sys = PSB.build_system(PSITestSystems, "c_sys5_bat")
model = DecisionModel(MockOperationProblem, DCPPowerModel, sys)
mock_construct_device!(model, device_model; built_for_recurrent_solves=true)
moi_tests(model, 121, 0, 74, 72, 24, true)
end
@testset "Test EnergyLimitFeedforward to EnergyReservoirStorage with BatteryAncillaryServices model" begin
device_model = DeviceModel(EnergyReservoirStorage, BatteryAncillaryServices)
ff_il = EnergyLimitFeedforward(;
component_type=EnergyReservoirStorage,
source=ActivePowerOutVariable,
affected_values=[ActivePowerOutVariable],
number_of_periods=12,
)
PSI.attach_feedforward!(device_model, ff_il)
sys = PSB.build_system(PSITestSystems, "c_sys5_bat")
model = DecisionModel(MockOperationProblem, DCPPowerModel, sys)
mock_construct_device!(model, device_model; built_for_recurrent_solves=true)
moi_tests(model, 121, 0, 74, 72, 24, true)
end
# To Fix
@testset "Test Reserves from Storage" begin
template = get_thermal_dispatch_template_network(CopperPlatePowerModel)
set_device_model!(template, DeviceModel(EnergyReservoirStorage, BatteryAncillaryServices))
set_device_model!(template, RenewableDispatch, FixedOutput)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve3"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveDown}, RangeReserve, "Reserve4"),
)
set_service_model!(
template,
ServiceModel(ReserveDemandCurve{ReserveUp}, StepwiseCostReserve, "ORDC1"),
)
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat"; add_reserves = true)
model = DecisionModel(template, c_sys5_bat)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 432, 0, 288, 264, 96, true)
end
=#
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 8096 | @testset "Decision Model initial_conditions test for Storage" begin
######## Test with BookKeeping ########
template = get_thermal_dispatch_template_network()
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat"; force_build=true)
set_device_model!(template, EnergyReservoirStorage, StorageDispatchWithReserves)
model = DecisionModel(template, c_sys5_bat; optimizer=HiGHS_optimizer)
@test build!(model; output_dir=mktempdir(; cleanup=true)) == PSI.ModelBuildStatus.BUILT
check_energy_initial_conditions_values(model, EnergyReservoirStorage)
@test solve!(model) == PSI.RunStatus.SUCCESSFULLY_FINALIZED
######## Test with EnergyTarget ########
template = get_thermal_dispatch_template_network()
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat_ems"; force_build=true)
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => true,
"complete_coverage" => false,
"regularization" => false,
),
)
set_device_model!(template, device_model)
model = DecisionModel(template, c_sys5_bat; optimizer=HiGHS_optimizer)
@test build!(model; output_dir=mktempdir(; cleanup=true)) == PSI.ModelBuildStatus.BUILT
check_energy_initial_conditions_values(model, EnergyReservoirStorage)
@test solve!(model) == PSI.RunStatus.SUCCESSFULLY_FINALIZED
end
@testset "Emulation Model initial_conditions test for Storage" begin
######## Test with BookKeeping ########
template = get_thermal_dispatch_template_network()
c_sys5_bat = PSB.build_system(
PSITestSystems,
"c_sys5_bat";
add_single_time_series=true,
force_build=true,
)
set_device_model!(template, EnergyReservoirStorage, StorageDispatchWithReserves)
model = EmulationModel(template, c_sys5_bat; optimizer=HiGHS_optimizer)
@test build!(model; executions=10, output_dir=mktempdir(; cleanup=true)) ==
PSI.ModelBuildStatus.BUILT
ic_data = PSI.get_initial_condition(
PSI.get_optimization_container(model),
InitialEnergyLevel(),
EnergyReservoirStorage,
)
for ic in ic_data
d = ic.component
name = PSY.get_name(d)
e_var = PSI.jump_value(PSI.get_value(ic))
@test PSY.get_initial_storage_capacity_level(d) *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d) == e_var
end
@test run!(model) == PSI.RunStatus.SUCCESSFULLY_FINALIZED
######## Test with BatteryAncillaryServices ########
template = get_thermal_dispatch_template_network()
c_sys5_bat = PSB.build_system(
PSITestSystems,
"c_sys5_bat";
add_single_time_series=true,
force_build=true,
)
set_device_model!(template, EnergyReservoirStorage, StorageDispatchWithReserves)
model = EmulationModel(template, c_sys5_bat; optimizer=HiGHS_optimizer)
@test build!(model; executions=10, output_dir=mktempdir(; cleanup=true)) ==
PSI.ModelBuildStatus.BUILT
ic_data = PSI.get_initial_condition(
PSI.get_optimization_container(model),
InitialEnergyLevel(),
EnergyReservoirStorage,
)
for ic in ic_data
d = ic.component
name = PSY.get_name(d)
e_var = PSI.jump_value(PSI.get_value(ic))
@test PSY.get_initial_storage_capacity_level(d) *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d) == e_var
end
@test run!(model) == PSI.RunStatus.SUCCESSFULLY_FINALIZED
######## Test with EnergyTarget ########
template = get_thermal_dispatch_template_network()
c_sys5_bat = PSB.build_system(
PSITestSystems,
"c_sys5_bat_ems";
add_single_time_series=true,
force_build=true,
)
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => true,
"complete_coverage" => true,
"regularization" => false,
),
)
set_device_model!(template, device_model)
model = EmulationModel(template, c_sys5_bat; optimizer=HiGHS_optimizer)
@test build!(model; executions=10, output_dir=mktempdir(; cleanup=true)) ==
PSI.ModelBuildStatus.BUILT
ic_data = PSI.get_initial_condition(
PSI.get_optimization_container(model),
InitialEnergyLevel(),
EnergyReservoirStorage,
)
for ic in ic_data
d = ic.component
name = PSY.get_name(d)
e_var = PSI.jump_value(PSI.get_value(ic))
@test PSY.get_initial_storage_capacity_level(d) *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d) == e_var
end
@test run!(model) == PSI.RunStatus.SUCCESSFULLY_FINALIZED
end
@testset "Simulation with 2-Stages EnergyLimitFeedforward with EnergyReservoirStorage" begin
sys_uc = build_system(PSITestSystems, "c_sys5_bat")
sys_ed = build_system(PSITestSystems, "c_sys5_bat")
template_uc = get_template_basic_uc_storage_simulation()
template_ed = get_template_dispatch_storage_simulation()
models = SimulationModels(;
decision_models=[
DecisionModel(
template_uc,
sys_uc;
name="UC",
optimizer=GLPK_optimizer,
store_variable_names=true,
),
DecisionModel(
template_ed,
sys_ed;
name="ED",
optimizer=GLPK_optimizer,
store_variable_names=true,
),
],
)
sequence = SimulationSequence(;
models=models,
feedforwards=Dict(
"ED" => [
SemiContinuousFeedforward(;
component_type=ThermalStandard,
source=OnVariable,
affected_values=[ActivePowerVariable],
),
EnergyLimitFeedforward(;
component_type=EnergyReservoirStorage,
source=ActivePowerOutVariable,
affected_values=[ActivePowerOutVariable],
number_of_periods=12,
),
],
),
ini_cond_chronology=InterProblemChronology(),
)
sim_cache = Simulation(;
name="sim",
steps=2,
models=models,
sequence=sequence,
simulation_folder=mktempdir(; cleanup=true),
)
build_out = build!(sim_cache)
@test build_out == PSI.SimulationBuildStatus.BUILT
execute_out = execute!(sim_cache)
@test execute_out == PSI.RunStatus.SUCCESSFULLY_FINALIZED
# Test UC Vars are equal to ED params
res = SimulationResults(sim_cache)
res_ed = res.decision_problem_results["ED"]
param_ed =
read_realized_parameter(res_ed, "EnergyLimitParameter__EnergyReservoirStorage")
res_uc = res.decision_problem_results["UC"]
p_out_bat =
read_realized_variable(res_uc, "ActivePowerOutVariable__EnergyReservoirStorage")
@test isapprox(param_ed[!, 2], p_out_bat[!, 2] / 100.0; atol=1e-4)
end
@testset "Test cost handling" begin
c_sys5_bat = PSB.build_system(PSITestSystems, "c_sys5_bat"; force_build=true)
template = get_thermal_dispatch_template_network()
storage_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict(
"reservation" => false,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => true,
),
)
set_device_model!(template, storage_model)
model = DecisionModel(template, c_sys5_bat; optimizer=HiGHS_optimizer)
@test build!(model; output_dir=mktempdir(; cleanup=true)) == PSI.ModelBuildStatus.BUILT
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 7035 | # NOTE: None of the models and function in this file are functional. All of these are used for testing purposes and do not represent valid examples either to develop custom
# models. Please refer to the documentation.
struct MockOperationProblem <: PSI.DefaultDecisionProblem end
struct MockEmulationProblem <: PSI.DefaultEmulationProblem end
function PSI.DecisionModel(
::Type{MockOperationProblem},
::Type{T},
sys::PSY.System;
name=nothing,
kwargs...,
) where {T <: PM.AbstractPowerModel}
settings = PSI.Settings(sys; kwargs...)
return DecisionModel{MockOperationProblem}(
ProblemTemplate(T),
sys,
settings,
nothing;
name=name,
)
end
function make_mock_forecast(horizon, resolution, interval, steps)
init_time = DateTime("2024-01-01")
timeseries_data = Dict{Dates.DateTime, Vector{Float64}}()
for i in 1:steps
forecast_timestamps = init_time + interval * i
timeseries_data[forecast_timestamps] = rand(horizon)
end
return Deterministic(;
name="mock_forecast",
data=timeseries_data,
resolution=resolution,
)
end
function make_mock_singletimeseries(horizon, resolution)
init_time = DateTime("2024-01-01")
tstamps = collect(range(init_time; length=horizon, step=resolution))
timeseries_data = TimeArray(tstamps, rand(horizon))
return SingleTimeSeries(; name="mock_timeseries", data=timeseries_data)
end
function PSI.DecisionModel(::Type{MockOperationProblem}; name=nothing, kwargs...)
sys = System(100.0)
add_component!(sys, Bus(nothing))
l = PowerLoad(nothing)
gen = ThermalStandard(nothing)
set_bus!(l, get_component(Bus, sys, "init"))
set_bus!(gen, get_component(Bus, sys, "init"))
add_component!(sys, l)
add_component!(sys, gen)
forecast = make_mock_forecast(
get(kwargs, :horizon, 24),
get(kwargs, :resolution, Hour(1)),
get(kwargs, :interval, Hour(1)),
get(kwargs, :steps, 2),
)
add_time_series!(sys, l, forecast)
settings = PSI.Settings(sys; horizon=get(kwargs, :horizon, 24))
return DecisionModel{MockOperationProblem}(
ProblemTemplate(CopperPlatePowerModel),
sys,
settings,
nothing;
name=name,
)
end
function PSI.EmulationModel(::Type{MockEmulationProblem}; name=nothing, kwargs...)
sys = System(100.0)
add_component!(sys, Bus(nothing))
l = PowerLoad(nothing)
gen = ThermalStandard(nothing)
set_bus!(l, get_component(Bus, sys, "init"))
set_bus!(gen, get_component(Bus, sys, "init"))
add_component!(sys, l)
add_component!(sys, gen)
single_ts = make_mock_singletimeseries(
get(kwargs, :horizon, 24),
get(kwargs, :resolution, Hour(1)),
)
add_time_series!(sys, l, single_ts)
settings = PSI.Settings(sys; horizon=get(kwargs, :horizon, 24))
return EmulationModel{MockEmulationProblem}(
ProblemTemplate(CopperPlatePowerModel),
sys,
settings,
nothing;
name=name,
)
end
# Only used for testing
function mock_construct_device!(
problem::PSI.DecisionModel{MockOperationProblem},
model;
built_for_recurrent_solves=false,
)
set_device_model!(problem.template, model)
template = PSI.get_template(problem)
PSI.finalize_template!(template, PSI.get_system(problem))
settings = PSI.get_settings(problem)
PSI.set_resolution!(
settings,
first(PSY.get_time_series_resolutions(PSI.get_system(problem))),
)
PSI.set_horizon!(settings, PSY.get_forecast_horizon(PSI.get_system(problem)))
PSI.init_optimization_container!(
PSI.get_optimization_container(problem),
PSI.get_network_model(template),
PSI.get_system(problem),
)
PSI.get_network_model(template).subnetworks =
PNM.find_subnetworks(PSI.get_system(problem))
PSI.get_optimization_container(problem).built_for_recurrent_solves =
built_for_recurrent_solves
PSI.initialize_system_expressions!(
PSI.get_optimization_container(problem),
PSI.get_network_model(template),
PSI.get_network_model(template).subnetworks,
PSI.get_system(problem),
Dict{Int64, Set{Int64}}(),
)
if PSI.validate_available_devices(model, PSI.get_system(problem))
PSI.construct_device!(
PSI.get_optimization_container(problem),
PSI.get_system(problem),
PSI.ArgumentConstructStage(),
model,
PSI.get_network_model(template),
)
PSI.construct_device!(
PSI.get_optimization_container(problem),
PSI.get_system(problem),
PSI.ModelConstructStage(),
model,
PSI.get_network_model(template),
)
end
PSI.check_optimization_container(PSI.get_optimization_container(problem))
JuMP.@objective(
PSI.get_jump_model(problem),
MOI.MIN_SENSE,
PSI.get_objective_expression(
PSI.get_optimization_container(problem).objective_function,
)
)
return
end
function mock_construct_network!(problem::PSI.DecisionModel{MockOperationProblem}, model)
PSI.set_network_model!(problem.template, model)
PSI.construct_network!(
PSI.get_optimization_container(problem),
PSI.get_system(problem),
model,
problem.template.branches,
)
return
end
function mock_uc_ed_simulation_problems(uc_horizon, ed_horizon)
return SimulationModels([
DecisionModel(MockOperationProblem; horizon=uc_horizon, name="UC"),
DecisionModel(
MockOperationProblem;
horizon=ed_horizon,
resolution=Minute(5),
name="ED",
),
])
end
function create_simulation_build_test_problems(
template_uc=get_template_standard_uc_simulation(),
template_ed=get_template_nomin_ed_simulation(),
sys_uc=PSB.build_system(PSITestSystems, "c_sys5_uc"),
sys_ed=PSB.build_system(PSITestSystems, "c_sys5_ed"),
)
return SimulationModels(;
decision_models=[
DecisionModel(template_uc, sys_uc; name="UC", optimizer=GLPK_optimizer),
DecisionModel(template_ed, sys_ed; name="ED", optimizer=GLPK_optimizer),
],
)
end
struct MockStagesStruct
stages::Dict{Int, Int}
end
function Base.show(io::IO, struct_stages::MockStagesStruct)
println(io, "mock problem")
return
end
function setup_ic_model_container!(model::DecisionModel)
# This function is only for testing purposes.
if !PSI.is_empty(model)
PSI.reset!(model)
end
PSI.init_optimization_container!(
PSI.get_optimization_container(model),
PSI.get_network_model(PSI.get_template(model)),
PSI.get_system(model),
)
PSI.init_model_store_params!(model)
@info "Make Initial Conditions Model"
PSI.set_output_dir!(model, mktempdir(; cleanup=true))
PSI.build_initial_conditions!(model)
PSI.initialize!(model)
return
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 15922 | const GAEVF = JuMP.GenericAffExpr{Float64, VariableRef}
const GQEVF = JuMP.GenericQuadExpr{Float64, VariableRef}
function moi_tests(
model::DecisionModel,
vars::Int,
interval::Int,
lessthan::Int,
greaterthan::Int,
equalto::Int,
binary::Bool,
)
JuMPmodel = PSI.get_jump_model(model)
@test JuMP.num_variables(JuMPmodel) == vars
@test JuMP.num_constraints(JuMPmodel, GAEVF, MOI.Interval{Float64}) == interval
@test JuMP.num_constraints(JuMPmodel, GAEVF, MOI.LessThan{Float64}) == lessthan
@test JuMP.num_constraints(JuMPmodel, GAEVF, MOI.GreaterThan{Float64}) == greaterthan
@test JuMP.num_constraints(JuMPmodel, GAEVF, MOI.EqualTo{Float64}) == equalto
@test ((JuMP.VariableRef, MOI.ZeroOne) in JuMP.list_of_constraint_types(JuMPmodel)) ==
binary
return
end
function psi_constraint_test(
model::DecisionModel,
constraint_keys::Vector{<:PSI.ConstraintKey},
)
constraints = PSI.get_constraints(model)
for con in constraint_keys
if get(constraints, con, nothing) !== nothing
@test true
else
@error con
@test false
end
end
return
end
function psi_aux_variable_test(
model::DecisionModel,
constraint_keys::Vector{<:PSI.AuxVarKey},
)
op_container = PSI.get_optimization_container(model)
vars = PSI.get_aux_variables(op_container)
for key in constraint_keys
@test get(vars, key, nothing) !== nothing
end
return
end
function psi_checkbinvar_test(
model::DecisionModel,
bin_variable_keys::Vector{<:PSI.VariableKey},
)
container = PSI.get_optimization_container(model)
for variable in bin_variable_keys
for v in PSI.get_variable(container, variable)
@test JuMP.is_binary(v)
end
end
return
end
function psi_checkobjfun_test(model::DecisionModel, exp_type)
model = PSI.get_jump_model(model)
@test JuMP.objective_function_type(model) == exp_type
return
end
function moi_lbvalue_test(model::DecisionModel, con_key::PSI.ConstraintKey, value::Number)
for con in PSI.get_constraints(model)[con_key]
@test JuMP.constraint_object(con).set.lower == value
end
return
end
function psi_checksolve_test(model::DecisionModel, status)
model = PSI.get_jump_model(model)
JuMP.optimize!(model)
@test termination_status(model) in status
end
function psi_checksolve_test(model::DecisionModel, status, expected_result, tol=0.0)
res = solve!(model)
model = PSI.get_jump_model(model)
@test termination_status(model) in status
obj_value = JuMP.objective_value(model)
@test isapprox(obj_value, expected_result, atol=tol)
end
function psi_ptdf_lmps(res::OptimizationProblemResults, ptdf)
cp_duals = read_dual(res, PSI.ConstraintKey(CopperPlateBalanceConstraint, PSY.System))
λ = Matrix{Float64}(cp_duals[:, propertynames(cp_duals) .!= :DateTime])
flow_duals = read_dual(res, PSI.ConstraintKey(NetworkFlowConstraint, PSY.Line))
μ = Matrix{Float64}(flow_duals[:, PNM.get_branch_ax(ptdf)])
buses = get_components(Bus, get_system(res))
lmps = OrderedDict()
for bus in buses
lmps[get_name(bus)] = μ * ptdf[:, get_number(bus)]
end
lmp = λ .+ DataFrames.DataFrame(lmps)
return lmp[!, sort(propertynames(lmp))]
end
function check_variable_unbounded(
model::DecisionModel,
::Type{T},
::Type{U},
) where {T <: PSI.VariableType, U <: PSY.Component}
return check_variable_unbounded(model::DecisionModel, PSI.VariableKey(T, U))
end
function check_variable_unbounded(model::DecisionModel, var_key::PSI.VariableKey)
psi_cont = PSI.get_optimization_container(model)
variable = PSI.get_variable(psi_cont, var_key)
for var in variable
if JuMP.has_lower_bound(var) || JuMP.has_upper_bound(var)
return false
end
end
return true
end
function check_variable_bounded(
model::DecisionModel,
::Type{T},
::Type{U},
) where {T <: PSI.VariableType, U <: PSY.Component}
return check_variable_bounded(model, PSI.VariableKey(T, U))
end
function check_variable_bounded(model::DecisionModel, var_key::PSI.VariableKey)
psi_cont = PSI.get_optimization_container(model)
variable = PSI.get_variable(psi_cont, var_key)
for var in variable
if !JuMP.has_lower_bound(var) || !JuMP.has_upper_bound(var)
return false
end
end
return true
end
function check_flow_variable_values(
model::DecisionModel,
::Type{T},
::Type{U},
device_name::String,
limit::Float64,
) where {T <: PSI.VariableType, U <: PSY.Component}
psi_cont = PSI.get_optimization_container(model)
variable = PSI.get_variable(psi_cont, T(), U)
for var in variable[device_name, :]
if !(PSI.jump_value(var) <= (limit + 1e-2))
@error "$device_name out of bounds $(PSI.jump_value(var))"
return false
end
end
return true
end
function check_flow_variable_values(
model::DecisionModel,
::Type{T},
::Type{U},
device_name::String,
limit_min::Float64,
limit_max::Float64,
) where {T <: PSI.VariableType, U <: PSY.Component}
psi_cont = PSI.get_optimization_container(model)
variable = PSI.get_variable(psi_cont, T(), U)
for var in variable[device_name, :]
if !(PSI.jump_value(var) <= (limit_max + 1e-2)) ||
!(PSI.jump_value(var) >= (limit_min - 1e-2))
return false
end
end
return true
end
function check_flow_variable_values(
model::DecisionModel,
::Type{T},
::Type{U},
::Type{V},
device_name::String,
limit_min::Float64,
limit_max::Float64,
) where {T <: PSI.VariableType, U <: PSI.VariableType, V <: PSY.Component}
psi_cont = PSI.get_optimization_container(model)
time_steps = PSI.get_time_steps(psi_cont)
pvariable = PSI.get_variable(psi_cont, T(), V)
qvariable = PSI.get_variable(psi_cont, U(), V)
for t in time_steps
fp = PSI.jump_value(pvariable[device_name, t])
fq = PSI.jump_value(qvariable[device_name, t])
flow = sqrt((fp)^2 + (fq)^2)
if !(flow <= (limit_max + 1e-2)^2) || !(flow >= (limit_min - 1e-2)^2)
return false
end
end
return true
end
function check_flow_variable_values(
model::DecisionModel,
::Type{T},
::Type{U},
::Type{V},
device_name::String,
limit::Float64,
) where {T <: PSI.VariableType, U <: PSI.VariableType, V <: PSY.Component}
psi_cont = PSI.get_optimization_container(model)
time_steps = PSI.get_time_steps(psi_cont)
pvariable = PSI.get_variable(psi_cont, T(), V)
qvariable = PSI.get_variable(psi_cont, U(), V)
for t in time_steps
fp = PSI.jump_value(pvariable[device_name, t])
fq = PSI.jump_value(qvariable[device_name, t])
flow = sqrt((fp)^2 + (fq)^2)
if !(flow <= (limit + 1e-2)^2)
return false
end
end
return true
end
function PSI.jump_value(int::Int)
@warn("This is for testing purposes only.")
return int
end
function _check_constraint_bounds(bounds::PSI.ConstraintBounds, valid_bounds::NamedTuple)
@test bounds.coefficient.min == valid_bounds.coefficient.min
@test bounds.coefficient.max == valid_bounds.coefficient.max
@test bounds.rhs.min == valid_bounds.rhs.min
@test bounds.rhs.max == valid_bounds.rhs.max
end
function _check_variable_bounds(bounds::PSI.VariableBounds, valid_bounds::NamedTuple)
@test bounds.bounds.min == valid_bounds.min
@test bounds.bounds.max == valid_bounds.max
end
function check_duration_on_initial_conditions_values(
model,
::Type{T},
) where {T <: PSY.Component}
initial_conditions_data =
PSI.get_initial_conditions_data(PSI.get_optimization_container(model))
duration_on_data = PSI.get_initial_condition(
PSI.get_optimization_container(model),
InitialTimeDurationOn(),
T,
)
for ic in duration_on_data
name = PSY.get_name(ic.component)
on_var = PSI.get_initial_condition_value(initial_conditions_data, OnVariable(), T)[
1,
name,
]
duration_on = PSI.jump_value(PSI.get_value(ic))
if on_var == 1.0 && PSY.get_status(ic.component)
@test duration_on == PSY.get_time_at_status(ic.component)
elseif on_var == 1.0 && !PSY.get_status(ic.component)
@test duration_on == 0.0
end
end
end
function check_duration_off_initial_conditions_values(
model,
::Type{T},
) where {T <: PSY.Component}
initial_conditions_data =
PSI.get_initial_conditions_data(PSI.get_optimization_container(model))
duration_off_data = PSI.get_initial_condition(
PSI.get_optimization_container(model),
InitialTimeDurationOff(),
T,
)
for ic in duration_off_data
name = PSY.get_name(ic.component)
on_var = PSI.get_initial_condition_value(initial_conditions_data, OnVariable(), T)[
1,
name,
]
duration_off = PSI.jump_value(PSI.get_value(ic))
if on_var == 0.0 && !PSY.get_status(ic.component)
@test duration_off == PSY.get_time_at_status(ic.component)
elseif on_var == 0.0 && PSY.get_status(ic.component)
@test duration_off == 0.0
end
end
end
function check_energy_initial_conditions_values(model, ::Type{T}) where {T <: PSY.Component}
ic_data = PSI.get_initial_condition(
PSI.get_optimization_container(model),
InitialEnergyLevel(),
T,
)
for ic in ic_data
d = ic.component
name = PSY.get_name(d)
e_value = PSI.jump_value(PSI.get_value(ic))
@test PSY.get_initial_storage_capacity_level(d) *
PSY.get_storage_capacity(d) *
PSY.get_conversion_factor(d) == e_value
end
end
function check_energy_initial_conditions_values(model, ::Type{T}) where {T <: PSY.HydroGen}
ic_data = PSI.get_initial_condition(
PSI.get_optimization_container(model),
InitialEnergyLevel(),
T,
)
for ic in ic_data
name = PSY.get_name(ic.component)
e_value = PSI.jump_value(PSI.get_value(ic))
@test PSY.get_initial_storage(ic.component) == e_value
end
end
function check_status_initial_conditions_values(model, ::Type{T}) where {T <: PSY.Component}
initial_conditions =
PSI.get_initial_condition(PSI.get_optimization_container(model), DeviceStatus(), T)
initial_conditions_data =
PSI.get_initial_conditions_data(PSI.get_optimization_container(model))
for ic in initial_conditions
name = PSY.get_name(ic.component)
status = PSI.get_initial_condition_value(initial_conditions_data, OnVariable(), T)[
1,
name,
]
@test PSI.jump_value(PSI.get_value(ic)) == status
end
end
function check_active_power_initial_condition_values(
model,
::Type{T},
) where {T <: PSY.Component}
initial_conditions =
PSI.get_initial_condition(PSI.get_optimization_container(model), DevicePower(), T)
initial_conditions_data =
PSI.get_initial_conditions_data(PSI.get_optimization_container(model))
for ic in initial_conditions
name = PSY.get_name(ic.component)
power = PSI.get_initial_condition_value(
initial_conditions_data,
ActivePowerVariable(),
T,
)[
1,
name,
]
@test PSI.jump_value(PSI.get_value(ic)) == power
end
end
function check_active_power_abovemin_initial_condition_values(
model,
::Type{T},
) where {T <: PSY.Component}
initial_conditions = PSI.get_initial_condition(
PSI.get_optimization_container(model),
PSI.DeviceAboveMinPower(),
T,
)
initial_conditions_data =
PSI.get_initial_conditions_data(PSI.get_optimization_container(model))
for ic in initial_conditions
name = PSY.get_name(ic.component)
power = PSI.get_initial_condition_value(
initial_conditions_data,
PSI.PowerAboveMinimumVariable(),
T,
)[
1,
name,
]
@test PSI.jump_value(PSI.get_value(ic)) == power
end
end
function check_initialization_variable_count(
model,
::S,
::Type{T},
) where {S <: PSI.VariableType, T <: PSY.Component}
container = PSI.get_optimization_container(model)
initial_conditions_data = PSI.get_initial_conditions_data(container)
no_component = length(PSY.get_components(PSY.get_available, T, model.sys))
variable = PSI.get_initial_condition_value(initial_conditions_data, S(), T)
rows, cols = size(variable)
@test rows * cols == no_component * PSI.INITIALIZATION_PROBLEM_HORIZON
end
function check_variable_count(
model,
::S,
::Type{T},
) where {S <: PSI.VariableType, T <: PSY.Component}
no_component = length(PSY.get_components(PSY.get_available, T, model.sys))
time_steps = PSI.get_time_steps(PSI.get_optimization_container(model))[end]
variable = PSI.get_variable(PSI.get_optimization_container(model), S(), T)
@test length(variable) == no_component * time_steps
end
function check_initialization_constraint_count(
model,
::S,
::Type{T};
filter_func=PSY.get_available,
meta=ISOPT.CONTAINER_KEY_EMPTY_META,
) where {S <: PSI.ConstraintType, T <: PSY.Component}
container = model.internal.ic_model_container
no_component = length(PSY.get_components(filter_func, T, model.sys))
time_steps = PSI.get_time_steps(container)[end]
constraint = PSI.get_constraint(container, S(), T, meta)
@test length(constraint) == no_component * time_steps
end
function check_constraint_count(
model,
::S,
::Type{T};
filter_func=PSY.get_available,
meta=ISOPT.CONTAINER_KEY_EMPTY_META,
) where {S <: PSI.ConstraintType, T <: PSY.Component}
no_component = length(PSY.get_components(filter_func, T, model.sys))
time_steps = PSI.get_time_steps(PSI.get_optimization_container(model))[end]
constraint = PSI.get_constraint(PSI.get_optimization_container(model), S(), T, meta)
@test length(constraint) == no_component * time_steps
end
function check_constraint_count(
model,
::PSI.RampConstraint,
::Type{T},
) where {T <: PSY.Component}
container = PSI.get_optimization_container(model)
set_name =
PSY.get_name.(
PSI._get_ramp_constraint_devices(
container,
get_components(PSY.get_available, T, model.sys),
),
)
check_constraint_count(
model,
PSI.RampConstraint(),
T;
meta="up",
filter_func=x -> x.name in set_name,
)
check_constraint_count(
model,
PSI.RampConstraint(),
T;
meta="dn",
filter_func=x -> x.name in set_name,
)
return
end
function check_constraint_count(
model,
::PSI.DurationConstraint,
::Type{T},
) where {T <: PSY.Component}
container = PSI.get_optimization_container(model)
resolution = PSI.get_resolution(container)
steps_per_hour = 60 / Dates.value(Dates.Minute(resolution))
fraction_of_hour = 1 / steps_per_hour
duration_devices = filter!(
x -> !(
PSY.get_time_limits(x).up <= fraction_of_hour &&
PSY.get_time_limits(x).down <= fraction_of_hour
),
collect(get_components(PSY.get_available, T, model.sys)),
)
set_name = PSY.get_name.(duration_devices)
check_constraint_count(
model,
PSI.DurationConstraint(),
T;
meta="up",
filter_func=x -> x.name in set_name,
)
return check_constraint_count(
model,
PSI.DurationConstraint(),
T;
meta="dn",
filter_func=x -> x.name in set_name,
)
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 1737 | function modify_ren_curtailment_cost!(sys)
rdispatch = get_components(RenewableDispatch, sys)
for ren in rdispatch
# We consider 15 $/MWh as a reasonable cost for renewable curtailment
cost = TwoPartCost(15.0, 0.0)
set_operation_cost!(ren, cost)
end
return
end
function _build_battery(
bus::PSY.Bus,
energy_capacity,
rating,
efficiency_in,
efficiency_out,
)
name = string(bus.number) * "_BATTERY"
device = EnergyReservoirStorage(;
name=name,
available=true,
bus=bus,
prime_mover_type=PSY.PrimeMovers.BA,
storage_technology_type=PSY.StorageTech.OTHER_CHEM,
storage_capacity=energy_capacity,
storage_level_limits=(min=0.0, max=1.0),
initial_storage_capacity_level=0.2,
rating=rating,
active_power=rating,
cycle_limits=1000.0,
storage_target=1.0,
input_active_power_limits=(min=0.0, max=rating),
output_active_power_limits=(min=0.0, max=rating),
efficiency=(in=efficiency_in, out=efficiency_out),
reactive_power=0.0,
reactive_power_limits=nothing,
base_power=100.0,
operation_cost=PSY.StorageCost(
energy_shortage_cost=1000.0,
energy_surplus_cost=1000.0,
fixed=0.0,
shut_down=0.0,
start_up=0.0,
variable=VariableCost(3.0),
),
)
return device
end
function add_battery_to_bus!(sys::System, bus_name::String)
bus = get_component(Bus, sys, bus_name)
bat = _build_battery(bus, 8.0, 4.0, 0.93, 0.93)
add_component!(sys, bat)
for s in get_components(Reserve, sys)
add_service!(bat, s, sys)
end
return
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | code | 5040 | function get_thermal_standard_uc_template()
template = ProblemTemplate(CopperPlatePowerModel)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, ThermalStandard, ThermalStandardUnitCommitment)
return template
end
function get_thermal_dispatch_template_network(network=CopperPlatePowerModel)
template = ProblemTemplate(network)
set_device_model!(template, ThermalStandard, ThermalBasicDispatch)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, MonitoredLine, StaticBranchBounds)
set_device_model!(template, Line, StaticBranch)
set_device_model!(template, Transformer2W, StaticBranch)
set_device_model!(template, TapTransformer, StaticBranch)
set_device_model!(template, TwoTerminalHVDCLine, HVDCTwoTerminalLossless)
return template
end
function get_template_basic_uc_simulation()
template = ProblemTemplate(CopperPlatePowerModel)
set_device_model!(template, ThermalStandard, ThermalBasicUnitCommitment)
set_device_model!(template, RenewableDispatch, RenewableFullDispatch)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, InterruptiblePowerLoad, StaticPowerLoad)
set_device_model!(template, HydroEnergyReservoir, HydroDispatchRunOfRiver)
return template
end
function get_template_standard_uc_simulation()
template = get_template_basic_uc_simulation()
set_device_model!(template, ThermalStandard, ThermalStandardUnitCommitment)
return template
end
function get_template_nomin_ed_simulation(network=CopperPlatePowerModel)
template = ProblemTemplate(network)
set_device_model!(template, ThermalStandard, ThermalDispatchNoMin)
set_device_model!(template, RenewableDispatch, RenewableFullDispatch)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, InterruptiblePowerLoad, PowerLoadDispatch)
set_device_model!(template, HydroEnergyReservoir, HydroDispatchRunOfRiver)
return template
end
function get_template_hydro_st_uc(network=CopperPlatePowerModel)
template = ProblemTemplate(network)
set_device_model!(template, ThermalStandard, ThermalStandardUnitCommitment),
set_device_model!(template, RenewableDispatch, RenewableFullDispatch),
set_device_model!(template, PowerLoad, StaticPowerLoad),
set_device_model!(template, InterruptiblePowerLoad, PowerLoadDispatch),
set_device_model!(template, HydroEnergyReservoir, HydroDispatchReservoirStorage),
return template
end
function get_template_hydro_st_ed(network=CopperPlatePowerModel, duals=[])
template = ProblemTemplate(network)
set_device_model!(template, ThermalStandard, ThermalBasicDispatch)
set_device_model!(template, RenewableDispatch, RenewableFullDispatch)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, InterruptiblePowerLoad, PowerLoadDispatch)
set_device_model!(template, HydroEnergyReservoir, HydroDispatchReservoirStorage)
return template
end
function get_template_dispatch_with_network(network=PTDFPowerModel)
template = ProblemTemplate(network)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, ThermalStandard, ThermalBasicDispatch)
set_device_model!(template, Line, StaticBranch)
set_device_model!(template, Transformer2W, StaticBranch)
set_device_model!(template, TapTransformer, StaticBranch)
set_device_model!(template, TwoTerminalHVDCLine, HVDCTwoTerminalLossless)
return template
end
function get_template_basic_uc_storage_simulation()
template = ProblemTemplate(CopperPlatePowerModel)
set_device_model!(template, ThermalStandard, ThermalBasicUnitCommitment)
set_device_model!(template, RenewableDispatch, RenewableFullDispatch)
set_device_model!(template, PowerLoad, StaticPowerLoad)
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => false,
),
)
set_device_model!(template, device_model)
return template
end
function get_template_dispatch_storage_simulation()
template = ProblemTemplate(CopperPlatePowerModel)
set_device_model!(template, ThermalStandard, ThermalBasicDispatch)
set_device_model!(template, RenewableDispatch, RenewableFullDispatch)
set_device_model!(template, PowerLoad, StaticPowerLoad)
device_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict{String, Any}(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => false,
),
)
set_device_model!(template, device_model)
return template
end
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 635 | # Contributing
Community driven development of this package is encouraged. To maintain code quality standards, please adhere to the following guidlines when contributing:
- To get started, <a href="https://www.clahub.com/agreements/NREL-Sienna/StorageSystemsSimulations.jl">sign the Contributor License Agreement</a>.
- Please do your best to adhere to our [coding style guide](docs/src/developer/style.md).
- To submit code contributions, [fork](https://help.github.com/articles/fork-a-repo/) the repository, commit your changes, and [submit a pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/).
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 1358 | # StorageSystemsSimulations.jl
[](https://github.com/NREL-Sienna/StorageSystemsSimulations.jl/actions/workflows/main-tests.yml)
[](https://codecov.io/gh/NREL-Sienna/StorageSystemsSimulations.jl)
[](https://nrel-sienna.github.io/StorageSystemsSimulations.jl/latest)
[<img src="https://img.shields.io/badge/slack-@Sienna/PSY-sienna.svg?logo=slack">](https://join.slack.com/t/nrel-sienna/shared_invite/zt-glam9vdu-o8A9TwZTZqqNTKHa7q3BpQ)
## Development
Contributions to the development and enahancement of StorageSystemsSimulations is welcome. Please see [CONTRIBUTING.md](https://github.com/NREL-Sienna/StorageSystemsSimulations.jl/blob/master/CONTRIBUTING.md) for code contribution guidelines.
## License
StorageSystemsSimulations is released under a BSD [license](https://github.com/NREL-Sienna/StorageSystemsSimulations/blob/master/LICENSE). StorageSystemsSimulations has been developed as part of ... at the U.S. Department of Energy's National Renewable Energy Laboratory ([NREL](https://www.nrel.gov/))
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 249 | Thanks for opening a PR to StorageSystemsSimulations.jl, please take note of the following when making a PR:
Check the [contributor guidelines](https://nrel-sienna.github.io/StorageSystemsSimulations.jl/stable/code_base_developer_guide/developer/)
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 1944 | # StorageSystemsSimulations.jl
```@meta
CurrentModule = StorageSystemsSimulations
```
## Overview
`StorageSimulations.jl` is a `PowerSimulations.jl` extension to support formulations and models
related to energy storage.
An Operational Storage Model can have multiple combinations of different restrictions. For instance,
it might be relevant to a study to consider cycling limits or employ energy targets coming from a planning model. To manage all these variations `StorageSimulations.jl` heavily uses the `DeviceModel` attributes feature.
For example, the formulation `StorageDispatchWithReserves` can be parametrized as follows:
```julia
DeviceModel(
StorageType, # E.g. EnergyReservoirStorage
StorageDispatchWithReserves;
attributes=Dict(
"reservation" => true,
"cycling_limits" => false,
"energy_target" => false,
"complete_coverage" => false,
"regularization" => true,
),
use_slacks=false,
)
```
Each formulation can have different implementations for these attributes and the details can be found in the Formulation Library section in the documentation.
## Installation
The latest stable release of PowerSimulations can be installed using the Julia package manager with
```
(@v1.10) pkg> add PowerSimulations StorageSystemsSimulations
```
For the current development version, "checkout" this package with
```
(@v1.10) pkg> add PowerSimulations StorageSystemsSimulations#main
```
An appropriate optimization solver is required for running StorageSystemsSimulations models. Refer to [`JuMP.jl` solver's page](https://jump.dev/JuMP.jl/stable/installation/#Install-a-solver) to select the most appropriate for the application of interest.
StorageSystemsSimulations has been developed as part of the Scalable Integrated Infrastructure Planning (SIIP) initiative at the U.S. Department of Energy's National Renewable Energy
Laboratory ([NREL](https://www.nrel.gov/)).
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 1530 | # Quick Start Guide
- **Julia:** If this is your first time using Julia visit our [Introduction to Julia](https://nrel-Sienna.github.io/SIIP-Tutorial/fundamentals/introduction-to-julia/) and the official [Getting started with Julia](https://julialang.org/learning/).
- **Package Installation:** If you want to install packages check the [Package Manager](https://pkgdocs.julialang.org/v1/environments/) instructions, or you can refer to the [StorageSystemsSimulations installation instructions](@ref Installation).
- **PowerSystems:** [PowerSystems.jl](https://github.com/nrel-Sienna/PowerSystems.jl) manages the data and is a fundamental dependency of PowerSimulations.jl. Check the [PowerSystems.jl Basics Tutorial](https://nrel-sienna.github.io/PowerSystems.jl/stable/tutorials/basics/) and [PowerSystems.jl documentation](https://nrel-Sienna.github.io/PowerSystems.jl/stable/) to understand how the inputs to the models are organized.
- **Dataset Library:** If you don't have a data set to start using `StorageSystemsSimulations.jl` check the test systems provided in [`PowerSystemCaseBuilder.jl`](https://nrel-sienna.github.io/PowerSystems.jl/stable/tutorials/powersystembuilder/)
!!! tip
If you need to develop a dataset for a simulation check the [PowerSystems.jl Tutorials](https://nrel-sienna.github.io/PowerSystems.jl/stable/tutorials/basics/) on how to parse data and attach time series
- **Tutorial:** If you are eager to run your first simulation visit the tutorial section of the documentation
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 422 | # StorageSystemsSimulations
```@meta
CurrentModule = StorageSystemsSimulations
DocTestSetup = quote
using StorageSystemsSimulations
end
```
## Exported
```@autodocs
Modules = [StorageSystemsSimulations]
Private = false
Filter = t -> typeof(t) === DataType ? !(t <: StorageSystemsSimulations.AbstractStorageFormulation) : true
```
## Internal
```@autodocs
Modules = [StorageSystemsSimulations]
Public = false
```
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 626 | # Guidelines for Developers
In order to contribute to `StorageSystemsSimulations.jl` repository please read the following sections of
[`InfrastructureSystems.jl`](https://github.com/NREL-Sienna/InfrastructureSystems.jl)
documentation in detail:
1. [Style Guide](https://nrel-sienna.github.io/InfrastructureSystems.jl/stable/style/)
2. [Contributing Guidelines](https://github.com/NREL-Sienna/StorageSystemsSimulations.jl/blob/master/CONTRIBUTING.md)
Pull requests are always welcome to fix bugs or add additional modeling capabilities.
**All the code contributions need to include tests with a minimum coverage of 70%**
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 12962 | # `StorageDispatchWithReserves` Formulation
```@docs
StorageDispatchWithReserves
```
## Attributes
- `"reservation"`: Forces the storage to operate exclusively on charge or discharge mode through the entire operation interval. We recommend setting this to false for models with relatively longer time resolutions (e.g., 1-Hr) since the storage can take simultaneous charge or discharge positions on average over the period.
- `"cycling_limits"`: This limits the storage's energy cycling. A single charging (discharging) cycle is fully charging (discharging) the storage once. The calculation uses the total energy charge/discharge and the number of cycles. Currently, the formulation only supports a fixed value per operation period. Additional variables for [`StorageChargeCyclingSlackVariable`](@ref) and [`StorageDischargeCyclingSlackVariable`](@ref) are included in the model if `use_slacks` is set to `true`.
- `"energy_target"`: Set a target at the end of the model horizon for the storage's state of charge. Currently, the formulation only supports a fixed value per operation period. Additional variables for [`StorageEnergyShortageVariable`](@ref) and [`StorageEnergySurplusVariable`](@ref) are included in the model if `use_slacks` is set to `true`.
!!! warning
Combining cycle limits and energy target attributes is not recommended. Both
attributes impose constraints on energy. There is no guarantee that the constraints can be satisfied simultaneously.
- `"complete_coverage"`: This attribute implements constraints that require the battery to cover the sum of all the ancillary services it participates in simultaneously. It is equivalent to holding energy in case all the services get deployed simultaneously. This constraint is added to the constraints that cover each service independently and corresponds to a more conservative operation regime.
- `"regularization"`: This attribute smooths the charge/discharge profiles to avoid bang-bang solutions via a penalty on the absolute value of the intra-temporal variations of the charge and discharge power. Solving for optimal storage dispatch can stall in models with large amounts of curtailment or long periods with negative or zero prices due to numerical degeneracy. The regularization term is scaled by the storage device's power limits to normalize the term and avoid additional penalties to larger storage units.
!!! danger
Setting the energy target attribute in combination with [`EnergyTargetFeedforward`](@ref) or [`EnergyLimitFeedforward`](@ref) is not permitted and StorageSystemsSimulations will throw an exception.
## Mathematical Model
### Sets
```math
\begin{align*}
&\mathcal{P}^{\text{as}_\text{up}} & \text{Up Ancillary Service Products Set}\\
&\mathcal{P}^{\text{as}_\text{dn}} & \text{Down Ancillary Service Products Set}\\
&\mathcal{P}^{\text{as}} := \bigcup\left\{ \mathcal{P}^{\text{as}_\text{up}}, \mathcal{P}^{\text{as}_\text{dn}}\right\} & \text{Ancillary Service Products Set}\\
&\mathcal{T} := \{1,\dots,T\} & \text{Time steps} \\
\end{align*}
```
### Parameters
#### Operational Parameters
```math
\begin{align*}
&P^{max,ch}_{st} &\text{Max Charge Power Storage [MW]}\\
&P^{max,ds}_{st} &\text{Max Discharge Power Storage [MW]}\\
&\eta^{ch}_{st} &\text{Charge Efficiency Storage [\%/hr]}\\
&\eta^{ds}_{st} &\text{Discharge Efficiency Storage [\%/hr]}\\
&R^{*}_{p, t} &\text{Ancillary Service deployment Forecast at time $t$ for service $p \in \mathcal{P}^{\text{as}}$ [\$/MW]}\\
&E^{max}_{st} &\text{Max Energy Storage Capacity [MWh]}\\
&E^{st}_{0} &\text{Storage initial energy [MWh]}\\
&E^{st}_{T} &\text{Storage Energy Target at the end of the horizon, i.e., time-step $T$ [MWh]}\\
&\Delta t &\text{Timestep length}\\
&C_{st} & \text{Maximum number of cycles over the horizon.} \\
&& \text{For DA the value is fixed to 3 and in RT the value depends on the DA allocation of cycles} \\
&N_{p} & \text{Number of periods of compliance to supply an AS.}\\
&& \text{For example Spinning reserve has 12 for 1 hour of compliance when $\Delta_t$ is 5-minutes.}
\end{align*}
```
#### Cost Parameters
```math
\begin{align*}
&\text{VOM} &\text{Storage Variable Operation and Maintenance Cost [\%/MWh]}\\
&\rho^{e+} &\text{Storage Surplus penalty at end of target cost [\$/MWh]. Used when \texttt{use\_slacks = true}}\\
&\rho^{e-} &\text{Storage Shortage penalty at end of target cost [\$/MWh]. Used when \texttt{use\_slacks = true}}\\
&\rho^{c} &\text{Storage Cycling Penalty [\$/MWh]. Used when \texttt{use\_slacks = true}}\\
&\rho^{z} &\text{Regularization Terms Penalty. Used when \texttt{"regularization" => true}}\\
\end{align*}
```
### Variables
```math
\begin{align*}
&p^{st, ch}_{t} & \in [0, P^{max,ch}_{st}] &\quad\text{Expected Storage charging power}\\
&p^{st, ds}_{t} & \in [0, P^{max,ds}_{st}] &\quad\text{Expected Storage discharging power}\\
&e^{st}_{t} & \in [0, E^{max}_{st}] &\quad \text{Expected Storage Energy}\\
&\text{ss}^{st}_{t} & \in \{ 0, 1 \} &\quad \text{Charge/Discharge status Storage. Used when \texttt{"reservation" => true}}\\
&sb_{stc,p,t} & \in [0, P^{max,ch}_{st}] & \quad \text{Ancillary service fraction assigned to Storage Charging}\\
&sb_{std,p,t} & \in [0, P^{max,ds}_{st}] & \quad \text{Ancillary service fraction assigned to Storage Discharging}\\
&e^{st+} & \in [0, E^{max}_{st}] &\quad \text{Storage Energy Surplus above target. Used when \texttt{use\_slacks = true}}\\
&e^{st-} & \in [0, E^{max}_{st}] &\quad \text{Storage Energy Shortage below target. Used when \texttt{use\_slacks = true}}\\
&c^{ch-} & \in [0, T C_{st}] &\quad \text{Charging Cycling Shortage. Used when \texttt{use\_slacks = true}}\\
&c^{ds-} & \in [0, T C_{st}] &\quad \text{Discharging Cycling Shortage. Used when \texttt{use\_slacks = true}}\\
&z^{st, ch}_{t} & \in [0, P^{max,ch}_{st}] &\quad \text{Regularization charge variable. Used when \texttt{"regularization" => true}}\\
&z^{st, ds}_{t} & \in [0, P^{max,ds}_{st}] &\quad \text{Regularization discharge variable. Used when \texttt{"regularization" => true}}\\
\end{align*}
```
### Model
```math
\begin{aligned}
\min_{\substack{\boldsymbol{p}^{st, ch}, \boldsymbol{p}^{st, ds}, \boldsymbol{e}^{st}, \\ e^{st+}, e^{st-}, c^{ch-} + c^{ds-}}}
& \rho^{e+} e^{st+} + \rho^{e-} e^{st-} + \rho^{c} \left(c^{ch-} + c^{ds-} \right) + \rho^{z} \left(\frac{z^{ch}}{P^{max,ch}_{st}} + \frac{z^{ds}}{P^{max,ds}_{st}} \right)\\
& +\Delta t \sum_{t \in \mathcal{T}} \text{VOM}_{st} \left ( \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{stc,p,t} + p^{st,ch}_{t} \right) + \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t} sb_{std,p,t} + p^{st,ds}_{t}\right) \right) &
\end{aligned}
```
```math
\begin{aligned}
\text{s.t.} & &\\
&\text{Power Limit Constraints.}&\\
&p^{st, ch}_{t} + \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} sb_{stc,p,t} \leq (1 - \text{ss}^{st}_{t})P^{max,ch}_{st} & \quad \forall t \in \mathcal{T} \\
& p^{st, ch}_{t} - \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} sb_{stc,p,t} \geq 0 & \quad \forall t \in \mathcal{T}\\
& p^{st, ds}_{t} + \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} sb_{std,p,t} \leq \text{ss}^{st}_{t}P^{max,ds}_{st} & \forall t \in \mathcal{T}\\
& p^{st, ds}_{t} - \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} sb_{std,p,t} \geq 0 & \forall t \in \mathcal{T}\\
&\text{Energy Storage Limit Constraints}&\\
&e^{st}_{t} \leq E^{max}_{st} & \forall t \in \mathcal{T}\\
& e^{st}_{t} \geq E^{min}_{st} & \forall t \in \mathcal{T}\\
&\text{Energy Bookkeeping constraints}&\\
& E^{st}_{0} + \Delta t \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,1} sb_{stc,p,1} + p^{st,ch}_{1} - \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,1} sb_{stc,p,1}\right)\eta^{ch}_{st}&\\
&-\Delta t\left(\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,1} sb_{std,p,1} + p^{st,ds}_{1} - \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{std,p,1}\right)\frac{1}{\eta^{ds}_{st}}=e^{st}_{1}\\
&e^{st}_{t-1} + \Delta t \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{stc,p,t} + p^{st,ch}_{t} - \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t} sb_{stc,p,t}\right)\eta^{ch}_{st}&\\
&-\Delta t\left(\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t} sb_{std,p,t} + p^{st,ds}_{t} - \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{std,p,t}\right)\frac{1}{\eta^{ds}_{st}} =e^{st}_{t} & \forall t \in \mathcal{T} \setminus {1}\\
&\text{End of period energy target constraint. Used when \texttt{"energy\_target" => true}}&\\
&e^{st}_{T} + e^{st+} - e^{st-} = E^{st}_{T}&\\
&\text{Storage Cycling Limits Constraints. Used when \texttt{"cycling\_limits" => true}}&\\
& \sum_{t \in \mathcal{T}} \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t} sb_{std,p,t} + p^{st,ds}_{t}\right)\frac{1}{\eta^{ds}_{st}} \Delta t - c^{ds-} \leq C_{st} E^{max}_{st} &\\
& \sum_{t \in \mathcal{T}} \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{stc,p,t} + p^{st,ch}_{t} \right)\eta^{ch}_{st} \Delta t - c^{ch-} \leq C_{st} E^{max}_{st} \\
&\text{Single Ancillary Services Energy Coverage}&\\
& sb_{stc,p,t} \eta^{ch}_{st} N_{p} \Delta t \le E_{st}^{max} - e^{st}_{t} & \forall p \in \mathcal{P}^{as_{dn}} \ \forall t \in \mathcal{T}\\
& sb_{std,p,t} \frac{1}{\eta^{ds}_{st}} N_{p} \Delta t \leq e^{st}_{t}- E^{min}_{st} & \forall p \in \mathcal{P}^{as_{up}}, \ \forall t \in \mathcal{T}\\
& sb_{stc,p,1} \eta^{ch}_{st} N_{p} \Delta t \le E_{st}^{max} - e^{st}_0 & \forall p \in \mathcal{P}^{as_{dn}}\\
& sb_{stc,p,t} \eta^{ch}_{st} N_{p} \Delta t \le E_{st}^{max} - e^{st}_{t-1} & \forall p \in \mathcal{P}^{as_{dn}} \ \forall t \in \mathcal{T} \setminus 1\\
&sb_{std,p,1} \frac{1}{\eta^{ds}_{st}} N_{p} \Delta t \leq e^{st}_0 - E^{min}_{st} & \forall p \in \mathcal{P}^{as_{up}}\\
& sb_{std,p,t} \frac{1}{\eta^{ds}_{st}} N_{p} \Delta t \leq e^{st}_{t-1} - E^{min}_{st} & \forall p \in \mathcal{P}^{as_{up}}, \ \forall t \in \mathcal{T} \setminus 1 \\
&\text{Complete Ancillary Services Energy Coverage. Used when \texttt{"complete\_coverage" => true}}&\\
& \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} sb_{stc,p,t} \eta^{ch}_{st} N_{p} \Delta t \le E_{st}^{max} - e^{st}_{t} & \forall t \in \mathcal{T}\\
& \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} sb_{std,p,t} \frac{1}{\eta^{ds}_{st}} N_{p} \Delta t \leq e^{st}_{t}- E^{min}_{st} & \forall t \in \mathcal{T}\\
& \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} sb_{stc,p,1} \eta^{ch}_{st} N_{p} \Delta t \le E_{st}^{max} - e^{st}_0 &\\
&\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} sb_{stc,p,t} \eta^{ch}_{st} N_{p} \Delta t \le E_{st}^{max} - e^{st}_{t-1} & \forall t \in \mathcal{T} \setminus 1\\
&\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} sb_{std,p,1} \frac{1}{\eta^{ds}_{st}} N_{p} \Delta t \leq e^{st}_0- E^{min}_{st} & \\
& \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} sb_{std,p,t} \frac{1}{\eta^{ds}_{st}} N_{p} \Delta t \leq e^{st}_{t-1}- E^{min}_{st} & \forall t \in \mathcal{T} \setminus 1\\
&\text{Regularization Constraints. Used when \texttt{"regularization" => true}}&\\
& \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t-1} sb_{stc,p,t-1} + p^{st,ch}_{t-1} - \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t-1} sb_{stc,p,t-1}\right) &\\
& - \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{stc,p,t} + p^{st,ch}_{t} - \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t} sb_{stc,p,t}\right) \le z^{st, ch}_{t} & \forall t \in \mathcal{T} \setminus 1\\
& \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t-1} sb_{stc,p,t-1} + p^{st,ch}_{t-1} - \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t-1} sb_{stc,p,t-1}\right) &\\
& - \left(\sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{stc,p,t} + p^{st,ch}_{t} - \sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t} sb_{stc,p,t}\right) \ge -z^{st, ch}_{t} & \forall t \in \mathcal{T} \setminus 1\\
&\left(\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t-1} sb_{std,p,t-1} + p^{st,ds}_{t-1} - \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t-1} sb_{std,p,t-1}\right) &\\
&-\left(\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t} sb_{std,p,t-1} + p^{st,ds}_{t} - \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{std,p,t}\right) \le z^{st, ds}_{t} & \forall t \in \mathcal{T} \setminus 1\\
&\left(\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t-1} sb_{std,p,t-1} + p^{st,ds}_{t-1} - \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t-1} sb_{std,p,t-1}\right) &\\
&-\left(\sum_{p \in \mathcal{P}^{\text{as}_\text{up}}} R^*_{p,t} sb_{std,p,t} + p^{st,ds}_{t} - \sum_{p \in \mathcal{P}^{\text{as}_\text{dn}}} R^*_{p,t} sb_{std,p,t}\right) \ge -z^{st, ds}_{t} & \forall t \in \mathcal{T} \setminus 1
\end{aligned}
```
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 975 | # [Simulating operations with StorageSystemSimulations](@id sim_tutorial)
**Originally Contributed by**: Jose Daniel Lara
## Introduction
## Load Packages
```@example op_problem
using PowerSystems
using PowerSimulations
using StorageSystemsSimulations
using PowerSystemCaseBuilder
using HiGHS # solver
```
## Data
!!! note
`PowerSystemCaseBuilder.jl` is a helper library that makes it easier to reproduce examples in the documentation and tutorials. Normally you would pass your local files to create the system data instead of calling the function `build_system`.
For more details visit [PowerSystemCaseBuilder Documentation](https://nrel-sienna.github.io/PowerSystems.jl/stable/tutorials/powersystembuilder/)
```@example op_problem
c_sys5_bat = build_system(
PSITestSystems,
"c_sys5_bat_ems";
add_single_time_series=true,
add_reserves=true,
)
orcd = get_component(ReserveDemandCurve, c_sys5_bat, "ORDC1")
set_available!(orcd, false)
```
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"BSD-3-Clause"
] | 0.10.1 | eead17e7a2ac1c553a274860b39b5953720c6893 | docs | 1987 | # [Solving an operation with StorageSystemSimulations](@id op_problem_tutorial)
**Originally Contributed by**: Jose Daniel Lara
## Introduction
## Load Packages
```@example op_problem
using PowerSystems
using PowerSimulations
using StorageSystemsSimulations
using PowerSystemCaseBuilder
using HiGHS # solver
```
## Data
!!! note
`PowerSystemCaseBuilder.jl` is a helper library that makes it easier to reproduce examples in the documentation and tutorials. Normally you would pass your local files to create the system data instead of calling the function `build_system`.
For more details visit [PowerSystemCaseBuilder Documentation](https://nrel-sienna.github.io/PowerSystems.jl/stable/tutorials/powersystembuilder/)
```@example op_problem
c_sys5_bat = build_system(
PSITestSystems,
"c_sys5_bat_ems";
add_single_time_series=true,
add_reserves=true,
)
orcd = get_component(ReserveDemandCurve, c_sys5_bat, "ORDC1")
set_available!(orcd, false)
```
```@example op_problem
batt = get_component(EnergyReservoirStorage, c_sys5_bat, "Bat2")
operation_cost = get_operation_cost(batt)
```
```@example op_problem
template_uc = ProblemTemplate(PTDFPowerModel)
set_device_model!(template_uc, ThermalStandard, ThermalStandardUnitCommitment)
set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch)
set_device_model!(template_uc, PowerLoad, StaticPowerLoad)
set_device_model!(template_uc, Line, StaticBranch)
```
```@example op_problem
storage_model = DeviceModel(
EnergyReservoirStorage,
StorageDispatchWithReserves;
attributes=Dict(
"reservation" => true,
"energy_target" => false,
"cycling_limits" => false,
"regulatization" => true,
),
)
set_device_model!(template_uc, storage_model)
```
```@example op_problem
set_service_model!(template_uc, ServiceModel(VariableReserve{ReserveUp}, RangeReserve))
set_service_model!(template_uc, ServiceModel(VariableReserve{ReserveDown}, RangeReserve))
```
| StorageSystemsSimulations | https://github.com/NREL-Sienna/StorageSystemsSimulations.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 7207 |
using StreamSampling
using Random, StatsBase, Distributions
using ChunkSplitters
using PyCall, BenchmarkTools
using CairoMakie
################
## sequential ##
################
function weighted_reservoir_sample(rng, a, ws, n)
return shuffle!(rng, weighted_reservoir_sample_seq(rng, a, ws, n)[1])
end
function weighted_reservoir_sample_seq(rng, a, ws, n)
m = min(length(a), n)
view_w_f_n = @view(ws[1:m])
w_sum = sum(view_w_f_n)
reservoir = sample(rng, @view(a[1:m]), Weights(view_w_f_n, w_sum), n)
length(a) <= n && return reservoir, w_sum
w_skip = skip(rng, w_sum, n)
@inbounds for i in n+1:length(a)
w_el = ws[i]
w_sum += w_el
if w_sum > w_skip
p = w_el/w_sum
q = 1-p
z = q^(n-4)
t = rand(rng, Uniform(z*q*q*q*q,1.0))
k = choose(n, p, q, t, z)
for j in 1:k
r = rand(rng, j:n)
@inbounds reservoir[r], reservoir[j] = reservoir[j], a[i]
end
w_skip = skip(rng, w_sum, n)
end
end
return reservoir, w_sum
end
function skip(rng, w_sum::AbstractFloat, n)
k = rand(rng)^(1/n)
return w_sum/k
end
function choose(n, p, q, t, z)
x = z*q*q*q*(q + n*p)
x > t && return 1
x += n*p*(n-1)*p*z*q*q/2
x > t && return 2
x += n*p*(n-1)*p*(n-2)*p*z*q/6
x > t && return 3
x += n*p*(n-1)*p*(n-2)*p*(n-3)*p*z/24
x > t && return 4
return quantile(Binomial(n, p), t)
end
#####################
## parallel 1 pass ##
#####################
function weighted_reservoir_sample_parallel_1_pass(rngs, a, ws, n)
nt = Threads.nthreads()
ss = Vector{Vector{eltype(a)}}(undef, nt)
w_sums = Vector{Float64}(undef, nt)
chunks_inds = chunks(a; n=nt)
Threads.@threads for (i, inds) in enumerate(chunks_inds)
s = weighted_reservoir_sample_seq(rngs[i], @view(a[inds]), @view(ws[inds]), n)
ss[i], w_sums[i] = s
end
W = sum(w_sums)
w_sums /= W
ns = rand(rngs[1], Multinomial(n, w_sums))
Threads.@threads for i in 1:nt
ss[i] = sample(rngs[i], ss[i], ns[i]; replace = false)
end
return shuffle!(rngs[1], reduce(vcat, ss))
end
#####################
## parallel 2 pass ##
#####################
function weighted_reservoir_sample_parallel_2_pass(rngs, a, ws, n)
nt = Threads.nthreads()
chunks_inds = chunks(a; n=nt)
w_sums = Vector{Float64}(undef, nt)
Threads.@threads for (i, inds) in enumerate(chunks_inds)
w_sums[i] = sum(@view(ws[inds]))
end
ss = Vector{Vector{eltype(a)}}(undef, nt)
W = sum(w_sums)
w_sums /= W
ns = rand(rngs[1], Multinomial(n, w_sums))
Threads.@threads for (i, inds) in enumerate(chunks_inds)
s = weighted_reservoir_sample_seq(rngs[i], @view(a[inds]), @view(ws[inds]), ns[i])
ss[i] = s[1]
end
return shuffle!(rngs[1], reduce(vcat, ss))
end
function sample_parallel_2_pass(rngs, a, ws, n)
nt = Threads.nthreads()
chunks_inds = chunks(a; n=nt)
w_sums = Vector{Float64}(undef, nt)
Threads.@threads for (i, inds) in enumerate(chunks_inds)
w_sums[i] = sum(@view(ws[inds]))
end
ss = Vector{Vector{eltype(a)}}(undef, nt)
W = sum(w_sums)
w_sums /= W
ns = rand(rngs[1], Multinomial(n, w_sums))
Threads.@threads for (i, inds) in enumerate(chunks_inds)
s = sample(rngs[i], @view(a[inds]), Weights(@view(ws[inds])), ns[i]; replace = true)
ss[i] = s
end
return shuffle!(rngs[1], reduce(vcat, ss))
end
################
## benchmarks ##
################
rng = Xoshiro(42);
rngs = Tuple(Xoshiro(rand(rng, 1:10000)) for _ in 1:Threads.nthreads());
a = collect(1:10^7);
wsa = Float64.(a);
times_other_parallel = Float64[]
for i in 0:6
b = @benchmark sample_parallel_2_pass($rngs, $a, $wsa, 10^$i)
push!(times_other_parallel, median(b.times)/10^6)
println("other $(10^i): $(median(b.times)/10^6) ms")
end
times_other = Float64[]
for i in 0:6
b = @benchmark sample($rng, $a, Weights($wsa), 10^$i; replace = true)
push!(times_other, median(b.times)/10^6)
println("other $(10^i): $(median(b.times)/10^6) ms")
end
## single thread
times_single_thread = Float64[]
for i in 0:6
b = @benchmark weighted_reservoir_sample($rng, $a, $wsa, 10^$i)
push!(times_single_thread, median(b.times)/10^6)
println("sequential $(10^i): $(median(b.times)/10^6) ms")
end
# multi thread 1 pass - 6 threads
times_multi_thread = Float64[]
for i in 0:6
b = @benchmark weighted_reservoir_sample_parallel_1_pass($rngs, $a, $wsa, 10^$i)
push!(times_multi_thread, median(b.times)/10^6)
println("parallel $(10^i): $(median(b.times)/10^6) ms")
end
# multi thread 2 pass - 6 threads
times_multi_thread_2 = Float64[]
for i in 0:6
b = @benchmark weighted_reservoir_sample_parallel_2_pass($rngs, $a, $wsa, 10^$i)
push!(times_multi_thread_2, median(b.times)/10^6)
println("parallel $(10^i): $(median(b.times)/10^6) ms")
end
py"""
import numpy as np
import timeit
a = np.arange(1, 10**7+1, dtype=np.int64);
wsa = np.arange(1, 10**7+1, dtype=np.float64)
p = wsa/np.sum(wsa);
def sample_times_numpy():
times_numpy = []
for i in range(7):
ts = []
for j in range(11):
t = timeit.timeit("np.random.choice(a, size=10**i, replace=True, p=p)",
setup=f"from __main__ import a, p; import numpy as np; i={i}",
number=1)
ts.append(t)
tv = (sorted(ts)[5]*10**3)
times_numpy.append(tv)
print(tv)
return times_numpy
"""
times_numpy = py"sample_times_numpy()"
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), size = (1100, 700));
ax1 = Axis(f[1, 1], yscale=log10, xscale=log10,
yminorticksvisible = true, yminorgridvisible = true,
yminorticks = IntervalsBetween(10))
scatterlines!(ax1, [10^i/10^7 for i in 1:6], times_numpy[2:end], label = "numpy.choice sequential", marker = :circle, markersize = 12, linestyle = :dot)
scatterlines!(ax1, [10^i/10^7 for i in 1:6], times_other[2:end], label = "StatsBase.sample sequential", marker = :rect, markersize = 12, linestyle = :dot)
scatterlines!(ax1, [10^i/10^7 for i in 1:6], times_other_parallel[2:end], label = "StatsBase.sample parallel (2 passes)", marker = :diamond, markersize = 12, linestyle = :dot)
scatterlines!(ax1, [10^i/10^7 for i in 1:6], times_single_thread[2:end], label = "WRSWR-SKIP sequential", marker = :hexagon, markersize = 12, linestyle = :dot)
scatterlines!(ax1, [10^i/10^7 for i in 1:6], times_multi_thread[2:end], label = "WRSWR-SKIP parallel (1 pass)", marker = :cross, markersize = 12, linestyle = :dot)
scatterlines!(ax1, [10^i/10^7 for i in 1:6], times_multi_thread_2[2:end], label = "WRSWR-SKIP parallel (2 passes)", marker = :xcross, markersize = 12, linestyle = :dot)
Legend(f[1,2], ax1, labelsize=10, framevisible = false)
ax1.xtickformat = x -> string.(round.(x.*100, digits=10)) .* "%"
ax1.title = "Comparison between weighted sampling algorithms in a non-streaming context"
ax1.xticks = [10^(i)/10^7 for i in 1:6]
ax1.xlabel = "sample ratio"
ax1.ylabel = "time (ms)"
f
save("comparison_WRSWR_SKIP_alg.png", f)
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 2927 | using StreamSampling, StatsBase
using Random, Printf, BenchmarkTools
using CairoMakie
rng = Xoshiro(42);
stream = Iterators.filter(x -> x != 10, 1:10^7);
pop = collect(stream);
w(el) = Float64(el);
weights = Weights(w.(stream));
algs = (AlgL(), AlgRSWRSKIP(), AlgAExpJ(), AlgWRSWRSKIP());
algsweighted = (AlgAExpJ(), AlgWRSWRSKIP());
algsreplace = (AlgRSWRSKIP(), AlgWRSWRSKIP());
sizes = (10^3, 10^4, 10^5, 10^6)
p = Dict((0, 0) => 1, (0, 1) => 2, (1, 0) => 3, (1, 1) => 4);
m_times = Matrix{Vector{Float64}}(undef, (3, 4));
for i in eachindex(m_times) m_times[i] = Float64[] end
m_mems = Matrix{Vector{Float64}}(undef, (3, 4));
for i in eachindex(m_mems) m_mems[i] = Float64[] end
for m in algs
for size in sizes
replace = m in algsreplace
weighted = m in algsweighted
if weighted
b1 = @benchmark itsample($rng, $stream, $w, $size, $m) evals=1
b2 = @benchmark sample($rng, collect($stream), Weights($w.($stream)), $size; replace = $replace) evals=1
b3 = @benchmark sample($rng, $pop, $weights, $size; replace = $replace) evals=1
else
b1 = @benchmark itsample($rng, $stream, $size, $m) evals=1
b2 = @benchmark sample($rng, collect($stream), $size; replace = $replace) evals=1
b3 = @benchmark sample($rng, $pop, $size; replace = $replace) evals=1
end
ts = [median(b1.times), median(b2.times), median(b3.times)] .* 1e-6
ms = [b1.memory, b2.memory, b3.memory] .* 1e-6
c = p[(weighted, replace)]
for r in 1:3
push!(m_times[r, c], ts[r])
push!(m_mems[r, c], ms[r])
end
end
end
f = Figure(fontsize = 9,);
axs = [Axis(f[i, j], yscale = log10, xscale = log10) for i in 1:4 for j in 1:2];
labels = (
"stream-based\n(StreamSampling.itsample)",
"collection-based with setup\n(StatsBase.sample)",
"collection-based\n(StatsBase.sample)"
)
markers = (:circle, :rect, :utriangle)
a, b = 0, 0
for j in 1:8
m = j in (3, 4, 7, 8) ? m_mems : m_times
m == m_mems ? (a += 1) : (b += 1)
s = m == m_mems ? a : b
for i in 1:3
scatterlines!(axs[j], [0.01, 0.1, 1, 10], m[i, s]; label = labels[i], marker = markers[i])
end
axs[j].ylabel = m == m_mems ? "memory (Mb)" : "time (ms)"
axs[j].xtickformat = x -> string.(x) .* "%"
j in (3, 4, 7, 8) && (axs[j].xlabel = "sample size")
pr = j in (1, 2) ? "un" : ""
t = j in (1, 5) ? "out" : ""
j in (1, 2, 5, 6) && (axs[j].title = pr * "weighted with" * t * " replacement")
axs[j].titlegap = 8.0
j in (1, 2, 5, 6) && hidexdecorations!(axs[j], grid = false)
end
f[5, 1] = Legend(f, axs[1], framevisible = false, orientation = :horizontal,
halign = :center, padding=(248,0,0,0))
Label(f[0, :], "Comparison between stream-based and collection-based algorithms", fontsize = 13,
font=:bold)
save("comparison_stream_algs.png", f)
f
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 660 | using Documenter
using StreamSampling
println("Documentation Build")
makedocs(
modules = [StreamSampling],
sitename = "StreamSampling.jl",
pages = [
"An Illustrative Example" => "index.md",
"API" => "api.md",
],
warnonly = [:doctest, :missing_docs, :cross_references],
)
@info "Deploying Documentation"
CI = get(ENV, "CI", nothing) == "true" || get(ENV, "GITHUB_TOKEN", nothing) !== nothing
if CI
deploydocs(
repo = "github.com/JuliaDynamics/StreamSampling.jl.git",
target = "build",
push_preview = true,
devbranch = "main",
)
end
println("Finished boulding and deploying docs.")
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 8628 |
"""
ReservoirSample([rng], T, method = AlgRSWRSKIP())
ReservoirSample([rng], T, n::Int, method = AlgL(); ordered = false)
Initializes a reservoir sample which can then be fitted with [`fit!`](@ref).
The first signature represents a sample where only a single element is collected.
If `ordered` is true, the reservoir sample values can be retrived in the order
they were collected with [`ordvalue`](@ref).
Look at the [`Sampling Algorithms`](@ref) section for the supported methods.
"""
function ReservoirSample(T, method::ReservoirAlgorithm = AlgRSWRSKIP())
return ReservoirSample(Random.default_rng(), T, method, MutSample())
end
function ReservoirSample(rng::AbstractRNG, T, method::ReservoirAlgorithm = AlgRSWRSKIP())
return ReservoirSample(rng, T, method, MutSample())
end
Base.@constprop :aggressive function ReservoirSample(T, n::Integer, method::ReservoirAlgorithm=AlgL();
ordered = false)
return ReservoirSample(Random.default_rng(), T, n, method, MutSample(), ordered ? Ord() : Unord())
end
Base.@constprop :aggressive function ReservoirSample(rng::AbstractRNG, T, n::Integer,
method::ReservoirAlgorithm=AlgL(); ordered = false)
return ReservoirSample(rng, T, n, method, MutSample(), ordered ? Ord() : Unord())
end
"""
fit!(rs::AbstractReservoirSample, el)
fit!(rs::AbstractReservoirSample, el, w)
Updates the reservoir sample by taking into account the element passed.
If the sampling is weighted also the weight of the elements needs to be
passed.
"""
@inline OnlineStatsBase.fit!(s::AbstractReservoirSample, el) = OnlineStatsBase._fit!(s, el)
@inline OnlineStatsBase.fit!(s::AbstractReservoirSample, el, w) = OnlineStatsBase._fit!(s, el, w)
"""
value(rs::AbstractReservoirSample)
Returns the elements collected in the sample at the current
sampling stage.
Note that even if the sampling respects the schema it is assigned
when [`ReservoirSample`](@ref) is instantiated, some ordering in
the sample can be more probable than others. To represent each one
with the same probability call `shuffle!` over the result.
"""
OnlineStatsBase.value(s::AbstractReservoirSample) = error("Abstract version")
"""
ordvalue(rs::AbstractReservoirSample)
Returns the elements collected in the sample at the current
sampling stage in the order they were collected. This applies
only when `ordered = true` is passed in [`ReservoirSample`](@ref).
"""
ordvalue(s::AbstractReservoirSample) = error("Not an ordered sample")
"""
nobs(rs::AbstractReservoirSample)
Returns the total number of elements that have been observed so far
during the sampling process.
"""
OnlineStatsBase.nobs(s::AbstractReservoirSample) = s.seen_k
"""
Base.empty!(rs::AbstractReservoirSample)
Resets the reservoir sample to its initial state.
Useful to avoid allocating a new sample in some cases.
"""
function Base.empty!(::AbstractReservoirSample)
error("Abstract Version")
end
"""
Base.merge!(rs::AbstractReservoirSample, rs::AbstractReservoirSample...)
Updates the first reservoir sample by merging its value with the values
of the other samples. Currently only supported for samples with replacement.
"""
function Base.merge!(::AbstractReservoirSample)
error("Abstract Version")
end
"""
Base.merge(rs::AbstractReservoirSample...)
Creates a new reservoir sample by merging the values
of the samples passed. Currently only supported for sample
with replacement.
"""
function OnlineStatsBase.merge(::AbstractReservoirSample)
error("Abstract Version")
end
"""
itsample([rng], iter, method = AlgRSWRSKIP())
itsample([rng], iter, wfunc, method = AlgWRSWRSKIP())
Return a random element of the iterator, optionally specifying a `rng`
(which defaults to `Random.default_rng()`) and a function `wfunc` which
accept each element as input and outputs the corresponding weight.
If the iterator is empty, it returns `nothing`.
-----
itsample([rng], iter, n::Int, method = AlgL(); ordered = false)
itsample([rng], iter, wfunc, n::Int, method = AlgAExpJ(); ordered = false)
Return a vector of `n` random elements of the iterator,
optionally specifying a `rng` (which defaults to `Random.default_rng()`)
a weight function `wfunc` and a `method`. `ordered` dictates whether an
ordered sample (also called a sequential sample, i.e. a sample where items
appear in the same order as in `iter`) must be collected.
If the iterator has less than `n` elements, in the case of sampling without
replacement, it returns a vector of those elements.
-----
itsample(rngs, iters, n::Int)
itsample(rngs, iters, wfuncs, n::Int)
Parallel implementation which returns a sample with replacement of size `n`
from the multiple iterables. All the arguments except from `n` must be tuples.
"""
function itsample(iter, method = AlgRSWRSKIP(); iter_type = infer_eltype(iter))
return itsample(Random.default_rng(), iter, method; iter_type)
end
function itsample(iter, n::Int, method = AlgL(); iter_type = infer_eltype(iter), ordered = false)
return itsample(Random.default_rng(), iter, n, method; ordered)
end
function itsample(iter, wv::Function, method = AlgWRSWRSKIP(); iter_type = infer_eltype(iter))
return itsample(Random.default_rng(), iter, wv, method)
end
function itsample(iter, wv::Function, n::Int, method = AlgAExpJ(); iter_type = infer_eltype(iter),
ordered = false)
return itsample(Random.default_rng(), iter, wv, n, method; iter_type, ordered)
end
Base.@constprop :aggressive function itsample(rng::AbstractRNG, iter, method = AlgRSWRSKIP();
iter_type = infer_eltype(iter))
if Base.IteratorSize(iter) isa Base.SizeUnknown
s = ReservoirSample(rng, iter_type, method, ImmutSample())
return update_all!(s, iter)
else
return sortedindices_sample(rng, iter)
end
end
Base.@constprop :aggressive function itsample(rng::AbstractRNG, iter, n::Int, method = AlgL();
iter_type = infer_eltype(iter), ordered = false)
if Base.IteratorSize(iter) isa Base.SizeUnknown
s = ReservoirSample(rng, iter_type, n, method, ImmutSample(), ordered ? Ord() : Unord())
return update_all!(s, iter, ordered)
else
replace = method isa AlgL || method isa AlgR ? false : true
sortedindices_sample(rng, iter, n; iter_type, replace, ordered)
end
end
function itsample(rng::AbstractRNG, iter, wv::Function, method = AlgWRSWRSKIP(); iter_type = infer_eltype(iter))
s = ReservoirSample(rng, iter_type, method, ImmutSample())
return update_all!(s, iter, wv)
end
Base.@constprop :aggressive function itsample(rng::AbstractRNG, iter, wv::Function, n::Int, method = AlgAExpJ();
iter_type = infer_eltype(iter), ordered = false)
s = ReservoirSample(rng, iter_type, n, method, ImmutSample(), ordered ? Ord() : Unord())
return update_all!(s, iter, ordered, wv)
end
function itsample(rngs::Tuple, iters::Tuple, n::Int,; iter_types = infer_eltype.(iters))
n_it = length(iters)
vs = Vector{Vector{Union{iter_types...}}}(undef, n_it)
ps = Vector{Float64}(undef, n_it)
Threads.@threads for i in 1:n_it
s = ReservoirSample(rngs[i], iter_types[i], n, AlgRSWRSKIP(), ImmutSample(), Unord())
vs[i], ps[i] = update_all_p!(s, iters[i])
end
ps /= sum(ps)
return shuffle!(rngs[1], reduce_samples(rngs, ps, vs))
end
function itsample(rngs::Tuple, iters::Tuple, wfuncs::Tuple, n::Int; iter_types = infer_eltype.(iters))
n_it = length(iters)
vs = Vector{Vector{Union{iter_types...}}}(undef, n_it)
ps = Vector{Float64}(undef, n_it)
Threads.@threads for i in 1:n_it
s = ReservoirSample(rngs[i], iter_types[i], n, AlgWRSWRSKIP(), ImmutSample(), Unord())
vs[i], ps[i] = update_all_p!(s, iters[i], wfuncs[i])
end
ps /= sum(ps)
return shuffle!(rngs[1], reduce_samples(rngs, ps, vs))
end
function update_all!(s, iter)
for x in iter
s = fit!(s, x)
end
return value(s)
end
function update_all!(s, iter, wv)
for x in iter
s = fit!(s, x, wv(x))
end
return value(s)
end
function update_all!(s, iter, ordered::Bool)
for x in iter
s = fit!(s, x)
end
return ordered ? ordvalue(s) : shuffle!(s.rng, value(s))
end
function update_all!(s, iter, ordered, wv)
for x in iter
s = fit!(s, x, wv(x))
end
return ordered ? ordvalue(s) : shuffle!(s.rng, value(s))
end
function update_all_p!(s, iter)
for x in iter
s = fit!(s, x)
end
return value(s), s.seen_k
end
function update_all_p!(s, iter, wv)
for x in iter
s = fit!(s, x, wv(x))
end
return value(s), s.state
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 1221 |
const SMWR = Union{SampleMultiAlgRSWRSKIP, SampleMultiAlgWRSWRSKIP}
reduce_samples(t) = error()
function reduce_samples(t, ss::T...) where {T<:SMWR}
nt = length(ss)
v = Vector{Vector{get_type_rs(t, ss...)}}(undef, nt)
ns = rand(ss[1].rng, Multinomial(length(value(ss[1])), get_ps(ss...)))
Threads.@threads for i in 1:nt
v[i] = sample(ss[i].rng, value(ss[i]), ns[i]; replace = false)
end
return reduce(vcat, v)
end
function reduce_samples(rngs, ps::Vector, vs::Vector)
nt = length(vs)
ns = rand(rngs[1], Multinomial(length(vs[1]), ps))
Threads.@threads for i in 1:nt
vs[i] = sample(rngs[i], vs[i], ns[i]; replace = false)
end
return reduce(vcat, vs)
end
function get_ps(ss::SampleMultiAlgRSWRSKIP...)
sum_w = sum(getfield(s, :seen_k) for s in ss)
return [s.seen_k/sum_w for s in ss]
end
function get_ps(ss::SampleMultiAlgWRSWRSKIP...)
sum_w = sum(getfield(s, :state) for s in ss)
return [s.state/sum_w for s in ss]
end
get_type_rs(::TypeS, s1::T, ss::T...) where {T<:SMWR} = eltype(value(s1))
function get_type_rs(::TypeUnion, s1::T, ss::T...) where {T<:SMWR}
return Union{eltype(value(s1)), Union{(eltype(value(s)) for s in ss)...}}
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 761 |
struct TypeS end
struct TypeUnion end
@hybrid struct RefVal{T}
value::T
RefVal{T}() where T = new{T}()
RefVal(value::T) where T = new{T}(value)
end
function infer_eltype(itr)
T1, T2 = eltype(itr), Base.@default_eltype(itr)
ifelse(T2 !== Union{} && T2 <: T1, T2, T1)
end
function sortedrandrange(rng, range, n)
exp_rands = randexp(rng, n)
sorted_rands = cumsum(exp_rands)
a, b = range.start, range.stop
range_size = b-a+1
cum_step = (sorted_rands[end] + randexp(rng)) / range_size
sorted_rands ./= cum_step
return ceil.(Int, sorted_rands)
end
function get_sorted_indices(rng, n, N, replace)
replace == true && return sortedrandrange(rng, 1:N, n)
return sort!(sample(rng, 1:N, n; replace=replace))
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 1394 |
"""
sortedindices_sample(rng, iter)
sortedindices_sample(rng, iter, n; replace = false, ordered = false)
Algorithm which generates sorted random indices used to retrieve the sample
from the iterable. The number of elements in the iterable needs to be known
before starting the sampling.
"""
function sortedindices_sample(rng, iter, n::Int;
iter_type = infer_eltype(iter), replace = false, ordered = false)
N = length(iter)
if N <= n
reservoir = collect(iter)
replace && return sample(rng, reservoir, n, ordered=ordered)
return ordered ? reservoir : shuffle!(rng, reservoir)
end
reservoir = Vector{iter_type}(undef, n)
indices = get_sorted_indices(rng, n, N, replace)
first_idx = indices[1]
el, state = iterate(iter)::Tuple
if first_idx != 1
el, state = skip_ahead_no_end(iter, state, first_idx - 2)
end
reservoir[1] = el
i = 2
@inbounds while i <= n
skip_k = indices[i] - indices[i-1] - 1
if skip_k >= 0
el, state = skip_ahead_no_end(iter, state, skip_k)
end
reservoir[i] = el
i += 1
end
return ordered ? reservoir : shuffle!(rng, reservoir)
end
function skip_ahead_no_end(iter, state, n)
for _ in 1:n
it = iterate(iter, state)::Tuple
state = it[2]
end
it = iterate(iter, state)::Tuple
return it
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 162 |
function sortedindices_sample(rng, iter; kwargs...)
k = rand(rng, 1:length(iter))
for (i, el) in enumerate(iter)
i == k && return el
end
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 2166 | module StreamSampling
using Accessors
using DataStructures
using Distributions
using HybridStructs
using OnlineStatsBase
using Random
using StatsBase
export fit!, merge!, value, ordvalue, nobs, itsample
export AbstractReservoirSample, ReservoirSample
export AlgL, AlgR, AlgRSWRSKIP, AlgARes, AlgAExpJ, AlgWRSWRSKIP
struct ImmutSample end
struct MutSample end
struct Ord end
struct Unord end
abstract type AbstractReservoirSample <: OnlineStat{Any} end
abstract type ReservoirAlgorithm end
"""
Implements random sampling without replacement.
Adapted from algorithm R described in "Random sampling with a reservoir, J. S. Vitter, 1985".
"""
struct AlgR <: ReservoirAlgorithm end
"""
Implements random sampling without replacement.
Adapted from algorithm L described in "Random sampling with a reservoir, J. S. Vitter, 1985".
"""
struct AlgL <: ReservoirAlgorithm end
"""
Implements random sampling with replacement.
Adapted fron algorithm RSWR_SKIP described in "Reservoir-based Random Sampling with Replacement from
Data Stream, B. Park et al., 2008".
"""
struct AlgRSWRSKIP <: ReservoirAlgorithm end
"""
Implements weighted random sampling without replacement.
Adapted from algorithm A-Res described in "Weighted random sampling with a reservoir,
P. S. Efraimidis et al., 2006".
"""
struct AlgARes <: ReservoirAlgorithm end
"""
Implements weighted random sampling without replacement.
Adapted from algorithm A-ExpJ described in "Weighted random sampling with a reservoir,
P. S. Efraimidis et al., 2006".
"""
struct AlgAExpJ <: ReservoirAlgorithm end
"""
Implements weighted random sampling with replacement.
Adapted from algorithm WRSWR_SKIP described in "A Skip-based Algorithm for Weighted Reservoir
Sampling with Replacement, A. Meligrana, 2024".
"""
struct AlgWRSWRSKIP <: ReservoirAlgorithm end
include("SamplingUtils.jl")
include("SamplingInterface.jl")
include("SortedSamplingSingle.jl")
include("SortedSamplingMulti.jl")
include("UnweightedSamplingSingle.jl")
include("UnweightedSamplingMulti.jl")
include("WeightedSamplingSingle.jl")
include("WeightedSamplingMulti.jl")
include("SamplingReduction.jl")
include("precompile.jl")
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 8119 |
@hybrid struct SampleMultiAlgR{O,T,R} <: AbstractReservoirSample
seen_k::Int
const rng::R
const value::Vector{T}
const ord::O
end
const SampleMultiOrdAlgR = SampleMultiAlgR{<:Vector}
@hybrid struct SampleMultiAlgL{O,T,R} <: AbstractReservoirSample
state::Float64
skip_k::Int
seen_k::Int
const rng::R
const value::Vector{T}
const ord::O
end
const SampleMultiOrdAlgL = SampleMultiAlgL{<:Vector}
@hybrid struct SampleMultiAlgRSWRSKIP{O,T,R} <: AbstractReservoirSample
skip_k::Int
seen_k::Int
const rng::R
const value::Vector{T}
const ord::O
end
const SampleMultiOrdAlgRSWRSKIP = SampleMultiAlgRSWRSKIP{<:Vector}
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgL, ::MutSample, ::Ord)
return SampleMultiAlgL_Mut(0.0, 0, 0, rng, Vector{T}(undef, n), collect(1:n))
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgL, ::MutSample, ::Unord)
return SampleMultiAlgL_Mut(0.0, 0, 0, rng, Vector{T}(undef, n), nothing)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgL, ::ImmutSample, ::Ord)
return SampleMultiAlgL_Immut(0.0, 0, 0, rng, Vector{T}(undef, n), collect(1:n))
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgL, ::ImmutSample, ::Unord)
return SampleMultiAlgL_Immut(0.0, 0, 0, rng, Vector{T}(undef, n), nothing)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgR, ::MutSample, ::Ord)
return SampleMultiAlgR_Mut(0, rng, Vector{T}(undef, n), collect(1:n))
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgR, ::MutSample, ::Unord)
return SampleMultiAlgR_Mut(0, rng, Vector{T}(undef, n), nothing)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgR, ::ImmutSample, ::Ord)
return SampleMultiAlgR_Immut(0, rng, Vector{T}(undef, n), collect(1:n))
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgR, ::ImmutSample, ::Unord)
return SampleMultiAlgR_Immut(0, rng, Vector{T}(undef, n), nothing)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgRSWRSKIP, ::MutSample, ::Ord)
return SampleMultiAlgRSWRSKIP_Mut(0, 0, rng, Vector{T}(undef, n), collect(1:n))
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgRSWRSKIP, ::MutSample, ::Unord)
return SampleMultiAlgRSWRSKIP_Mut(0, 0, rng, Vector{T}(undef, n), nothing)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgRSWRSKIP, ::ImmutSample, ::Ord)
return SampleMultiAlgRSWRSKIP_Immut(0, 0, rng, Vector{T}(undef, n), collect(1:n))
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgRSWRSKIP, ::ImmutSample, ::Unord)
return SampleMultiAlgRSWRSKIP_Immut(0, 0, rng, Vector{T}(undef, n), nothing)
end
@inline function OnlineStatsBase._fit!(s::SampleMultiAlgR, el)
n = length(s.value)
s = @inline update_state!(s)
if s.seen_k <= n
@inbounds s.value[s.seen_k] = el
else
j = rand(s.rng, 1:s.seen_k)
if j <= n
@inbounds s.value[j] = el
update_order!(s, j)
end
end
return s
end
@inline function OnlineStatsBase._fit!(s::SampleMultiAlgL, el)
n = length(s.value)
s = @inline update_state!(s)
if s.seen_k <= n
@inbounds s.value[s.seen_k] = el
if s.seen_k === n
s = @inline recompute_skip!(s, n)
end
elseif s.skip_k < s.seen_k
j = rand(s.rng, 1:n)
@inbounds s.value[j] = el
update_order!(s, j)
s = @inline recompute_skip!(s, n)
end
return s
end
@inline function OnlineStatsBase._fit!(s::SampleMultiAlgRSWRSKIP, el)
n = length(s.value)
s = @inline update_state!(s)
if s.seen_k <= n
@inbounds s.value[s.seen_k] = el
if s.seen_k === n
s = recompute_skip!(s, n)
new_values = sample(s.rng, s.value, n, ordered=is_ordered(s))
@inbounds for i in 1:n
s.value[i] = new_values[i]
end
end
elseif s.skip_k < s.seen_k
p = 1/s.seen_k
z = (1-p)^(n-3)
q = rand(s.rng, Uniform(z*(1-p)*(1-p)*(1-p),1.0))
k = choose(n, p, q, z)
@inbounds begin
if k == 1
r = rand(s.rng, 1:n)
s.value[r] = el
update_order_single!(s, r)
else
for j in 1:k
r = rand(s.rng, j:n)
s.value[r] = el
s.value[r], s.value[j] = s.value[j], s.value[r]
update_order_multi!(s, r, j)
end
end
end
s = recompute_skip!(s, n)
end
return s
end
function Base.empty!(s::SampleMultiAlgR_Mut)
s.seen_k = 0
return s
end
function Base.empty!(s::SampleMultiAlgL_Mut)
s.state = 0.0
s.skip_k = 0
s.seen_k = 0
return s
end
function Base.empty!(s::SampleMultiAlgRSWRSKIP_Mut)
s.skip_k = 0
s.seen_k = 0
return s
end
function update_state!(s::SampleMultiAlgR)
@update s.seen_k += 1
return s
end
function update_state!(s::SampleMultiAlgL)
@update s.seen_k += 1
return s
end
function update_state!(s::SampleMultiAlgRSWRSKIP)
@update s.seen_k += 1
return s
end
function recompute_skip!(s::SampleMultiAlgL, n)
@update s.state += randexp(s.rng)
@update s.skip_k = s.seen_k-ceil(Int, randexp(s.rng)/log(1-exp(-s.state/n)))
return s
end
function recompute_skip!(s::SampleMultiAlgRSWRSKIP, n)
q = rand(s.rng)^(1/n)
@update s.skip_k = ceil(Int, s.seen_k/q)-1
return s
end
function choose(n, p, q, z)
m = 1-p
s = z
z = s*m*m*(m + n*p)
z > q && return 1
z += n*p*(n-1)*p*s*m/2
z > q && return 2
z += n*p*(n-1)*p*(n-2)*p*s/6
z > q && return 3
b = Binomial(n, p)
return quantile(b, q)
end
update_order!(s::Union{SampleMultiAlgR, SampleMultiAlgL}, j) = nothing
function update_order!(s::Union{SampleMultiOrdAlgR, SampleMultiOrdAlgL}, j)
s.ord[j] = nobs(s)
end
update_order_single!(s::SampleMultiAlgRSWRSKIP, r) = nothing
function update_order_single!(s::SampleMultiOrdAlgRSWRSKIP, r)
s.ord[r] = nobs(s)
end
update_order_multi!(s::SampleMultiAlgRSWRSKIP, r, j) = nothing
function update_order_multi!(s::SampleMultiOrdAlgRSWRSKIP, r, j)
s.ord[r], s.ord[j] = s.ord[j], nobs(s)
end
is_ordered(s::SampleMultiOrdAlgRSWRSKIP) = true
is_ordered(s::SampleMultiAlgRSWRSKIP) = false
function Base.merge(ss::SampleMultiAlgRSWRSKIP...)
newvalue = reduce_samples(TypeUnion(), ss...)
skip_k = sum(getfield(s, :skip_k) for s in ss)
seen_k = sum(getfield(s, :seen_k) for s in ss)
return SampleMultiAlgRSWRSKIP_Mut(skip_k, seen_k, ss[1].rng, newvalue, nothing)
end
function Base.merge!(s1::SampleMultiAlgRSWRSKIP{<:Nothing}, ss::SampleMultiAlgRSWRSKIP...)
newvalue = reduce_samples(TypeS(), s1, ss...)
for i in 1:length(newvalue)
@inbounds s1.value[i] = newvalue[i]
end
s1.skip_k += sum(getfield(s, :skip_k) for s in ss)
s1.seen_k += sum(getfield(s, :seen_k) for s in ss)
return s1
end
function OnlineStatsBase.value(s::Union{SampleMultiAlgR, SampleMultiAlgL})
if nobs(s) < length(s.value)
return s.value[1:nobs(s)]
else
return s.value
end
end
function OnlineStatsBase.value(s::SampleMultiAlgRSWRSKIP)
if nobs(s) < length(s.value)
return sample(s.rng, s.value[1:nobs(s)], length(s.value))
else
return s.value
end
end
function ordvalue(s::Union{SampleMultiOrdAlgR, SampleMultiOrdAlgL})
if nobs(s) < length(s.value)
return s.value[1:nobs(s)]
else
return s.value[sortperm(s.ord)]
end
end
function ordvalue(s::SampleMultiOrdAlgRSWRSKIP)
if nobs(s) < length(s.value)
return sample(s.rng, s.value[1:nobs(s)], length(s.value); ordered=true)
else
return s.value[sortperm(s.ord)]
end
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 1728 |
@hybrid struct SampleSingleAlgRSWRSKIP{RT,R} <: AbstractReservoirSample
seen_k::Int
skip_k::Int
const rng::R
rvalue::RT
end
function ReservoirSample(rng::AbstractRNG, T, ::AlgRSWRSKIP, ::MutSample)
return SampleSingleAlgRSWRSKIP_Mut(0, 0, rng, RefVal_Immut{T}())
end
function ReservoirSample(rng::AbstractRNG, T, ::AlgRSWRSKIP, ::ImmutSample)
return SampleSingleAlgRSWRSKIP_Immut(0, 0, rng, RefVal_Mut{T}())
end
function OnlineStatsBase.value(s::SampleSingleAlgRSWRSKIP)
s.seen_k === 0 && return nothing
return s.rvalue.value
end
@inline function OnlineStatsBase._fit!(s::SampleSingleAlgRSWRSKIP, el)
@update s.seen_k += 1
if s.skip_k <= s.seen_k
@update s.skip_k = ceil(Int, s.seen_k/rand(s.rng))
reset_value!(s, el)
end
return s
end
function reset_value!(s::SampleSingleAlgRSWRSKIP_Mut, el)
s.rvalue = RefVal_Immut(el)
end
function reset_value!(s::SampleSingleAlgRSWRSKIP_Immut, el)
s.rvalue.value = el
end
function Base.empty!(s::SampleSingleAlgRSWRSKIP)
s.seen_k = 0
s.skip_k = 0
return s
end
function Base.merge(s1::SampleSingleAlgRSWRSKIP, s2::SampleSingleAlgRSWRSKIP)
n1, n2 = nobs(s1), nobs(s2)
n_tot = n1 + n2
value = rand(s1.rng) < n1/n_tot ? s1.rvalue : s2.rvalue
return typeof(s1)(n_tot, s1.skip_k + s2.skip_k, s1.rng, value)
end
function Base.merge!(s1::SampleSingleAlgRSWRSKIP_Mut, s2::SampleSingleAlgRSWRSKIP_Mut)
n1, n2 = nobs(s1), nobs(s2)
n_tot = n1 + n2
r = rand(s1.rng)
p = n2 / n_tot
if r < p
s1.rvalue = RefVal_Immut(s2.rvalue.value)
end
s1.seen_k = n_tot
s1.skip_k += s2.skip_k
return s1
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 9916 |
const OrdWeighted = BinaryHeap{Tuple{T, Int64, Float64}, Base.Order.By{typeof(last), DataStructures.FasterForward}} where T
@hybrid struct SampleMultiAlgARes{BH,R} <: AbstractReservoirSample
seen_k::Int
n::Int
const rng::R
const value::BH
end
const SampleMultiOrdAlgARes = Union{SampleMultiAlgARes_Immut{<:OrdWeighted}, SampleMultiAlgARes_Mut{<:OrdWeighted}}
@hybrid struct SampleMultiAlgAExpJ{BH,R} <: AbstractReservoirSample
state::Float64
min_priority::Float64
seen_k::Int
const n::Int
const rng::R
const value::BH
end
const SampleMultiOrdAlgAExpJ = Union{SampleMultiAlgAExpJ_Immut{<:OrdWeighted}, SampleMultiAlgAExpJ_Mut{<:OrdWeighted}}
@hybrid struct SampleMultiAlgWRSWRSKIP{O,T,R} <: AbstractReservoirSample
state::Float64
skip_w::Float64
seen_k::Int
const rng::R
const weights::Vector{Float64}
const value::Vector{T}
const ord::O
end
const SampleMultiOrdAlgWRSWRSKIP = Union{SampleMultiAlgWRSWRSKIP_Immut{<:Vector}, SampleMultiAlgWRSWRSKIP_Mut{<:Vector}}
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgAExpJ, ::MutSample, ::Ord)
value = BinaryHeap(Base.By(last, DataStructures.FasterForward()), Tuple{T, Int, Float64}[])
sizehint!(value, n)
return SampleMultiAlgAExpJ_Mut(0.0, 0.0, 0, n, rng, value)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgAExpJ, ::MutSample, ::Unord)
value = BinaryHeap(Base.By(last, DataStructures.FasterForward()), Pair{T, Float64}[])
sizehint!(value, n)
return SampleMultiAlgAExpJ_Mut(0.0, 0.0, 0, n, rng, value)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgAExpJ, ::ImmutSample, ::Ord)
value = BinaryHeap(Base.By(last, DataStructures.FasterForward()), Tuple{T, Int, Float64}[])
sizehint!(value, n)
return SampleMultiAlgAExpJ_Immut(0.0, 0.0, 0, n, rng, value)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgAExpJ, ::ImmutSample, ::Unord)
value = BinaryHeap(Base.By(last, DataStructures.FasterForward()), Pair{T, Float64}[])
sizehint!(value, n)
return SampleMultiAlgAExpJ_Immut(0.0, 0.0, 0, n, rng, value)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgARes, ::MutSample, ::Ord)
value = BinaryHeap(Base.By(last, DataStructures.FasterForward()), Tuple{T, Int, Float64}[])
sizehint!(value, n)
return SampleMultiAlgARes_Mut(0, n, rng, value)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgARes, ::MutSample, ::Unord)
value = BinaryHeap(Base.By(last, DataStructures.FasterForward()), Pair{T, Float64}[])
sizehint!(value, n)
return SampleMultiAlgARes_Mut(0, n, rng, value)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgARes, ::ImmutSample, ::Ord)
value = BinaryHeap(Base.By(last, DataStructures.FasterForward()), Tuple{T, Int, Float64}[])
sizehint!(value, n)
return SampleMultiAlgARes_Immut(0, n, rng, value)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgARes, ::ImmutSample, ::Unord)
value = BinaryHeap(Base.By(last, DataStructures.FasterForward()), Pair{T, Float64}[])
sizehint!(value, n)
return SampleMultiAlgARes_Immut(0, n, rng, value)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgWRSWRSKIP, ::MutSample, ::Ord)
ord = collect(1:n)
return SampleMultiAlgWRSWRSKIP_Mut(0.0, 0.0, 0, rng, Vector{Float64}(undef, n), Vector{T}(undef, n), ord)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgWRSWRSKIP, ::MutSample, ::Unord)
return SampleMultiAlgWRSWRSKIP_Mut(0.0, 0.0, 0, rng, Vector{Float64}(undef, n), Vector{T}(undef, n), nothing)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgWRSWRSKIP, ::ImmutSample, ::Ord)
ord = collect(1:n)
return SampleMultiAlgWRSWRSKIP_Immut(0.0, 0.0, 0, rng, Vector{Float64}(undef, n), Vector{T}(undef, n), ord)
end
function ReservoirSample(rng::AbstractRNG, T, n::Integer, ::AlgWRSWRSKIP, ::ImmutSample, ::Unord)
return SampleMultiAlgWRSWRSKIP_Immut(0.0, 0.0, 0, rng, Vector{Float64}(undef, n), Vector{T}(undef, n), nothing)
end
@inline function OnlineStatsBase._fit!(s::Union{SampleMultiAlgARes, SampleMultiOrdAlgARes}, el, w)
n = s.n
s = @inline update_state!(s, w)
priority = -randexp(s.rng)/w
if s.seen_k <= n
push_value!(s, el, priority)
else
min_priority = last(first(s.value))
if priority > min_priority
pop!(s.value)
push_value!(s, el, priority)
end
end
return s
end
@inline function OnlineStatsBase._fit!(s::SampleMultiAlgAExpJ, el, w)
n = s.n
s = @inline update_state!(s, w)
if s.seen_k <= n
priority = exp(-randexp(s.rng)/w)
push_value!(s, el, priority)
if s.seen_k == n
s = @inline recompute_skip!(s)
end
elseif s.state <= 0.0
priority = @inline compute_skip_priority(s, w)
pop!(s.value)
push_value!(s, el, priority)
s = @inline recompute_skip!(s)
end
return s
end
@inline function OnlineStatsBase._fit!(s::SampleMultiAlgWRSWRSKIP, el, w)
n = length(s.value)
s = @inline update_state!(s, w)
if s.seen_k <= n
@inbounds s.value[s.seen_k] = el
@inbounds s.weights[s.seen_k] = w
if s.seen_k == n
new_values = sample(s.rng, s.value, weights(s.weights), n; ordered = is_ordered(s))
@inbounds for i in 1:n
s.value[i] = new_values[i]
end
s = @inline recompute_skip!(s, n)
empty!(s.weights)
end
elseif s.skip_w <= s.state
p = w/s.state
z = (1-p)^(n-3)
q = rand(s.rng, Uniform(z*(1-p)*(1-p)*(1-p),1.0))
k = choose(n, p, q, z)
@inbounds begin
if k == 1
r = rand(s.rng, 1:n)
s.value[r] = el
update_order_single!(s, r)
else
for j in 1:k
r = rand(s.rng, j:n)
s.value[r] = el
s.value[r], s.value[j] = s.value[j], s.value[r]
update_order_multi!(s, r, j)
end
end
end
s = @inline recompute_skip!(s, n)
end
return s
end
function Base.empty!(s::SampleMultiAlgARes_Mut)
s.seen_k = 0
empty!(s.value)
sizehint!(s.value, s.n)
return s
end
function Base.empty!(s::SampleMultiAlgAExpJ_Mut)
s.state = 0.0
s.min_priority = 0.0
s.seen_k = 0
empty!(s.value)
sizehint!(s.value, s.n)
return s
end
function Base.empty!(s::SampleMultiAlgWRSWRSKIP_Mut)
s.state = 0.0
s.skip_w = 0.0
s.seen_k = 0
return s
end
function Base.merge(ss::SampleMultiAlgWRSWRSKIP...)
newvalue = reduce_samples(TypeUnion(), ss...)
skip_w = sum(getfield(s, :skip_w) for s in ss)
state = sum(getfield(s, :state) for s in ss)
seen_k = sum(getfield(s, :seen_k) for s in ss)
s = SampleMultiAlgWRSWRSKIP_Mut(state, skip_w, seen_k, ss[1].rng, Float64[], newvalue, nothing)
return s
end
function Base.merge!(s1::SampleMultiAlgWRSWRSKIP{<:Nothing}, ss::SampleMultiAlgWRSWRSKIP...)
newvalue = reduce_samples(TypeS(), s1, ss...)
for i in 1:length(newvalue)
@inbounds s1.value[i] = newvalue[i]
end
s1.skip_w += sum(getfield(s, :skip_w) for s in ss)
s1.state += sum(getfield(s, :state) for s in ss)
s1.seen_k += sum(getfield(s, :seen_k) for s in ss)
empty!(s1.weights)
return s1
end
function update_state!(s::SampleMultiAlgARes, w)
@update s.seen_k += 1
return s
end
function update_state!(s::SampleMultiAlgAExpJ, w)
@update s.seen_k += 1
@update s.state -= w
return s
end
function update_state!(s::SampleMultiAlgWRSWRSKIP, w)
@update s.seen_k += 1
@update s.state += w
return s
end
function compute_skip_priority(s, w)
t = exp(log(s.min_priority)*w)
return exp(log(rand(s.rng, Uniform(t,1)))/w)
end
function recompute_skip!(s::SampleMultiAlgAExpJ)
@update s.min_priority = last(first(s.value))
@update s.state = -randexp(s.rng)/log(s.min_priority)
return s
end
function recompute_skip!(s::SampleMultiAlgWRSWRSKIP, n)
q = rand(s.rng)^(1/n)
@update s.skip_w = s.state/q
return s
end
function push_value!(s::Union{SampleMultiAlgARes, SampleMultiAlgAExpJ}, el, priority)
push!(s.value, el => priority)
end
function push_value!(s::Union{SampleMultiOrdAlgARes, SampleMultiOrdAlgAExpJ}, el, priority)
push!(s.value, (el, s.seen_k, priority))
end
update_order_single!(s::SampleMultiAlgWRSWRSKIP, r) = nothing
function update_order_single!(s::SampleMultiOrdAlgWRSWRSKIP, r)
s.ord[r] = nobs(s)
end
update_order_multi!(s::SampleMultiAlgWRSWRSKIP, r, j) = nothing
function update_order_multi!(s::SampleMultiOrdAlgWRSWRSKIP, r, j)
s.ord[r], s.ord[j] = s.ord[j], nobs(s)
end
is_ordered(s::SampleMultiOrdAlgWRSWRSKIP) = true
is_ordered(s::SampleMultiAlgWRSWRSKIP) = false
function OnlineStatsBase.value(s::Union{SampleMultiAlgARes, SampleMultiAlgAExpJ})
if nobs(s) < s.n
return first.(s.value.valtree[1:nobs(s)])
else
return first.(s.value.valtree)
end
end
function OnlineStatsBase.value(s::SampleMultiAlgWRSWRSKIP)
if nobs(s) < length(s.value)
return sample(s.rng, s.value[1:nobs(s)], weights(s.weights[1:nobs(s)]), length(s.value))
else
return s.value
end
end
function ordvalue(s::Union{SampleMultiOrdAlgARes, SampleMultiOrdAlgAExpJ})
if nobs(s) < length(s.value)
vals = s.value.valtree[1:nobs(s)]
else
vals = s.value.valtree
end
return first.(vals[sortperm(map(x -> x[2], vals))])
end
function ordvalue(s::SampleMultiOrdAlgWRSWRSKIP)
if nobs(s) < length(s.value)
return sample(s.rng, s.value[1:nobs(s)], weights(s.weights[1:nobs(s)]), length(s.value); ordered=true)
else
return s.value[sortperm(s.ord)]
end
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 1264 |
@hybrid struct SampleSingleAlgWRSWRSKIP{RT,R} <: AbstractReservoirSample
seen_k::Int
total_w::Float64
skip_w::Float64
const rng::R
rvalue::RT
end
function ReservoirSample(rng::R, T, ::AlgWRSWRSKIP, ::MutSample) where {R<:AbstractRNG}
return SampleSingleAlgWRSWRSKIP_Mut(0, 0.0, 0.0, rng, RefVal_Immut{T}())
end
function ReservoirSample(rng::R, T, ::AlgWRSWRSKIP, ::ImmutSample) where {R<:AbstractRNG}
return SampleSingleAlgWRSWRSKIP_Immut(0, 0.0, 0.0, rng, RefVal_Mut{T}())
end
function OnlineStatsBase.value(s::SampleSingleAlgWRSWRSKIP)
s.seen_k === 0 && return nothing
return get_value(s)
end
@inline function OnlineStatsBase._fit!(s::SampleSingleAlgWRSWRSKIP, el, w)
@update s.seen_k += 1
@update s.total_w += w
if s.skip_w <= s.total_w
@update s.skip_w = s.total_w/rand(s.rng)
reset_value!(s, el)
end
return s
end
function Base.empty!(s::SampleSingleAlgWRSWRSKIP_Mut)
s.seen_k = 0
s.total_w = 0.0
s.skip_w = 0.0
return s
end
get_value(s::SampleSingleAlgWRSWRSKIP) = s.rvalue.value
function reset_value!(s::SampleSingleAlgWRSWRSKIP_Mut, el)
s.rvalue = RefVal_Immut(el)
end
function reset_value!(s::SampleSingleAlgWRSWRSKIP_Immut, el)
s.rvalue.value = el
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 902 |
using PrecompileTools
@setup_workload let
iter = Iterators.filter(x -> x != 10, 1:20);
wv(el) = 1.0
update_s!(rs, iter) = for x in iter fit!(rs, x) end
update_s!(rs, iter, wv) = for x in iter fit!(rs, x, wv(x)) end
@compile_workload let
rs = ReservoirSample(Int, AlgRSWRSKIP())
update_s!(rs, iter)
rs = ReservoirSample(Int, AlgWRSWRSKIP())
update_s!(rs, iter, wv)
rs = ReservoirSample(Int, 2, AlgR())
update_s!(rs, iter)
rs = ReservoirSample(Int, 2, AlgL())
update_s!(rs, iter)
rs = ReservoirSample(Int, 2, AlgRSWRSKIP())
update_s!(rs, iter)
rs = ReservoirSample(Int, 2, AlgARes())
update_s!(rs, iter, wv)
rs = ReservoirSample(Int, 2, AlgAExpJ())
update_s!(rs, iter, wv)
rs = ReservoirSample(Int, 2, AlgWRSWRSKIP())
update_s!(rs, iter, wv)
end
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 1317 | @testset "benchmarks" begin
rng = Xoshiro(42)
iter_no_f = (x for x in 1:10^2)
iter = Iterators.filter(x -> x != 10, 1:10^2)
wv(el) = 1.0
for m in (:(AlgS()), AlgR(), AlgL(), AlgRSWRSKIP())
for size in (nothing, 10)
size == nothing && m === AlgL() && continue
size == nothing && m === AlgR() && continue
s = size == nothing ? () : (size,)
b = @benchmark itsample($rng, $(m == :(AlgS()) ? iter_no_f : iter), $s..., $m) evals=1
mstr = "$m $(size == nothing ? :single : :multi)"
print(mstr * repeat(" ", 35-length(mstr)))
print(" --> Time: $(median(b.times)) ns |")
println(" Memory: $(b.memory) bytes")
end
end
for m in (AlgARes(), AlgAExpJ(), AlgWRSWRSKIP())
for size in (nothing, 10)
size == nothing && m === AlgARes() && continue
size == nothing && m === AlgAExpJ() && continue
s = size == nothing ? () : (size,)
b = @benchmark itsample($rng, $iter, $wv, $s..., $m) evals=1
mstr = "$m $(size == nothing ? :single : :multi)"
print(mstr * repeat(" ", 35-length(mstr)))
print(" --> Time: $(median(b.times)) ns |")
println(" Memory: $(b.memory) bytes")
end
end
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 1303 |
@testset "merge tests" begin
rng = StableRNG(43)
iters = (1:2, 3:10)
reps = 10^5
size = 2
for (m1, m2) in [(AlgRSWRSKIP(), AlgRSWRSKIP())]
res = zeros(Int, 10, 10)
for _ in 1:reps
s1 = ReservoirSample(rng, Int, size, m1)
s2 = ReservoirSample(rng, Int, size, m2)
s_all = (s1, s2)
for (s, it) in zip(s_all, iters)
for x in it
fit!(s, x)
end
end
s_merged = merge(s1, s2)
res[shuffle!(rng, value(s_merged))...] += 1
end
cases = m1 == AlgRSWRSKIP() ? 10^size : factorial(10)/factorial(10-size)
ps_exact = [1/cases for _ in 1:cases]
count_est = vec(res)
chisq_test = ChisqTest(count_est, ps_exact)
@test pvalue(chisq_test) > 0.05
end
s1 = ReservoirSample(rng, Int, 2, AlgRSWRSKIP())
s2 = ReservoirSample(rng, Int, 2, AlgRSWRSKIP())
s_all = (s1, s2)
for (s, it) in zip(s_all, iters)
for x in it
fit!(s, x)
end
end
@test length(value(merge!(s1, s2))) == 2
s1 = ReservoirSample(rng, Int, AlgRSWRSKIP())
s2 = ReservoirSample(rng, Int, AlgRSWRSKIP())
fit!(s1, 1)
fit!(s2, 2)
@test value(merge!(s1, s2)) in (1, 2)
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 102 |
using Aqua
@testset "Code quality" begin
Aqua.test_all(StreamSampling, ambiguities = false)
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 505 |
using BenchmarkTools
using Distributions
using HypothesisTests
using Printf
using Random
using StableRNGs
using Test
using StreamSampling
@testset "StreamSampling.jl Tests" begin
include("package_sanity_tests.jl")
include("unweighted_sampling_single_tests.jl")
include("unweighted_sampling_multi_tests.jl")
include("weighted_sampling_single_tests.jl")
include("weighted_sampling_multi_tests.jl")
include("merge_tests.jl")
include("benchmark_tests.jl")
end | StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 2966 |
@testset "Unweighted sampling multi tests" begin
combs = Iterators.product([(AlgL(), AlgR(), AlgRSWRSKIP()), (false, true)]...)
@testset "method=$method ordered=$ordered" for (method, ordered) in combs
a, b = 1, 10
# test return values of iter with known lengths are inrange
iter = a:b
s = itsample(iter, 2, method; ordered=ordered)
@test length(s) == 2
@test all(x -> a <= x <= b, s)
s = itsample(iter, 10^7, method; ordered=ordered)
@test method == AlgRSWRSKIP() ? length(s) == 10^7 : length(s) == 10
@test length(unique(s)) == 10
@test all(x -> a <= x <= b, s)
@test typeof(s) == Vector{Int}
s = itsample(iter, 2, method; ordered=ordered)
@test length(s) == 2
@test all(x -> a <= x <= b, s)
@test typeof(s) == Vector{Int}
s = itsample(iter, 100, method; ordered=ordered)
@test method == AlgRSWRSKIP() ? length(s) == 100 : length(s) == 10
@test length(unique(s)) == 10
# test return values of iter with unknown lengths are inrange
iter = Iterators.filter(x -> x < 5, a:b)
s = itsample(iter, 2, method; ordered=ordered)
@test length(s) == 2
@test all(x -> a <= x <= b, s)
@test typeof(s) == Vector{Int}
s = itsample(iter, 2, method; ordered=ordered)
@test length(s) == 2
@test all(x -> a <= x <= b, s)
@test typeof(s) == Vector{Int}
s = itsample(iter, 100, method; ordered=ordered)
@test method == AlgRSWRSKIP() ? length(s) == 100 : length(s) == 4
@test length(unique(s)) == 4
@test ordered ? issorted(s) : true
iter = Iterators.filter(x -> x != b + 1, a:b+1)
rs = ReservoirSample(Int, 5, method; ordered = ordered)
for x in iter
fit!(rs, x)
end
@test length(value(rs)) == 5
@test all(x -> a <= x <= b, value(rs))
@test nobs(rs) == 10
rng = StableRNG(42)
iters = (a:b, Iterators.filter(x -> x != b + 1, a:b+1))
sizes = (2, 3)
for it in iters
for size in sizes
reps = 10^(size+2)
dict_res = Dict{Vector, Int}()
for _ in 1:reps
s = shuffle!(rng, itsample(rng, it, size, method; ordered=ordered))
if s in keys(dict_res)
dict_res[s] += 1
else
dict_res[s] = 1
end
end
cases = method == AlgRSWRSKIP() ? 10^size : factorial(10)/factorial(10-size)
ps_exact = [1/cases for _ in 1:cases]
count_est = collect(values(dict_res))
chisq_test = ChisqTest(count_est, ps_exact)
@test pvalue(chisq_test) > 0.05
end
end
end
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 1223 |
@testset "Unweighted sampling single tests" begin
@testset "method=$method" for method in (AlgRSWRSKIP(),)
a, b = 1, 100
z = itsample(a:b, method)
@test a <= z <= b
z = itsample(Iterators.filter(x -> x != b+1, a:b+1), method)
@test a <= z <= b
iter = Iterators.filter(x -> x != b + 1, a:b+1)
rs = ReservoirSample(Int, method)
for x in iter
fit!(rs, x)
end
@test a <= value(rs) <= b
@test nobs(rs) == 100
rng = StableRNG(43)
iters = (a:b, Iterators.filter(x -> x != b + 1, a:b+1))
for it in iters
reps = 10000
dict_res = Dict{Int, Int}()
for _ in 1:reps
s = itsample(rng, it, method)
if s in keys(dict_res)
dict_res[s] += 1
else
dict_res[s] = 1
end
end
cases = 100
ps_exact = [1/cases for _ in 1:cases]
count_est = collect(values(dict_res))
chisq_test = ChisqTest(count_est, ps_exact)
@test pvalue(chisq_test) > 0.05
end
end
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
|
[
"MIT"
] | 0.5.1 | 4a51ecb0d0bb2bb7ccf06891437c7bf928f7d356 | code | 3668 |
function prob_replace(k)
num = 1
for x in k
v = x <= 5 ? 1 : 2
num *= v
end
return num/15^length(k)
end
function prob_no_replace(k)
num = 1
den = 1
m = 0
for x in k
v = x <= 5 ? 1 : 2
num *= v
den *= (15 - m)
m += v
end
if num == 2 && (den == 15*14 || den == 15*13)
num = 9
den = 910
end
return num/den
end
@testset "Weighted sampling multi tests" begin
combs = Iterators.product([(AlgAExpJ(), AlgARes(), AlgWRSWRSKIP()), (false, true)]...)
@testset "method=$method ordered=$ordered" for (method, ordered) in combs
a, b = 1, 10
# test return values of iter with known lengths are inrange
weight(el) = 1.0
iter = a:b
s = itsample(iter, weight, 2, method; ordered=ordered)
@test length(s) == 2
@test all(x -> a <= x <= b, s)
s = itsample(iter, weight, 10^7, method; ordered=ordered)
@test method == AlgWRSWRSKIP() ? length(s) == 10^7 : length(s) == 10
@test length(unique(s)) == 10
@test all(x -> a <= x <= b, s)
@test typeof(s) == Vector{Int}
s = itsample(iter, weight, 2, method; ordered=ordered)
@test length(s) == 2
@test all(x -> a <= x <= b, s)
@test typeof(s) == Vector{Int}
s = itsample(iter, weight, 100, method; ordered=ordered)
@test method == AlgWRSWRSKIP() ? length(s) == 100 : length(s) == 10
@test length(unique(s)) == 10
# test return values of iter with unknown lengths are inrange
iter = Iterators.filter(x -> x < 5, a:b)
s = itsample(iter, weight, 2, method; ordered=ordered)
@test length(s) == 2
@test all(x -> a <= x <= b, s)
@test typeof(s) == Vector{Int}
s = itsample(iter, weight, 2, method; ordered=ordered)
@test length(s) == 2
@test all(x -> a <= x <= b, s)
@test typeof(s) == Vector{Int}
s = itsample(iter, weight, 100, method; ordered=ordered)
@test method == AlgWRSWRSKIP() ? length(s) == 100 : length(s) == 4
@test length(unique(s)) == 4
@test ordered ? issorted(s) : true
iter = Iterators.filter(x -> x != b + 1, a:b+1)
rs = ReservoirSample(Int, 5, method; ordered = ordered)
for x in iter
fit!(rs, x, weight(x))
end
@test length(value(rs)) == 5
@test all(x -> a <= x <= b, value(rs))
@test nobs(rs) == 10
weight2(el) = el <= 5 ? 1.0 : 2.0
rng = StableRNG(41)
iters = (a:b, Iterators.filter(x -> x != b+1, a:b+1))
sizes = (1, 2)
for it in iters
for size in sizes
reps = 10^(size+3)
dict_res = Dict{Vector, Int}()
for _ in 1:reps
s = shuffle!(rng, itsample(rng, it, weight2, size, method; ordered=ordered))
if s in keys(dict_res)
dict_res[s] += 1
else
dict_res[s] = 1
end
end
cases = method == AlgWRSWRSKIP() ? 10^size : factorial(10)/factorial(10-size)
pairs_dict = collect(pairs(dict_res))
if method == AlgWRSWRSKIP()
ps_exact = [prob_replace(k) for (k, v) in pairs_dict]
else
ps_exact = [prob_no_replace(k) for (k, v) in pairs_dict if length(unique(k)) == size]
end
count_est = [v for (k, v) in pairs_dict]
chisq_test = ChisqTest(count_est, ps_exact)
@test pvalue(chisq_test) > 0.05
end
end
end
end
| StreamSampling | https://github.com/JuliaDynamics/StreamSampling.jl.git |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.