Android implementation for RunHTTPRequest() with C++ and Java unit tests.

... 
Right, so either a parameter or a lambda do the trick, right?
On Dec 12, 2014 9:33 PM, "Alex Zolotarev" <notifications@github.com> wrote:

> In src/platform/android/src/main/jni/jni_wrapper.cc
> <https://github.com/KnowSheet/AlohaStatsClient/pull/9#discussion-diff-21786672>
> :
>
> > +bool HTTPClientPlatformWrapper::RunHTTPRequest() {
> > +  // Attaching multiple times from the same thread is a no-op, which only gets good env for us.
> > +  JNIEnv* env;
> > +  if (JNI_OK != ::GetJVM()->AttachCurrentThread(PLATFORM_SPECIFIC_CAST & env, nullptr)) {
> > +    // TODO(AlexZ): throw some critical exception.
> > +    return false;
> > +  }
> > +
> > +  // TODO(AlexZ): May need to refactor if this method will be agressively used from the same thread.
> > +  const auto detachThreadOnScopeExit = bricks::MakeScopeGuard([] { ::GetJVM()->DetachCurrentThread(); });
> > +
> > +  // Convenience lambda.
> > +  const auto deleteLocalRef = [&env](jobject o) { env->DeleteLocalRef(o); };
> > +
> > +  // Create and fill request params.
> > +  const auto jniUrl = MakePointerScopeGuard(env->NewStringUTF(url_requested_.c_str()), deleteLocalRef);
>
> It's not as simple, variables should be freed only after they have been
> passed to Java or on this big function exit, not earlier.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/KnowSheet/AlohaStatsClient/pull/9/files#r21786672>.
>