Skip to content

Commit

Permalink
Rename to meet package naming guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
BenChung committed Dec 7, 2021
1 parent 4fdd0fd commit 305096e
Show file tree
Hide file tree
Showing 9 changed files with 2,898 additions and 2,906 deletions.
7 changes: 5 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "kRPC"
uuid = "1c1c9389-3631-468f-a056-497e06f4ffdb"
name = "KRPC"
uuid = "7a052949-c101-4ca3-9a7e-43a2532b2fa8"
authors = ["Ben Chung <[email protected]> and contributors"]
version = "0.3.0"

Expand All @@ -11,6 +11,9 @@ Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"

[compat]
julia = "1.6"
LightXML = "^0.9"
MacroTools = "^0.5"
ProtoBuf = "^0.11"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# kRPC
# KRPC

A Julia wrapper library for the [KRPC remote procedure call system for Kerbal Space Program](https://krpc.github.io/krpc/index.html).

# Example

## Setup:
```julia
using kRPC
using kRPC.Interface.SpaceCenter.Helpers
using KRPC
using KRPC.Interface.SpaceCenter.Helpers

kRPC.kerbal_connect("test", "127.0.0.1") do
KRPC.kerbal_connect("test", "127.0.0.1") do
# use the connection
end
```

## Get the vessel's current position:
```julia
spaceCenter = kRPC.Interface.SpaceCenter.RemoteTypes.SpaceCenter(conn)
spaceCenter = KRPC.Interface.SpaceCenter.RemoteTypes.SpaceCenter(conn)
vessel = ActiveVessel(spaceCenter)
body_rf = ReferenceFrame(Body(Orbit(vessel)))
println(Position(vessel, body_rf))
```

## Stream the vessel's current position:
```julia
spaceCenter = kRPC.Interface.SpaceCenter.RemoteTypes.SpaceCenter(conn)
spaceCenter = KRPC.Interface.SpaceCenter.RemoteTypes.SpaceCenter(conn)
vessel = ActiveVessel(spaceCenter)
body_rf = ReferenceFrame(Body(Orbit(vessel)))
add_stream(conn, (kRPC.Interface.SpaceCenter.Vessel_Position(vessel, body_rf), )) do stream
add_stream(conn, (KRPC.Interface.SpaceCenter.Vessel_Position(vessel, body_rf), )) do stream
for (position, ) in stream
println(position)
end
Expand Down
8 changes: 4 additions & 4 deletions src/kRPC.jl → src/KRPC.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module kRPC
module KRPC
using Sockets
using ProtoBuf
using LightXML
Expand All @@ -21,7 +21,7 @@ end
"""
A connection to Kerbal Space Program.
"""
mutable struct kRPCConnection
mutable struct KRPCConnection
conn::TCPSocket
stream_conn::TCPSocket
identifier::Array{UInt8, 1}
Expand All @@ -31,7 +31,7 @@ mutable struct kRPCConnection
active::Channel
end

function Base.show(io::IO, conn::kRPCConnection)
function Base.show(io::IO, conn::KRPCConnection)
print(io, "KRPC Connection(main fd: $(conn.conn), stream fd: $(conn.stream_conn))")
end

Expand All @@ -46,7 +46,7 @@ if isfile("generated.jl")
end

struct AddStream_Phantom <: Request{:KRPC, :AddStream, kRPCTypes.kStream}
call::kRPC.Request
call::KRPC.Request
start::Bool
end
struct RemoveStream_Phantom <: Request{:KRPC, :RemoveStream, Nothing}
Expand Down
10 changes: 5 additions & 5 deletions src/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function generate_wrapper_method(g::Union{StaticMember,Standard}, proc, procname
push!(args, make_param(argname, param, ctx))
push!(argnames, argname)
end
return mname, :($mname(conn::kRPCConnection, $(args...)) = kerbal(conn, $procname($(argnames...))))
return mname, :($mname(conn::KRPCConnection, $(args...)) = kerbal(conn, $procname($(argnames...))))
end
function generate_wrapper_method(g::ServiceGetter, proc, procname, ctx::SymbolContext)
name = Symbol(g.name)
Expand Down Expand Up @@ -275,7 +275,7 @@ function generateHelpers(info::krpc.schema.Services, status::krpc.schema.Status)
classnames = []
for clazz in service.classes
classname = kerbal_name(clazz.name)
push!(classes_ast,:(struct $classname <: kRPCTypes.Class conn::kRPCConnection; id::Int end))
push!(classes_ast,:(struct $classname <: kRPCTypes.Class conn::KRPCConnection; id::Int end))
push!(classnames, classname)
end

Expand Down Expand Up @@ -334,8 +334,8 @@ function generateHelpers(info::krpc.schema.Services, status::krpc.schema.Status)
for req in ctx.needed
push!(body.args, :(import ..($(Symbol(req)))))
end
push!(classes_ast, :(struct $service_module_name conn::kRPCConnection end))
push!(body.args, :(module RemoteTypes import ....kRPCTypes; import ....kRPCConnection; $(classes_ast...); $(Expr(:export, classnames...)); export $service_module_name; end))
push!(classes_ast, :(struct $service_module_name conn::KRPCConnection end))
push!(body.args, :(module RemoteTypes import ....kRPCTypes; import ....KRPCConnection; $(classes_ast...); $(Expr(:export, classnames...)); export $service_module_name; end))
append!(body.args, enumerations_ast)
if length(enumeration_names) > 0
push!(body.args, Expr(:export, enumeration_names...))
Expand All @@ -346,7 +346,7 @@ function generateHelpers(info::krpc.schema.Services, status::krpc.schema.Status)
end
push!(body.args, :(module Helpers
import ....kerbal;
import ....kRPCConnection;
import ....KRPCConnection;
import ....Request;
import ..RemoteTypes;
$((:(import ...($(Symbol(req)))) for req in ctx.needed)...);
Expand Down
21 changes: 5 additions & 16 deletions src/connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function connect_or_error(conn, cr::krpc.schema.ConnectionRequest)
end

"""
generate_stubs(conn::kRPCConnection; save_file::Bool=false)
generate_stubs(conn::KRPCConnection; save_file::Bool=false)
Generate (and `eval`) the stubs offered by the server at `conn`. If `save_file` is `true`,
then the stubs will be saved into the package's directory and will be imported
Expand All @@ -32,17 +32,6 @@ julia> generate_stubs(conn)
```
"""
function generate_stubs(conn; save_file=false)
#=
cachepath = joinpath(@__DIR__, "..", "deps")
genpath = joinpath(cachepath, "gen.jl")
if isfile(genpath)
kRPC.eval(:(include($genpath)))
else
mkpath(cachepath)
info = GetServices(conn)
println(info)
end
=#
serviceInfo = GetServices(conn)
status = kerbal(conn, GetStatus_Phantom())
ast = generateHelpers(serviceInfo, status.status)
Expand Down Expand Up @@ -89,15 +78,15 @@ function kerbal_connect(client_name::String, host::String="localhost", port::Int
connect_or_error(str_conn, krpc.schema.ConnectionRequest(client_identifier=resp.client_identifier,_type=krpc.schema.ConnectionRequest_Type.STREAM))

active = Channel(0)
conn = kRPCConnection(conn, str_conn, resp.client_identifier, Nothing(), Dict{UInt8, Listener}(), active)
conn = KRPCConnection(conn, str_conn, resp.client_identifier, Nothing(), Dict{UInt8, Listener}(), active)
conn.str_listener = @async stream_listener(conn)
bind(active, conn.str_listener)

if isdefined(kRPC, :Interface)
if isdefined(KRPC, :Interface)
server_version = kerbal(conn, GetStatus_Phantom()).status.version
if Interface.version != server_version
println("Warning: current stubs version $(Interface.version) is not equal to server's version $server_version")
println("some functions may not work correctly (or produce an error). Run kRPC.generateStubs(conn) to generate a new (one-time) copy of the stubs.")
println("some functions may not work correctly (or produce an error). Run KRPC.generateStubs(conn) to generate a new (one-time) copy of the stubs.")
end
end

Expand Down Expand Up @@ -129,7 +118,7 @@ function kerbal_connect(f::Function, client_name::String, host::String="localhos
end
end

function Base.close(conn::kRPCConnection)
function Base.close(conn::KRPCConnection)
try put!(conn.active, false) catch e end
Base.close(conn.conn)
end
Expand Down
Loading

0 comments on commit 305096e

Please sign in to comment.