Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ThummeTo/FMIImport.jl into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
ThummeTo committed Aug 9, 2024
2 parents 108d13b + f9dba58 commit d8edf53
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMIImport"
uuid = "9fcbc62e-52a0-44e9-a616-1359a0008194"
authors = ["TT <tobias.thummerer@informatik.uni-augsburg.de>", "LM <lars.mikelsons@informatik.uni-augsburg.de>", "JK <josef.kircher@student.uni-augsburg.de>"]
version = "1.0.1"
version = "1.0.2"

[deps]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand Down
18 changes: 9 additions & 9 deletions src/FMI2/ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,23 @@ function loadPointers(fmu::FMU2)
fmu.cSetInteger = dlsym(fmu.libHandle, :fmi2SetInteger)
fmu.cGetBoolean = dlsym(fmu.libHandle, :fmi2GetBoolean)
fmu.cSetBoolean = dlsym(fmu.libHandle, :fmi2SetBoolean)
fmu.cGetString = dlsym_opt(fmu.libHandle, :fmi2GetString)
fmu.cSetString = dlsym_opt(fmu.libHandle, :fmi2SetString)
fmu.cGetString = dlsym_opt(fmu, fmu.libHandle, :fmi2GetString)
fmu.cSetString = dlsym_opt(fmu, fmu.libHandle, :fmi2SetString)

if canGetSetFMUState(fmu.modelDescription)
fmu.cGetFMUstate = dlsym_opt(fmu.libHandle, :fmi2GetFMUstate)
fmu.cSetFMUstate = dlsym_opt(fmu.libHandle, :fmi2SetFMUstate)
fmu.cFreeFMUstate = dlsym_opt(fmu.libHandle, :fmi2FreeFMUstate)
fmu.cGetFMUstate = dlsym_opt(fmu, fmu.libHandle, :fmi2GetFMUstate)
fmu.cSetFMUstate = dlsym_opt(fmu, fmu.libHandle, :fmi2SetFMUstate)
fmu.cFreeFMUstate = dlsym_opt(fmu, fmu.libHandle, :fmi2FreeFMUstate)
end

if canSerializeFMUState(fmu.modelDescription)
fmu.cSerializedFMUstateSize = dlsym_opt(fmu.libHandle, :fmi2SerializedFMUstateSize)
fmu.cSerializeFMUstate = dlsym_opt(fmu.libHandle, :fmi2SerializeFMUstate)
fmu.cDeSerializeFMUstate = dlsym_opt(fmu.libHandle, :fmi2DeSerializeFMUstate)
fmu.cSerializedFMUstateSize = dlsym_opt(fmu, fmu.libHandle, :fmi2SerializedFMUstateSize)
fmu.cSerializeFMUstate = dlsym_opt(fmu, fmu.libHandle, :fmi2SerializeFMUstate)
fmu.cDeSerializeFMUstate = dlsym_opt(fmu, fmu.libHandle, :fmi2DeSerializeFMUstate)
end

if providesDirectionalDerivatives(fmu.modelDescription)
fmu.cGetDirectionalDerivative = dlsym_opt(fmu.libHandle, :fmi2GetDirectionalDerivative)
fmu.cGetDirectionalDerivative = dlsym_opt(fmu, fmu.libHandle, :fmi2GetDirectionalDerivative)
end

# CS specific function calls
Expand Down
24 changes: 12 additions & 12 deletions src/FMI3/ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,29 +187,29 @@ function loadPointers(fmu::FMU3)
fmu.cGetBoolean = dlsym(fmu.libHandle, :fmi3GetBoolean)
fmu.cSetBoolean = dlsym(fmu.libHandle, :fmi3SetBoolean)

