Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
b8be3fa0
Commit
b8be3fa0
authored
Nov 06, 2017
by
Ronan
Browse files
fix(c-wrapper): add private on some functions, owner is by default External
parent
e37f307c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/c-wrapper/internal/c-tools.h
View file @
b8be3fa0
...
...
@@ -122,8 +122,8 @@ private:
// ---------------------------------------------------------------------------
enum
class
WrappedObjectOwner
:
int
{
In
ternal
,
Ex
ternal
Ex
ternal
,
In
ternal
};
template
<
typename
CppType
>
...
...
@@ -132,7 +132,7 @@ private:
std
::
shared_ptr
<
CppType
>
cppPtr
;
std
::
weak_ptr
<
CppType
>
weakCppPtr
;
// By default:
In
ternal.
// By default:
Ex
ternal.
WrappedObjectOwner
owner
;
};
...
...
@@ -151,22 +151,39 @@ private:
std
::
terminate
();
}
public:
// ---------------------------------------------------------------------------
//
Belle sip handlers.
//
Deal with floating references
.
//
Get cpp ptr (shared if BaseObject, not shared if ClonableObject)
//
from cpp object
.
// ---------------------------------------------------------------------------
static
void
onBelleSipFirstRef
(
belle_sip_object_t
*
base
)
{
WrappedBaseObject
<
BaseObject
>
*
wrappedObject
=
reinterpret_cast
<
WrappedBaseObject
<
BaseObject
>
*>
(
base
);
if
(
wrappedObject
->
owner
==
WrappedObjectOwner
::
Internal
)
wrappedObject
->
cppPtr
=
wrappedObject
->
weakCppPtr
.
lock
();
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
IsDefinedBaseCppObject
<
CppType
>
::
value
,
CppType
>::
type
>
static
inline
std
::
shared_ptr
<
CppType
>
getResolvedCppPtr
(
const
CppType
*
cppObject
)
{
if
(
L_UNLIKELY
(
!
cppObject
))
return
nullptr
;
try
{
typedef
typename
std
::
decay
<
decltype
(
*
cppObject
->
getSharedFromThis
())
>::
type
SharedFromThisType
;
return
std
::
static_pointer_cast
<
CppType
>
(
std
::
const_pointer_cast
<
SharedFromThisType
>
(
cppObject
->
getSharedFromThis
())
);
}
catch
(
const
std
::
bad_weak_ptr
&
e
)
{
abort
(
e
.
what
());
}
L_ASSERT
(
false
);
return
nullptr
;
}
static
void
onBelleSipLastRef
(
belle_sip_object_t
*
base
)
{
WrappedBaseObject
<
BaseObject
>
*
wrappedObject
=
reinterpret_cast
<
WrappedBaseObject
<
BaseObject
>
*>
(
base
);
if
(
wrappedObject
->
owner
==
WrappedObjectOwner
::
Internal
)
wrappedObject
->
cppPtr
.
reset
();
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
IsDefinedClonableCppObject
<
CppType
>
::
value
,
CppType
>::
type
>
static
constexpr
const
CppType
*
getResolvedCppPtr
(
const
CppType
*
cppObject
)
{
return
cppObject
;
}
// ---------------------------------------------------------------------------
...
...
@@ -192,6 +209,24 @@ public:
#endif
}
public:
// ---------------------------------------------------------------------------
// Belle sip handlers.
// Deal with floating references.
// ---------------------------------------------------------------------------
static
void
onBelleSipFirstRef
(
belle_sip_object_t
*
base
)
{
WrappedBaseObject
<
BaseObject
>
*
wrappedObject
=
reinterpret_cast
<
WrappedBaseObject
<
BaseObject
>
*>
(
base
);
if
(
wrappedObject
->
owner
==
WrappedObjectOwner
::
Internal
)
wrappedObject
->
cppPtr
=
wrappedObject
->
weakCppPtr
.
lock
();
}
static
void
onBelleSipLastRef
(
belle_sip_object_t
*
base
)
{
WrappedBaseObject
<
BaseObject
>
*
wrappedObject
=
reinterpret_cast
<
WrappedBaseObject
<
BaseObject
>
*>
(
base
);
if
(
wrappedObject
->
owner
==
WrappedObjectOwner
::
Internal
)
wrappedObject
->
cppPtr
.
reset
();
}
// ---------------------------------------------------------------------------
// Get private data of cpp Object.
// ---------------------------------------------------------------------------
...
...
@@ -356,45 +391,11 @@ public:
setCppPtrFromC
(
cObject
,
new
CppType
(
*
cppObject
));
}
// ---------------------------------------------------------------------------
// Get cpp ptr (shared if BaseObject, not shared if ClonableObject)
// from cpp object.
// ---------------------------------------------------------------------------
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
IsDefinedBaseCppObject
<
CppType
>
::
value
,
CppType
>::
type
>
static
inline
std
::
shared_ptr
<
CppType
>
getResolvedCppPtr
(
const
CppType
*
cppObject
)
{
if
(
L_UNLIKELY
(
!
cppObject
))
return
nullptr
;
try
{
typedef
typename
std
::
decay
<
decltype
(
*
cppObject
->
getSharedFromThis
())
>::
type
SharedFromThisType
;
return
std
::
static_pointer_cast
<
CppType
>
(
std
::
const_pointer_cast
<
SharedFromThisType
>
(
cppObject
->
getSharedFromThis
())
);
}
catch
(
const
std
::
bad_weak_ptr
&
e
)
{
abort
(
e
.
what
());
}
L_ASSERT
(
false
);
return
nullptr
;
}
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
IsDefinedClonableCppObject
<
CppType
>
::
value
,
CppType
>::
type
>
static
constexpr
const
CppType
*
getResolvedCppPtr
(
const
CppType
*
cppObject
)
{
return
cppObject
;
}
// ---------------------------------------------------------------------------
// Get c back ptr resolver helpers.
// ---------------------------------------------------------------------------
private:
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
IsDefinedBaseCppObject
<
CppType
>
::
value
,
CppType
>::
type
...
...
@@ -427,6 +428,7 @@ public:
// Get c back ptr helpers.
// ---------------------------------------------------------------------------
public:
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment