}
if (inst->authenticator->GetHandle() >= 0) {
- inst->looper = ALooper_forThread();
- if (inst->looper == nullptr) {
- ErrPrint("There is no android looper found");
- delete inst;
- inst = nullptr;
- break;
- }
-
- ALooper_acquire(inst->looper);
-
- int ret = ALooper_addFd(inst->looper,
- inst->authenticator->GetHandle(),
- ALOOPER_POLL_CALLBACK,
- ALOOPER_EVENT_INPUT,
- static_cast<ALooper_callbackFunc>(Authenticator_eventHandler),
- static_cast<void *>(inst));
+ int ret = inst->AttachEventLoop();
if (ret < 0) {
- ErrPrint("Failed to add event handler");
delete inst;
inst = nullptr;
break;
- } // otherwise, the ret is 1 if succeed
+ }
} else {
DbgPrint("Authenticator module does not support asynchronous mode");
}
return reinterpret_cast<long>(inst);
}
+int AuthenticatorNativeInterface::AttachEventLoop(void)
+{
+ looper = ALooper_forThread();
+ if (looper == nullptr) {
+ ErrPrint("There is no android looper found");
+ return -ENOTSUP;
+ }
+
+ ALooper_acquire(looper);
+
+ int ret = ALooper_addFd(looper,
+ authenticator->GetHandle(),
+ ALOOPER_POLL_CALLBACK,
+ ALOOPER_EVENT_INPUT,
+ static_cast<ALooper_callbackFunc>(Authenticator_eventHandler),
+ static_cast<void *>(this));
+ if (ret < 0) {
+ ErrPrint("Failed to add event handler");
+ } // otherwise, the ret is 1 if succeed
+
+ return ret;
+}
+
int AuthenticatorNativeInterface::Java_com_samsung_android_beyond_Authenticator_configure(JNIEnv *env, jobject thiz, jlong _inst, jchar type, jlong objInst)
{
AuthenticatorNativeInterface *inst = reinterpret_cast<AuthenticatorNativeInterface *>(_inst);
private:
int InvokeEventListener(JNIEnv *env, jobject thiz, int eventType, void *eventData);
+ int AttachEventLoop(void);
private:
beyond::Authenticator *authenticator;
}
if (inst->discovery->GetHandle() >= 0) {
- inst->looper = ALooper_forThread();
- if (inst->looper == nullptr) {
- ErrPrint("There is no android looper found");
- delete inst;
- inst = nullptr;
- break;
- }
-
- ALooper_acquire(inst->looper);
-
- int ret = ALooper_addFd(inst->looper,
- inst->discovery->GetHandle(),
- ALOOPER_POLL_CALLBACK,
- ALOOPER_EVENT_INPUT,
- static_cast<ALooper_callbackFunc>(Discovery_eventHandler),
- static_cast<void *>(inst));
+ int ret = inst->AttachEventLoop();
if (ret < 0) {
- ErrPrint("Failed to add event handler");
delete inst;
inst = nullptr;
break;
- } // otherwise, the ret is 1 if succeed
+ }
}
} while (0);
return reinterpret_cast<jlong>(inst);
}
+int DiscoveryNativeInterface::AttachEventLoop(void)
+{
+ looper = ALooper_forThread();
+ if (looper == nullptr) {
+ ErrPrint("There is no android looper found");
+ return -ENOTSUP;
+ }
+
+ ALooper_acquire(looper);
+
+ int ret = ALooper_addFd(looper,
+ discovery->GetHandle(),
+ ALOOPER_POLL_CALLBACK,
+ ALOOPER_EVENT_INPUT,
+ static_cast<ALooper_callbackFunc>(Discovery_eventHandler),
+ static_cast<void *>(this));
+ if (ret < 0) {
+ ErrPrint("Failed to add event handler");
+ } // otherwise, the ret is 1 if succeed
+
+ return ret;
+}
+
void DiscoveryNativeInterface::Java_com_samsung_android_beyond_discovery_Discovery_destroy(JNIEnv *env, jclass klass, jlong instance)
{
if (instance == 0) {
private:
int InvokeEventListener(JNIEnv *env, jobject thiz, int eventType, void *eventData);
+ int AttachEventLoop(void);
private:
beyond::Discovery *discovery;