aboutsummaryrefslogtreecommitdiffstats
path: root/src/native
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2012-07-12 11:12:09 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2012-07-12 11:12:09 +0000
commit4dfd16a63faf44b8e6f21ca6600b387d56e8e67f (patch)
treeedcd12d674bcd2aa12fd161bad12b309205ee2de /src/native
parentdd3b5f120a3b99fba694674468fc0296e74685ea (diff)
downloadjitsi-4dfd16a63faf44b8e6f21ca6600b387d56e8e67f.zip
jitsi-4dfd16a63faf44b8e6f21ca6600b387d56e8e67f.tar.gz
jitsi-4dfd16a63faf44b8e6f21ca6600b387d56e8e67f.tar.bz2
Commits work in progress on calling from Microsoft Office with Jitsi to phone numbers originating from Microsoft Office.
Diffstat (limited to 'src/native')
-rw-r--r--src/native/windows/msofficecomm/Messenger.cxx222
-rw-r--r--src/native/windows/msofficecomm/Messenger.h2
2 files changed, 135 insertions, 89 deletions
diff --git a/src/native/windows/msofficecomm/Messenger.cxx b/src/native/windows/msofficecomm/Messenger.cxx
index 41f42ba..a24eb49 100644
--- a/src/native/windows/msofficecomm/Messenger.cxx
+++ b/src/native/windows/msofficecomm/Messenger.cxx
@@ -705,7 +705,7 @@ HRESULT Messenger::start(JNIEnv *env)
= env->GetMethodID(
clazz,
"startConversation",
- "(I[Ljava/lang/String;)V");
+ "(I[Ljava/lang/String;Ljava/lang/String;)V");
if (startConversationMethodID)
{
@@ -744,11 +744,119 @@ Messenger::StartConversation
VARIANT vConversationData,
VARIANT *pvWndHnd)
{
+ JavaVM *vm = OutOfProcessServer::getJavaVM();
+ JNIEnv *env;
+ HRESULT hr;
+
+ if (vm && !(vm->AttachCurrentThreadAsDaemon((void **) &env, NULL)))
+ {
+ jobjectArray participants;
+
+ hr = toStringArray(env, vParticipants, &participants);
+ if (SUCCEEDED(hr))
+ {
+ jstring conversationData;
+
+ hr = toString(env, vConversationData, &conversationData);
+ /*
+ * The MSDN is pretty scarce on the subject of vConversationData
+ * thus we can hardly rely on getting it right.
+ */
+ if (hr == E_INVALIDARG)
+ {
+ conversationData = NULL;
+ hr = S_OK;
+ }
+ if (SUCCEEDED(hr))
+ {
+ if (_jobject)
+ {
+ env->CallVoidMethod(
+ _jobject,
+ _jstartConversationMethodID,
+ (jint) ConversationType,
+ participants,
+ conversationData);
+ }
+ else
+ hr = E_FAIL;
+ }
+ }
+ if (env->ExceptionCheck())
+ {
+ env->ExceptionClear();
+ hr = E_FAIL;
+ }
+ }
+ else
+ hr = E_UNEXPECTED;
+ return hr;
+}
+
+STDMETHODIMP Messenger::StartVideo(VARIANT vContact, IDispatch **ppMWindow)
+ STDMETHODIMP_E_NOTIMPL_STUB
+
+STDMETHODIMP Messenger::StartVoice(VARIANT vContact, IDispatch **ppMWindow)
+ STDMETHODIMP_E_NOTIMPL_STUB
+
+HRESULT Messenger::stop(JNIEnv *env)
+{
+ jclass clazz = _jclass;
+
+ _jclass = NULL;
+ _jctorMethodID = NULL;
+ _jstartConversationMethodID = NULL;
+ if (clazz)
+ env->DeleteGlobalRef(clazz);
+
+ return S_OK;
+}
+
+HRESULT Messenger::toString(JNIEnv *env, VARIANT &v, jstring *string)
+{
+ BSTR bstr;
HRESULT hr;
- if (VT_ARRAY == (vParticipants.vt & VT_ARRAY))
+ if (VT_BSTR == v.vt)
{
- SAFEARRAY *sa = vParticipants.parray;
+ bstr = v.bstrVal;
+ hr = S_OK;
+ }
+ else if ((VT_BSTR | VT_BYREF) == v.vt)
+ {
+ bstr = *(v.pbstrVal);
+ hr = S_OK;
+ }
+ else
+ hr = E_INVALIDARG;
+
+ if (SUCCEEDED(hr))
+ {
+ if (bstr)
+ {
+ jstring _string
+ = env->NewString((const jchar *) bstr, ::SysStringLen(bstr));
+
+ if (_string)
+ *string = _string;
+ else
+ hr = E_OUTOFMEMORY;
+ }
+ else
+ *string = NULL;
+ }
+
+ return hr;
+}
+
+HRESULT
+Messenger::toStringArray(JNIEnv *env, VARIANT &v, jobjectArray *stringArray)
+{
+ HRESULT hr;
+
+ if (VT_ARRAY == (v.vt & VT_ARRAY))
+ {
+ SAFEARRAY *sa = v.parray;
if (sa
&& (1 == sa->cDims)
@@ -759,86 +867,41 @@ Messenger::StartConversation
hr = ::SafeArrayAccessData(sa, (PVOID *) &data);
if (SUCCEEDED(hr))
{
- JavaVM *vm = OutOfProcessServer::getJavaVM();
- JNIEnv *env;
+ jclass stringClass = env->FindClass("java/lang/String");
- if (vm
- && !(vm->AttachCurrentThreadAsDaemon(
- (void **) &env,
- NULL)))
+ if (stringClass)
{
- jclass stringClass = env->FindClass("java/lang/String");
+ SAFEARRAYBOUND *bound = sa->rgsabound;
+ ULONG length = bound->cElements;
+ jobjectArray _stringArray
+ = env->NewObjectArray(length, stringClass, NULL);
- if (stringClass)
+ if (_stringArray)
{
- SAFEARRAYBOUND *bound = sa->rgsabound;
- ULONG length = bound->cElements;
- jobjectArray participants
- = env->NewObjectArray(length, stringClass, NULL);
+ ULONG elemsize = sa->cbElements;
- if (participants)
+ data += bound->lLbound;
+ for (ULONG i = 0; i < length; i++, data += elemsize)
{
- ULONG elemsize = sa->cbElements;
-
- data += bound->lLbound;
- for (ULONG i = 0; i < length; i++, data += elemsize)
- {
- VARIANT *v = (VARIANT *) data;
- BSTR bstr;
-
- if (VT_BSTR == v->vt)
- bstr = v->bstrVal;
- else if ((VT_BSTR | VT_BYREF) == v->vt)
- bstr = *(v->pbstrVal);
- else
- {
- hr = E_INVALIDARG;
- break;
- }
-
- jstring participant
- = env->NewString(
- (const jchar *) bstr,
- ::SysStringLen(bstr));
-
- if (participant)
- {
- env->SetObjectArrayElement(
- participants,
- i,
- participant);
- }
- else
- {
- hr = E_OUTOFMEMORY;
- break;
- }
- }
+ jstring _string;
+ hr = toString(env, *((VARIANT *) data), &_string);
if (SUCCEEDED(hr))
{
- if (_jobject)
- {
- env->CallVoidMethod(
- _jobject,
- _jstartConversationMethodID,
- (jint) ConversationType,
- participants);
- if (env->ExceptionCheck())
- {
- env->ExceptionClear();
- hr = E_FAIL;
- }
- }
- else
- hr = E_FAIL;
+ env->SetObjectArrayElement(
+ _stringArray,
+ i,
+ _string);
}
+ else
+ break;
}
- else
- hr = E_OUTOFMEMORY;
+
+ if (SUCCEEDED(hr))
+ *stringArray = _stringArray;
}
else
- hr = E_UNEXPECTED;
+ hr = E_OUTOFMEMORY;
}
else
hr = E_UNEXPECTED;
@@ -853,24 +916,5 @@ Messenger::StartConversation
return hr;
}
-STDMETHODIMP Messenger::StartVideo(VARIANT vContact, IDispatch **ppMWindow)
- STDMETHODIMP_E_NOTIMPL_STUB
-
-STDMETHODIMP Messenger::StartVoice(VARIANT vContact, IDispatch **ppMWindow)
- STDMETHODIMP_E_NOTIMPL_STUB
-
-HRESULT Messenger::stop(JNIEnv *env)
-{
- jclass clazz = _jclass;
-
- _jclass = NULL;
- _jctorMethodID = NULL;
- _jstartConversationMethodID = NULL;
- if (clazz)
- env->DeleteGlobalRef(clazz);
-
- return S_OK;
-}
-
STDMETHODIMP Messenger::ViewProfile(VARIANT vContact)
STDMETHODIMP_E_NOTIMPL_STUB
diff --git a/src/native/windows/msofficecomm/Messenger.h b/src/native/windows/msofficecomm/Messenger.h
index 7a8051c..5eca3e8 100644
--- a/src/native/windows/msofficecomm/Messenger.h
+++ b/src/native/windows/msofficecomm/Messenger.h
@@ -113,6 +113,8 @@ private:
HRESULT createMessengerContact(BSTR signinName, REFIID iid, PVOID *obj);
HRESULT destructJobject();
HRESULT getMessengerContact(BSTR signinName, REFIID iid, PVOID *obj);
+ HRESULT toString(JNIEnv *env, VARIANT &v, jstring *string);
+ HRESULT toStringArray(JNIEnv *env, VARIANT &v, jobjectArray *stringArray);
DMessengerEventsConnectionPoint *_dMessengerEventsConnectionPoint;
jobject _jobject;