Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-julialib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-julialib
Commits
e527a0c3
Commit
e527a0c3
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Allow the void pointees to be managed by C or by Julia
parent
f11e5072
No related branches found
No related tags found
1 merge request
!4
ENH: Add minimal functionality
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Connection.jl
+82
-23
82 additions, 23 deletions
src/Connection.jl
with
82 additions
and
23 deletions
src/Connection.jl
+
82
−
23
View file @
e527a0c3
...
@@ -25,7 +25,7 @@ module Connection
...
@@ -25,7 +25,7 @@ module Connection
using
..
CaosDB
using
..
CaosDB
export
connect
export
connect
,
connect_manually
"""
"""
Struct containing the actual connection to a CaosDB server. Meant for
Struct containing the actual connection to a CaosDB server. Meant for
...
@@ -35,11 +35,13 @@ to create an connection object from a configuration.
...
@@ -35,11 +35,13 @@ to create an connection object from a configuration.
mutable struct
_Connection
mutable struct
_Connection
wrapped_connection
::
Ptr
{
Cvoid
}
wrapped_connection
::
Ptr
{
Cvoid
}
function
_Connection
()
function
_Connection
(
managed_by_julia
::
Bool
=
false
)
conn
=
new
()
conn
=
new
()
conn
.
wrapped_connection
=
C_NULL
if
managed_by_julia
# Only append a finalizer for this if the object is
# actually managed by Julia and not created and destroyed
# internally by libcaosdb.
function
f
(
t
)
function
f
(
t
)
if
t
.
wrapped_connection
!=
C_NULL
ccall
(
ccall
(
(
:
caosdb_connection_delete_connection
,
"libccaosdb"
),
(
:
caosdb_connection_delete_connection
,
"libccaosdb"
),
Cint
,
Cint
,
...
@@ -47,9 +49,10 @@ mutable struct _Connection
...
@@ -47,9 +49,10 @@ mutable struct _Connection
Ref
{
_Connection
}(
t
),
Ref
{
_Connection
}(
t
),
)
)
end
end
end
finalizer
(
f
,
conn
)
finalizer
(
f
,
conn
)
end
end
return
conn
end
end
end
"""
"""
...
@@ -61,11 +64,13 @@ an certificate-provider object from a configuration.
...
@@ -61,11 +64,13 @@ an certificate-provider object from a configuration.
mutable struct
_CertificateProvider
mutable struct
_CertificateProvider
wrapped_certificate_provider
::
Ptr
{
Cvoid
}
wrapped_certificate_provider
::
Ptr
{
Cvoid
}
function
_CertificateProvider
()
function
_CertificateProvider
(
managed_by_julia
::
Bool
=
false
)
prov
=
new
()
prov
=
new
()
prov
.
wrapped_certificate_provider
=
C_NULL
if
managed_by_julia
# Only append a finalizer for this if the object is
# actually managed by Julia and not created and destroyed
# internally by libcaosdb.
function
f
(
t
)
function
f
(
t
)
if
t
.
wrapped_certificate_provider
!=
C_NULL
ccall
(
ccall
(
(
:
caosdb_connection_delete_certificate_provider
,
"libccaosdb"
),
(
:
caosdb_connection_delete_certificate_provider
,
"libccaosdb"
),
Cint
,
Cint
,
...
@@ -73,9 +78,10 @@ mutable struct _CertificateProvider
...
@@ -73,9 +78,10 @@ mutable struct _CertificateProvider
Ref
{
_CertificateProvider
}(
t
),
Ref
{
_CertificateProvider
}(
t
),
)
)
end
end
end
finalizer
(
f
,
prov
)
finalizer
(
f
,
prov
)
end
end
return
prov
end
end
end
"""
"""
...
@@ -87,11 +93,10 @@ an connection-configuration object from a configuration.
...
@@ -87,11 +93,10 @@ an connection-configuration object from a configuration.
mutable struct
_Configuration
mutable struct
_Configuration
wrapped_connection_configuration
::
Ptr
{
Cvoid
}
wrapped_connection_configuration
::
Ptr
{
Cvoid
}
function
_Configuration
()
function
_Configuration
(
managed_by_julia
::
Bool
=
false
)
config
=
new
()
config
=
new
()
config
.
wrapped_connection_configuration
=
C_NULL
if
managed_by_julia
function
f
(
t
)
function
f
(
t
)
if
t
.
wrapped_connection_configuration
!=
C_NULL
ccall
(
ccall
(
(
:
caosdb_connection_delete_connection_configuration
,
"libccaosdb"
),
(
:
caosdb_connection_delete_connection_configuration
,
"libccaosdb"
),
Cint
,
Cint
,
...
@@ -99,9 +104,10 @@ mutable struct _Configuration
...
@@ -99,9 +104,10 @@ mutable struct _Configuration
Ref
{
_Configuration
}(
t
),
Ref
{
_Configuration
}(
t
),
)
)
end
end
end
finalizer
(
f
,
config
)
finalizer
(
f
,
config
)
end
end
return
config
end
end
end
"""
"""
...
@@ -112,7 +118,7 @@ Return a `_CertificateProvider` for the pem certificate located at
...
@@ -112,7 +118,7 @@ Return a `_CertificateProvider` for the pem certificate located at
"""
"""
function
create_pem_file_certificate_provider
(
path
::
AbstractString
)
function
create_pem_file_certificate_provider
(
path
::
AbstractString
)
cert_provider
=
Ref
{
_CertificateProvider
}(
_CertificateProvider
())
cert_provider
=
Ref
{
_CertificateProvider
}(
_CertificateProvider
(
true
))
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_create_pem_file_certificate_provider
,
"libccaosdb"
),
(
:
caosdb_connection_create_pem_file_certificate_provider
,
"libccaosdb"
),
...
@@ -149,7 +155,7 @@ function create_tls_connection_configuration(
...
@@ -149,7 +155,7 @@ function create_tls_connection_configuration(
provider
::
Ref
{
_CertificateProvider
},
provider
::
Ref
{
_CertificateProvider
},
)
)
config
=
Ref
{
_Configuration
}(
_Configuration
())
config
=
Ref
{
_Configuration
}(
_Configuration
(
true
))
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_create_tls_connection_configuration
,
"libccaosdb"
),
(
:
caosdb_connection_create_tls_connection_configuration
,
"libccaosdb"
),
...
@@ -180,7 +186,7 @@ end
...
@@ -180,7 +186,7 @@ end
function
create_insecure_connection_configuration
(
host
::
AbstractString
,
port
::
Cint
)
function
create_insecure_connection_configuration
(
host
::
AbstractString
,
port
::
Cint
)
config
=
Ref
{
_Configuration
}(
_Configuration
())
config
=
Ref
{
_Configuration
}(
_Configuration
(
true
))
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_create_insecure_connection_configuration
,
"libccaosdb"
),
(
:
caosdb_connection_create_insecure_connection_configuration
,
"libccaosdb"
),
...
@@ -207,7 +213,7 @@ Return a connection based on the given `config`.
...
@@ -207,7 +213,7 @@ Return a connection based on the given `config`.
"""
"""
function
create_connection
(
config
::
Ref
{
_Configuration
})
function
create_connection
(
config
::
Ref
{
_Configuration
})
connection
=
Ref
{
_Connection
}(
_Connection
())
connection
=
Ref
{
_Connection
}(
_Connection
(
true
))
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_create_connection
,
"libccaosdb"
),
(
:
caosdb_connection_create_connection
,
"libccaosdb"
),
...
@@ -227,6 +233,39 @@ function create_connection(config::Ref{_Configuration})
...
@@ -227,6 +233,39 @@ function create_connection(config::Ref{_Configuration})
end
end
function
get_connection
(
name
::
AbstractString
=
"default"
)
connection
=
Ref
{
_Connection
}(
_Connection
())
if
name
==
"default"
err_code
=
ccall
(
(
:
caosdb_connection_connection_manager_get_default_connection
,
"libccaosdb"
),
Cint
,
(
Ref
{
_Connection
},),
connection
)
else
err_code
=
ccall
(
(
:
caosdb_connection_connection_manager_get_connection
,
"libccaosdb"
),
Cint
,
(
Ref
{
_Connection
},
Cstring
),
connection
,
name
)
end
if
err_code
!=
0
@error
"Creating connection '
$
name' failed with code
$
err_code"
end
return
connection
end
"""
"""
get_version_info(con::Ref{_Connection})
get_version_info(con::Ref{_Connection})
...
@@ -235,7 +274,7 @@ to.
...
@@ -235,7 +274,7 @@ to.
"""
"""
function
get_version_info
(
con
::
Ref
{
_Connection
})
function
get_version_info
(
con
::
Ref
{
_Connection
})
info
=
Ref
{
CaosDB
.
Info
.
_VersionInfo
}(
CaosDB
.
Info
.
_VersionInfo
())
info
=
Ref
{
CaosDB
.
Info
.
_VersionInfo
}(
CaosDB
.
Info
.
_VersionInfo
(
true
))
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_get_version_info
,
"libccaosdb"
),
(
:
caosdb_connection_get_version_info
,
"libccaosdb"
),
...
@@ -280,7 +319,7 @@ function print_version_info(con::Ref{_Connection})
...
@@ -280,7 +319,7 @@ function print_version_info(con::Ref{_Connection})
end
end
"""
"""
function connect([;
function connect
_manually
([;
host::AbstractString="",
host::AbstractString="",
port_str::AbstractString="
undefined
",
port_str::AbstractString="
undefined
",
cacert::AbstractString="",
cacert::AbstractString="",
...
@@ -325,7 +364,7 @@ SSL certificate located at `cacert` with the given credentials.
...
@@ -325,7 +364,7 @@ SSL certificate located at `cacert` with the given credentials.
not defined, "
caosdb
" is used. The default value is "
undefined
"
not defined, "
caosdb
" is used. The default value is "
undefined
"
rather than an empty string to allow an empty password.
rather than an empty string to allow an empty password.
"""
"""
function
connect
(;
function
connect
_manually
(;
host
::
AbstractString
=
""
,
host
::
AbstractString
=
""
,
port_str
::
AbstractString
=
"undefined"
,
port_str
::
AbstractString
=
"undefined"
,
cacert
::
AbstractString
=
""
,
cacert
::
AbstractString
=
""
,
...
@@ -376,4 +415,24 @@ function connect(;
...
@@ -376,4 +415,24 @@ function connect(;
end
end
"""
connect(name::AbstractString="
default
")
Create a connection with name `name` from your configuration file,
print the version of the server the connection is established to, and
return the connection object.
# Arguments
- name::AbstractString="
default
": The name of the configuration
defined in your config json that will be used to connect to the
CaosDB server defined therein. Default value is "
default
".
"""
function
connect
(
name
::
AbstractString
=
"default"
)
conn
=
get_connection
(
name
)
print_version_info
(
conn
)
return
conn
end
end
# Connection
end
# Connection
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment