Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC-Android
Manage
Activity
Members
Labels
Plan
Issues
528
Issue boards
Milestones
Wiki
Code
Merge requests
14
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLC-Android
Commits
e76b3a13
Commit
e76b3a13
authored
3 years ago
by
Hugo Beauzée-Luyssen
Committed by
Nicolas Pomepuy
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
jni: Add a wrapper to automatically release localrefs
parent
8ef33a4e
Loading
Loading
1 merge request
!1102
medialibrary: Simplify local refs handling
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
medialibrary/jni/utils.h
+96
-0
96 additions, 0 deletions
medialibrary/jni/utils.h
with
96 additions
and
0 deletions
medialibrary/jni/utils.h
+
96
−
0
View file @
e76b3a13
...
...
@@ -39,8 +39,104 @@
#include
<medialibrary/IBookmark.h>
#include
<medialibrary/filesystem/Errors.h>
#include
<type_traits>
#define VLC_JNI_VERSION JNI_VERSION_1_2
namespace
utils
{
namespace
jni
{
template
<
typename
T
>
class
localref
{
static_assert
(
std
::
is_pointer
<
T
>::
value
,
"T must be a pointer type"
);
public:
localref
(
JNIEnv
*
env
,
T
ref
)
:
m_env
(
env
)
,
m_ref
(
ref
)
{
}
localref
()
:
m_env
(
nullptr
)
,
m_ref
(
nullptr
)
{
}
~
localref
()
{
if
(
m_ref
)
{
assert
(
m_env
!=
nullptr
);
m_env
->
DeleteLocalRef
(
m_ref
);
}
}
/* Disable copy since there's no good reason to copy those and not move then */
localref
(
const
localref
&
)
=
delete
;
localref
&
operator
=
(
const
localref
&
)
=
delete
;
localref
(
localref
&&
old
)
:
m_env
(
nullptr
)
,
m_ref
(
nullptr
)
{
using
std
::
swap
;
swap
(
m_env
,
old
.
m_env
);
swap
(
m_ref
,
old
.
m_ref
);
}
localref
&
operator
=
(
localref
&&
rhs
)
{
if
(
m_ref
!=
nullptr
)
{
assert
(
m_env
!=
nullptr
);
m_env
->
DeleteLocalRef
(
m_ref
);
}
using
std
::
swap
;
swap
(
m_env
,
rhs
.
m_env
);
swap
(
m_ref
,
rhs
.
m_ref
);
return
*
this
;
}
T
get
()
const
{
return
m_ref
;
}
/**
* @brief release Will release the wrapper ownership but will *not* invoke DeleteLocalRef
* @return The underlying raw pointer
*
* This is meant to be used when a JNI value needs to be provided back to java
* which is expected to release the value itself
*/
T
release
()
{
auto
ref
=
m_ref
;
m_ref
=
nullptr
;
return
ref
;
}
bool
operator
==
(
std
::
nullptr_t
)
const
{
return
m_ref
==
nullptr
;
}
bool
operator
!=
(
std
::
nullptr_t
)
const
{
return
m_ref
!=
nullptr
;
}
private
:
JNIEnv
*
m_env
;
T
m_ref
;
};
using
string
=
localref
<
jstring
>
;
}
}
struct
fields
{
jint
SDK_INT
;
struct
IllegalStateException
{
...
...
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