Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cpplib
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cpplib
Commits
473e5532
Commit
473e5532
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
DRAFT: Include a `_deletable` flag
parent
08fa3e55
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!12
F consolidation
,
!9
Draft: API: remove UniqueResult, lower-case at, size for ResultSet
,
!8
ENH: Add retrieval and queries to Extern C interface
Pipeline
#11822
passed with warnings
3 years ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Pipeline: caosdb-cppinttest
#11823
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/ccaosdb.h
+10
-0
10 additions, 0 deletions
include/ccaosdb.h
src/ccaosdb.cpp
+62
-21
62 additions, 21 deletions
src/ccaosdb.cpp
test/test_ccaosdb.cpp
+8
-8
8 additions, 8 deletions
test/test_ccaosdb.cpp
with
80 additions
and
29 deletions
include/ccaosdb.h
+
10
−
0
View file @
473e5532
...
...
@@ -61,6 +61,7 @@ const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE();
*/
typedef
struct
{
void
*
wrapped_connection
;
bool
_deletable
=
false
;
}
caosdb_connection_connection
;
/**
...
...
@@ -72,6 +73,7 @@ typedef struct {
*/
typedef
struct
{
void
*
wrapped_connection_configuration
;
bool
_deletable
=
false
;
}
caosdb_connection_connection_configuration
;
/**
...
...
@@ -91,10 +93,12 @@ typedef struct {
typedef
struct
{
void
*
wrapped_certificate_provider
;
bool
_deletable
=
false
;
}
caosdb_connection_certificate_provider
;
typedef
struct
{
void
*
wrapped_authenticator
;
bool
_deletable
=
false
;
}
caosdb_authentication_authenticator
;
/**
...
...
@@ -263,6 +267,7 @@ int caosdb_connection_connection_manager_get_connection(
// not sufficient yet.
typedef
struct
{
void
*
wrapped_transaction
;
bool
_deletable
=
false
;
}
caosdb_transaction_transaction
;
/**
...
...
@@ -289,6 +294,7 @@ int caosdb_transaction_transaction_execute(
typedef
struct
{
void
*
wrapped_result_set
;
bool
_deletable
=
false
;
}
caosdb_transaction_result_set
;
int
caosdb_transaction_transaction_get_result_set
(
...
...
@@ -300,6 +306,7 @@ int caosdb_transaction_transaction_get_count_result(
typedef
struct
{
void
*
wrapped_entity
;
bool
_deletable
=
false
;
}
caosdb_entity_entity
;
int
caosdb_transaction_result_set_at
(
caosdb_transaction_result_set
*
result_set
,
...
...
@@ -309,12 +316,15 @@ int caosdb_transaction_result_set_size(
typedef
struct
{
void
*
wrapped_property
;
bool
_deletable
=
false
;
}
caosdb_entity_property
;
typedef
struct
{
void
*
wrapped_parent
;
bool
_deletable
=
false
;
}
caosdb_entity_parent
;
typedef
struct
{
void
*
wrapped_message
;
bool
_deletable
=
false
;
}
caosdb_entity_message
;
// GETTERS FOR EVERYTHING
...
...
This diff is collapsed.
Click to expand it.
src/ccaosdb.cpp
+
62
−
21
View file @
473e5532
...
...
@@ -180,6 +180,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
out
->
wrapped_certificate_provider
=
new
caosdb
::
configuration
::
PemFileCertificateProvider
(
std
::
string
(
path
));
out
->
_deletable
=
true
;
return
0
;
})
...
...
@@ -188,8 +189,11 @@ ERROR_RETURN_CODE(
int
caosdb_connection_delete_certificate_provider
(
caosdb_connection_certificate_provider
*
provider
),
{
delete
static_cast
<
caosdb
::
configuration
::
CertificateProvider
*>
(
provider
->
wrapped_certificate_provider
);
if
(
provider
->
_deletable
)
{
delete
static_cast
<
caosdb
::
configuration
::
CertificateProvider
*>
(
provider
->
wrapped_certificate_provider
);
}
provider
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -201,17 +205,22 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
out
->
wrapped_authenticator
=
new
caosdb
::
authentication
::
PlainPasswordAuthenticator
(
std
::
string
(
username
),
std
::
string
(
password
));
out
->
_deletable
=
true
;
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_authentication_delete_authenticator
(
caosdb_authentication_authenticator
*
authenticator
),
{
delete
static_cast
<
caosdb
::
authentication
::
Authenticator
*>
(
authenticator
->
wrapped_authenticator
);
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_authentication_delete_authenticator
(
caosdb_authentication_authenticator
*
authenticator
),
{
if
(
authenticator
->
_deletable
)
{
delete
static_cast
<
caosdb
::
authentication
::
Authenticator
*>
(
authenticator
->
wrapped_authenticator
);
}
authenticator
->
_deletable
=
false
;
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
...
...
@@ -249,6 +258,7 @@ ERROR_RETURN_CODE(
out
->
wrapped_connection_configuration
=
new
caosdb
::
configuration
::
TlsConnectionConfiguration
(
host_str
,
port
);
}
out
->
_deletable
=
true
;
return
0
;
})
...
...
@@ -260,6 +270,7 @@ ERROR_RETURN_CODE(
{
out
->
wrapped_connection_configuration
=
new
caosdb
::
configuration
::
InsecureConnectionConfiguration
(
host
,
port
);
out
->
_deletable
=
true
;
return
0
;
})
...
...
@@ -268,8 +279,11 @@ ERROR_RETURN_CODE(
int
caosdb_connection_delete_connection_configuration
(
caosdb_connection_connection_configuration
*
configuration
),
{
delete
static_cast
<
caosdb
::
configuration
::
ConnectionConfiguration
*>
(
configuration
->
wrapped_connection_configuration
);
if
(
configuration
->
_deletable
)
{
delete
static_cast
<
caosdb
::
configuration
::
ConnectionConfiguration
*>
(
configuration
->
wrapped_connection_configuration
);
}
configuration
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -283,6 +297,7 @@ ERROR_RETURN_CODE(
static_cast
<
caosdb
::
configuration
::
ConnectionConfiguration
*>
(
configuration
->
wrapped_connection_configuration
);
out
->
wrapped_connection
=
new
caosdb
::
connection
::
Connection
(
*
config
);
out
->
_deletable
=
true
;
return
0
;
})
...
...
@@ -290,8 +305,11 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
int
caosdb_connection_delete_connection
(
caosdb_connection_connection
*
connection
),
{
delete
static_cast
<
caosdb
::
connection
::
Connection
*>
(
connection
->
wrapped_connection
);
if
(
connection
->
_deletable
)
{
delete
static_cast
<
caosdb
::
connection
::
Connection
*>
(
connection
->
wrapped_connection
);
}
connection
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -347,6 +365,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
caosdb
::
connection
::
ConnectionManager
::
GetConnection
(
std
::
string
(
name
))
.
get
();
// managed by the connection manager now, so not
// to be deleted manually
out
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -363,6 +384,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
connection
->
wrapped_connection
);
out
->
wrapped_transaction
=
wrapped_connection
->
CreateTransaction
().
release
();
out
->
_deletable
=
true
;
return
0
;
})
...
...
@@ -370,8 +392,10 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
int
caosdb_transaction_delete_transaction
(
caosdb_transaction_transaction
*
transaction
),
{
delete
static_cast
<
caosdb
::
transaction
::
Transaction
*>
(
transaction
->
wrapped_transaction
);
if
(
transaction
->
_deletable
)
{
delete
static_cast
<
caosdb
::
transaction
::
Transaction
*>
(
transaction
->
wrapped_transaction
);
}
return
0
;
})
...
...
@@ -476,13 +500,17 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_create_entity
(
caosdb_entity_entity
*
out
),
{
out
->
wrapped_entity
=
new
caosdb
::
entity
::
Entity
();
out
->
_deletable
=
true
;
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_delete_entity
(
caosdb_entity_entity
*
out
),
{
delete
static_cast
<
caosdb
::
entity
::
Entity
*>
(
out
->
wrapped_entity
);
if
(
out
->
_deletable
)
{
delete
static_cast
<
caosdb
::
entity
::
Entity
*>
(
out
->
wrapped_entity
);
}
out
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -490,26 +518,34 @@ ERROR_RETURN_CODE(
GENERIC_ERROR
,
int
caosdb_entity_create_property
(
caosdb_entity_property
*
out
),
{
out
->
wrapped_property
=
new
caosdb
::
entity
::
Property
();
out
->
_deletable
=
true
;
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_delete_property
(
caosdb_entity_property
*
out
),
{
delete
static_cast
<
caosdb
::
entity
::
Property
*>
(
out
->
wrapped_property
);
if
(
out
->
_deletable
)
{
delete
static_cast
<
caosdb
::
entity
::
Property
*>
(
out
->
wrapped_property
);
}
out
->
_deletable
=
false
;
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_create_parent
(
caosdb_entity_parent
*
out
),
{
out
->
wrapped_parent
=
new
caosdb
::
entity
::
Parent
();
out
->
_deletable
=
true
;
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_delete_parent
(
caosdb_entity_parent
*
out
),
{
delete
static_cast
<
caosdb
::
entity
::
Parent
*>
(
out
->
wrapped_parent
);
if
(
out
->
_deletable
)
{
delete
static_cast
<
caosdb
::
entity
::
Parent
*>
(
out
->
wrapped_parent
);
}
out
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -543,6 +579,7 @@ ERROR_RETURN_CODE(
auto
*
wrapped_entity
=
static_cast
<
caosdb
::
entity
::
Entity
*>
(
entity
->
wrapped_entity
);
out
->
wrapped_message
=
wrapped_entity
->
GetErrors
().
mutable_at
(
index
);
out
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -565,6 +602,7 @@ ERROR_RETURN_CODE(
auto
*
wrapped_entity
=
static_cast
<
caosdb
::
entity
::
Entity
*>
(
entity
->
wrapped_entity
);
out
->
wrapped_message
=
wrapped_entity
->
GetWarnings
().
mutable_at
(
index
);
out
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -587,6 +625,7 @@ ERROR_RETURN_CODE(
auto
*
wrapped_entity
=
static_cast
<
caosdb
::
entity
::
Entity
*>
(
entity
->
wrapped_entity
);
out
->
wrapped_message
=
wrapped_entity
->
GetInfos
().
mutable_at
(
index
);
out
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -609,6 +648,7 @@ ERROR_RETURN_CODE(
auto
*
wrapped_entity
=
static_cast
<
caosdb
::
entity
::
Entity
*>
(
entity
->
wrapped_entity
);
out
->
wrapped_property
=
wrapped_entity
->
GetProperties
().
mutable_at
(
index
);
out
->
_deletable
=
false
;
return
0
;
})
...
...
@@ -631,6 +671,7 @@ ERROR_RETURN_CODE(
auto
*
wrapped_entity
=
static_cast
<
caosdb
::
entity
::
Entity
*>
(
entity
->
wrapped_entity
);
out
->
wrapped_parent
=
wrapped_entity
->
GetParents
().
mutable_at
(
index
);
out
->
_deletable
=
false
;
return
0
;
})
...
...
This diff is collapsed.
Click to expand it.
test/test_ccaosdb.cpp
+
8
−
8
View file @
473e5532
...
...
@@ -324,13 +324,13 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
return_code
=
caosdb_entity_delete_entity
(
&
entity
);
EXPECT_EQ
(
return_code
,
0
);
// T
ODO(fspreck) This fails, because the output_p{arent,roperty} is owned
//
by the entity (which is
a
l
re
ady deleted). Also, this shows that it is
//
dangerous to call the deletion of output_p{arent,roperty} before the
//
entity is being deleted, because it screws up the RepeatedPtrFieldWrapper
.
// T
his tests the `_deletable` flag. The wrapped cpp objects of
//
`output_parent` and `output_property`
are
owned by the entity, so
//
they have been deleted together with the entity. With a wrong
//
`_deletable` flag, the following would cause segfaults
.
//
//
return_code = caosdb_entity_delete_parent(&output_parent);
//
EXPECT_EQ(return_code, 0);
//
return_code = caosdb_entity_delete_property(&output_property);
//
EXPECT_EQ(return_code, 0);
return_code
=
caosdb_entity_delete_parent
(
&
output_parent
);
EXPECT_EQ
(
return_code
,
0
);
return_code
=
caosdb_entity_delete_property
(
&
output_property
);
EXPECT_EQ
(
return_code
,
0
);
}
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