fmu.cGetString = dlsym_opt(fmu.libHandle, :fmi3GetString)
fmu.cSetString = dlsym_opt(fmu.libHandle, :fmi3SetString)
fmu.cGetBinary = dlsym_opt(fmu.libHandle, :fmi3GetBinary)
fmu.cSetBinary = dlsym_opt(fmu.libHandle, :fmi3SetBinary)
fmu.cGetString = dlsym_opt(fmu, fmu.libHandle, :fmi3GetString)
fmu.cSetString = dlsym_opt(fmu, fmu.libHandle, :fmi3SetString)
fmu.cGetBinary = dlsym_opt(fmu, fmu.libHandle, :fmi3GetBinary)
fmu.cSetBinary = dlsym_opt(fmu, fmu.libHandle, :fmi3SetBinary)

if canGetSetFMUState(fmu)
fmu.cGetFMUState = dlsym_opt(fmu.libHandle, :fmi3GetFMUState)
fmu.cSetFMUState = dlsym_opt(fmu.libHandle, :fmi3SetFMUState)
fmu.cFreeFMUState = dlsym_opt(fmu.libHandle, :fmi3FreeFMUState)
fmu.cGetFMUState = dlsym_opt(fmu, fmu.libHandle, :fmi3GetFMUState)
fmu.cSetFMUState = dlsym_opt(fmu, fmu.libHandle, :fmi3SetFMUState)
fmu.cFreeFMUState = dlsym_opt(fmu, fmu.libHandle, :fmi3FreeFMUState)
end

if canSerializeFMUState(fmu)
fmu.cSerializedFMUStateSize = dlsym_opt(fmu.libHandle, :fmi3SerializedFMUStateSize)
fmu.cSerializeFMUState = dlsym_opt(fmu.libHandle, :fmi3SerializeFMUState)
fmu.cDeSerializeFMUState = dlsym_opt(fmu.libHandle, :fmi3DeserializeFMUState)
fmu.cSerializedFMUStateSize = dlsym_opt(fmu, fmu.libHandle, :fmi3SerializedFMUStateSize)
fmu.cSerializeFMUState = dlsym_opt(fmu, fmu.libHandle, :fmi3SerializeFMUState)
fmu.cDeSerializeFMUState = dlsym_opt(fmu, fmu.libHandle, :fmi3DeserializeFMUState)
end

if providesDirectionalDerivatives(fmu)
fmu.cGetDirectionalDerivative = dlsym_opt(fmu.libHandle, :fmi3GetDirectionalDerivative)
fmu.cGetDirectionalDerivative = dlsym_opt(fmu, fmu.libHandle, :fmi3GetDirectionalDerivative)
end

if providesAdjointDerivatives(fmu)
fmu.cGetAdjointDerivative = dlsym_opt(fmu.libHandle, :fmi3GetAdjointDerivative)
fmu.cGetAdjointDerivative = dlsym_opt(fmu, fmu.libHandle, :fmi3GetAdjointDerivative)
end

# CS specific function calls
Expand Down
21 changes: 17 additions & 4 deletions src/binary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@

using FMIBase.EzXML

function dlsym_opt(libHandle, symbol)
"""
dlsym_opt(fmu, libHandle, symbol)
The same as `dlsym(libHandle, symbol)`, but returns - `Ptr{Cvoid}(C_NULL)` if the symbol `symbol` is not available.
# Arguments
- `fmu`: The FMU to log a info message if not available.
- `libHandle`: The library handle, see `dlsym`.
- `symbol`: The library symbol, see `dlsym`.
# Returns
Library symbol if available, else `Ptr{Cvoid}(C_NULL)`.
"""
function dlsym_opt(fmu, libHandle, symbol)
addr = dlsym(libHandle, symbol; throw_error=false)
if addr == nothing
logWarning(fmu, "This FMU does not support function '$symbol'.")
if isnothing(addr)
logInfo(fmu, "This FMU does not support the optional function '$symbol'.")
addr = Ptr{Cvoid}(C_NULL)
end
addr
return addr
end

"""
Expand Down

0 comments on commit d8edf53

Please sign in to comment.