Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
djinni
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
djinni
Commits
ed6ef3c5
Commit
ed6ef3c5
authored
Sep 18, 2014
by
Jacob Potter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Naming fixes: switch towards Proxy instead of Wrapper
parent
15002676
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
38 deletions
+38
-38
example/generated-src/jni/NativeTextboxListener.cpp
example/generated-src/jni/NativeTextboxListener.cpp
+1
-1
example/generated-src/jni/NativeTextboxListener.hpp
example/generated-src/jni/NativeTextboxListener.hpp
+3
-3
src/source/JNIGenerator.scala
src/source/JNIGenerator.scala
+4
-4
support-lib/jni/djinni_support.cpp
support-lib/jni/djinni_support.cpp
+10
-10
support-lib/jni/djinni_support.hpp
support-lib/jni/djinni_support.hpp
+16
-16
test-suite/generated-src/jni/NativeClientInterface.cpp
test-suite/generated-src/jni/NativeClientInterface.cpp
+1
-1
test-suite/generated-src/jni/NativeClientInterface.hpp
test-suite/generated-src/jni/NativeClientInterface.hpp
+3
-3
No files found.
example/generated-src/jni/NativeTextboxListener.cpp
View file @
ed6ef3c5
...
...
@@ -8,7 +8,7 @@ namespace djinni_generated {
NativeTextboxListener
::
NativeTextboxListener
()
:
djinni
::
JniInterfaceJavaExt
<::
textsort
::
TextboxListener
,
NativeTextboxListener
>
()
{}
NativeTextboxListener
::
JavaProxy
::
JavaProxy
(
jobject
obj
)
:
J
niWrapper
CacheEntry
(
obj
)
{}
NativeTextboxListener
::
JavaProxy
::
JavaProxy
(
jobject
obj
)
:
J
avaProxy
CacheEntry
(
obj
)
{}
void
NativeTextboxListener
::
JavaProxy
::
JavaProxy
::
update
(
const
::
textsort
::
ItemList
&
c_items
)
{
JNIEnv
*
const
jniEnv
=
djinni
::
jniGetThreadEnv
();
...
...
example/generated-src/jni/NativeTextboxListener.hpp
View file @
ed6ef3c5
...
...
@@ -18,15 +18,15 @@ public:
const
djinni
::
GlobalRef
<
jclass
>
clazz
{
djinni
::
jniFindClass
(
"com/dropbox/textsort/TextboxListener"
)
};
const
jmethodID
method_update
{
djinni
::
jniGetMethodID
(
clazz
.
get
(),
"update"
,
"(Lcom/dropbox/textsort/ItemList;)V"
)
};
class
JavaProxy
final
:
djinni
::
J
niWrapper
CacheEntry
,
public
::
textsort
::
TextboxListener
{
class
JavaProxy
final
:
djinni
::
J
avaProxy
CacheEntry
,
public
::
textsort
::
TextboxListener
{
public:
JavaProxy
(
jobject
obj
);
virtual
void
update
(
const
::
textsort
::
ItemList
&
items
)
override
;
private:
using
djinni
::
J
niWrapper
CacheEntry
::
getGlobalRef
;
using
djinni
::
J
avaProxy
CacheEntry
::
getGlobalRef
;
friend
class
djinni
::
JniInterfaceJavaExt
<::
textsort
::
TextboxListener
,
NativeTextboxListener
>
;
friend
class
djinni
::
J
niWrapper
Cache
<
JavaProxy
>
;
friend
class
djinni
::
J
avaProxy
Cache
<
JavaProxy
>
;
};
private:
...
...
src/source/JNIGenerator.scala
View file @
ed6ef3c5
...
...
@@ -210,7 +210,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
}
if
(
i
.
ext
.
java
)
{
w
.
wl
w
.
w
(
s
"class JavaProxy final : djinni::J
niWrapper
CacheEntry, public ${withNs(spec.cppNamespace, idCpp.ty(ident))}"
).
bracedSemi
{
w
.
w
(
s
"class JavaProxy final : djinni::J
avaProxy
CacheEntry, public ${withNs(spec.cppNamespace, idCpp.ty(ident))}"
).
bracedSemi
{
w
.
wlOutdent
(
s
"public:"
)
w
.
wl
(
s
"JavaProxy(jobject obj);"
)
for
(
m
<-
i
.
methods
)
{
...
...
@@ -220,9 +220,9 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
}
w
.
wl
w
.
wlOutdent
(
s
"private:"
)
w
.
wl
(
s
"using djinni::J
niWrapper
CacheEntry::getGlobalRef;"
)
w
.
wl
(
s
"using djinni::J
avaProxy
CacheEntry::getGlobalRef;"
)
w
.
wl
(
s
"friend class djinni::JniInterfaceJavaExt<$selfQ, $jniClassName>;"
)
w
.
wl
(
s
"friend class djinni::J
niWrapper
Cache<JavaProxy>;"
)
w
.
wl
(
s
"friend class djinni::J
avaProxy
Cache<JavaProxy>;"
)
}
}
w
.
wl
...
...
@@ -239,7 +239,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
w
.
wl
if
(
i
.
ext
.
java
)
{
writeJniTypeParams
(
w
,
typeParams
)
w
.
wl
(
s
"$jniClassName::JavaProxy::JavaProxy(jobject obj) : J
niWrapper
CacheEntry(obj) {}"
)
w
.
wl
(
s
"$jniClassName::JavaProxy::JavaProxy(jobject obj) : J
avaProxy
CacheEntry(obj) {}"
)
for
(
m
<-
i
.
methods
)
{
w
.
wl
...
...
support-lib/jni/djinni_support.cpp
View file @
ed6ef3c5
...
...
@@ -417,33 +417,33 @@ void jniSetPendingFromCurrent(JNIEnv * env, const char * /*ctx*/) noexcept {
}
}
struct
J
niWrapper
CacheState
{
struct
J
avaProxy
CacheState
{
std
::
mutex
mtx
;
std
::
unordered_map
<
jobject
,
std
::
weak_ptr
<
void
>
,
JavaIdentityHash
,
JavaIdentityEquals
>
m
;
int
counter
=
0
;
static
J
niWrapper
CacheState
&
get
()
{
static
J
niWrapper
CacheState
st
;
static
J
avaProxy
CacheState
&
get
()
{
static
J
avaProxy
CacheState
st
;
return
st
;
}
};
J
niWrapperCacheEntry
::
JniWrapper
CacheEntry
(
jobject
localRef
,
JNIEnv
*
env
)
J
avaProxyCacheEntry
::
JavaProxy
CacheEntry
(
jobject
localRef
,
JNIEnv
*
env
)
:
m_globalRef
(
env
,
localRef
)
{
DJINNI_ASSERT
(
m_globalRef
,
env
);
}
J
niWrapperCacheEntry
::
JniWrapper
CacheEntry
(
jobject
localRef
)
:
J
niWrapper
CacheEntry
(
localRef
,
jniGetThreadEnv
())
{}
J
avaProxyCacheEntry
::
JavaProxy
CacheEntry
(
jobject
localRef
)
:
J
avaProxy
CacheEntry
(
localRef
,
jniGetThreadEnv
())
{}
J
niWrapperCacheEntry
::~
JniWrapper
CacheEntry
()
noexcept
{
J
niWrapperCacheState
&
st
=
JniWrapper
CacheState
::
get
();
J
avaProxyCacheEntry
::~
JavaProxy
CacheEntry
()
noexcept
{
J
avaProxyCacheState
&
st
=
JavaProxy
CacheState
::
get
();
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
st
.
mtx
);
st
.
m
.
erase
(
m_globalRef
.
get
());
}
std
::
shared_ptr
<
void
>
j
niWrapper
CacheLookup
(
jobject
obj
,
std
::
pair
<
std
::
shared_ptr
<
void
>
,
jobject
>
(
*
factory
)(
jobject
))
{
J
niWrapperCacheState
&
st
=
JniWrapper
CacheState
::
get
();
std
::
shared_ptr
<
void
>
j
avaProxy
CacheLookup
(
jobject
obj
,
std
::
pair
<
std
::
shared_ptr
<
void
>
,
jobject
>
(
*
factory
)(
jobject
))
{
J
avaProxyCacheState
&
st
=
JavaProxy
CacheState
::
get
();
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
st
.
mtx
);
const
auto
it
=
st
.
m
.
find
(
obj
);
...
...
support-lib/jni/djinni_support.hpp
View file @
ed6ef3c5
...
...
@@ -202,7 +202,7 @@ jfieldID jniGetFieldID(jclass clazz, const char * name, const char * sig);
*
* This is used for automatically wrapping a Java object that exposes some interface
* with a C++ object that calls back into the JVM, such as a listener. Calling
* J
niWrapper
Cache<T>::get(jobj, ...) the first time will construct a T and return a
* J
avaProxy
Cache<T>::get(jobj, ...) the first time will construct a T and return a
* shared_ptr to it, and also save a weak_ptr to the new object internally. The constructed
* T contains a strong GlobalRef to jobj. As long as something in C++ maintains a strong
* reference to the wrapper, future calls to get(jobj) will return the *same* wrapper object.
...
...
@@ -212,11 +212,11 @@ jfieldID jniGetFieldID(jclass clazz, const char * name, const char * sig);
* _____________ | | | | |
* | | | | JniImplFooListener | <=========== | Foo |
* | FooListener | <============ | : public FooListener, | shared_ptr |___________|
* |_____________| GlobalRef |
JniWrapperCacheEntry
|
* |_____________| GlobalRef |
JavaProxyCacheEntry
|
* | |________________________|
* | ^ ______________________
* | \ | |
* | - - - - - - |
JniWrapper
Cache |
* | - - - - - - |
JavaProxy
Cache |
* | weak_ptr | <JniImplFooListener> |
* | |______________________|
*
...
...
@@ -238,32 +238,32 @@ jfieldID jniGetFieldID(jclass clazz, const char * name, const char * sig);
* a shared_ptr to the object (JniImplFooListener, in the diagram above), as well as the
* jobject *global* ref contained inside.
*/
std
::
shared_ptr
<
void
>
j
niWrapper
CacheLookup
(
jobject
obj
,
std
::
pair
<
std
::
shared_ptr
<
void
>
,
std
::
shared_ptr
<
void
>
j
avaProxy
CacheLookup
(
jobject
obj
,
std
::
pair
<
std
::
shared_ptr
<
void
>
,
jobject
>
(
*
factory
)(
jobject
));
class
J
niWrapper
CacheEntry
{
class
J
avaProxy
CacheEntry
{
public:
jobject
getGlobalRef
()
{
return
m_globalRef
.
get
();
}
protected:
J
niWrapper
CacheEntry
(
jobject
localRef
,
JNIEnv
*
env
);
// env used only for construction
J
niWrapper
CacheEntry
(
jobject
localRef
);
J
avaProxy
CacheEntry
(
jobject
localRef
,
JNIEnv
*
env
);
// env used only for construction
J
avaProxy
CacheEntry
(
jobject
localRef
);
virtual
~
J
niWrapper
CacheEntry
()
noexcept
;
virtual
~
J
avaProxy
CacheEntry
()
noexcept
;
J
niWrapperCacheEntry
(
const
JniWrapper
CacheEntry
&
other
)
=
delete
;
J
niWrapperCacheEntry
&
operator
=
(
const
JniWrapper
CacheEntry
&
other
)
=
delete
;
J
avaProxyCacheEntry
(
const
JavaProxy
CacheEntry
&
other
)
=
delete
;
J
avaProxyCacheEntry
&
operator
=
(
const
JavaProxy
CacheEntry
&
other
)
=
delete
;
private:
const
GlobalRef
<
jobject
>
m_globalRef
;
};
template
<
class
T
>
class
J
niWrapper
Cache
{
class
J
avaProxy
Cache
{
public:
using
Entry
=
J
niWrapper
CacheEntry
;
using
Entry
=
J
avaProxy
CacheEntry
;
static
std
::
pair
<
std
::
shared_ptr
<
void
>
,
jobject
>
factory
(
jobject
obj
)
{
std
::
shared_ptr
<
T
>
ret
=
std
::
make_shared
<
T
>
(
obj
);
...
...
@@ -275,10 +275,10 @@ public:
* construct a new one with obj, save it, and return it.
*/
static
std
::
shared_ptr
<
T
>
get
(
jobject
obj
)
{
static_assert
(
std
::
is_base_of
<
J
niWrapper
CacheEntry
,
T
>::
value
,
"J
niWrapper
Cache can only be used with T if T derives from Entry<T>"
);
static_assert
(
std
::
is_base_of
<
J
avaProxy
CacheEntry
,
T
>::
value
,
"J
avaProxy
Cache can only be used with T if T derives from Entry<T>"
);
return
std
::
static_pointer_cast
<
T
>
(
j
niWrapper
CacheLookup
(
obj
,
&
factory
));
return
std
::
static_pointer_cast
<
T
>
(
j
avaProxy
CacheLookup
(
obj
,
&
factory
));
}
};
...
...
@@ -324,7 +324,7 @@ public:
if
(
j
==
0
)
{
return
nullptr
;
}
return
J
niWrapper
Cache
<
typename
Self
::
JavaProxy
>::
get
(
j
);
return
J
avaProxy
Cache
<
typename
Self
::
JavaProxy
>::
get
(
j
);
}
};
...
...
test-suite/generated-src/jni/NativeClientInterface.cpp
View file @
ed6ef3c5
...
...
@@ -9,7 +9,7 @@ namespace djinni_generated {
NativeClientInterface
::
NativeClientInterface
()
:
djinni
::
JniInterfaceJavaExt
<
ClientInterface
,
NativeClientInterface
>
()
{}
NativeClientInterface
::
JavaProxy
::
JavaProxy
(
jobject
obj
)
:
J
niWrapper
CacheEntry
(
obj
)
{}
NativeClientInterface
::
JavaProxy
::
JavaProxy
(
jobject
obj
)
:
J
avaProxy
CacheEntry
(
obj
)
{}
ClientReturnedRecord
NativeClientInterface
::
JavaProxy
::
JavaProxy
::
get_record
(
const
std
::
string
&
c_utf8string
)
{
JNIEnv
*
const
jniEnv
=
djinni
::
jniGetThreadEnv
();
...
...
test-suite/generated-src/jni/NativeClientInterface.hpp
View file @
ed6ef3c5
...
...
@@ -18,15 +18,15 @@ public:
const
djinni
::
GlobalRef
<
jclass
>
clazz
{
djinni
::
jniFindClass
(
"com/dropbox/djinni/test/ClientInterface"
)
};
const
jmethodID
method_getRecord
{
djinni
::
jniGetMethodID
(
clazz
.
get
(),
"getRecord"
,
"(Ljava/lang/String;)Lcom/dropbox/djinni/test/ClientReturnedRecord;"
)
};
class
JavaProxy
final
:
djinni
::
J
niWrapper
CacheEntry
,
public
ClientInterface
{
class
JavaProxy
final
:
djinni
::
J
avaProxy
CacheEntry
,
public
ClientInterface
{
public:
JavaProxy
(
jobject
obj
);
virtual
ClientReturnedRecord
get_record
(
const
std
::
string
&
utf8string
)
override
;
private:
using
djinni
::
J
niWrapper
CacheEntry
::
getGlobalRef
;
using
djinni
::
J
avaProxy
CacheEntry
::
getGlobalRef
;
friend
class
djinni
::
JniInterfaceJavaExt
<
ClientInterface
,
NativeClientInterface
>
;
friend
class
djinni
::
J
niWrapper
Cache
<
JavaProxy
>
;
friend
class
djinni
::
J
avaProxy
Cache
<
JavaProxy
>
;
};
private:
...
...
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