LINEDEVCAPS *tapi_getdevcaps(uint dev) { LINEDEVCAPS *pcaps=NULL; LONG retval, size; DWORD apiver; size = sizeof(LINEDEVCAPS) + 256; while (1) { LINEEXTENSIONID extid; retval = lineNegotiateAPIVersion(TapiObj.hObj, dev, TAPI_VERSION, TAPI_VERSION, &apiver, &extid); if (retval != 0) return NULL; pcaps = (LINEDEVCAPS *)realloc(pcaps, size); if (!pcaps) return NULL; memset(pcaps, 0, size); pcaps->dwTotalSize = size; retval = lineGetDevCaps(TapiObj.hObj, dev, apiver, 0, pcaps); if (retval!=0) { free(pcaps); return NULL; } if (pcaps->dwNeededSize > pcaps->dwTotalSize) { size = pcaps->dwNeededSize; continue; } else break; } return pcaps; }
JNIEXPORT jint JNICALL Java_net_xtapi_serviceProvider_MSTAPI_openLine (JNIEnv *pEnv, jobject oObj, jint lLine, jobject oTerminalName) { long lRc; DWORD lNegVer; char szDebug[256]; long lUnused = 0; long sizeBuffer; HLINE hLine; LINEEXTENSIONID lpExtensionID; LPLINEDEVCAPS lpLineDevCaps = NULL; lRc = lineNegotiateAPIVersion(g_hTAPI, lLine, TAPIVERSION, TAPIVERSION, &lNegVer, &lpExtensionID); if(TAPIVERSION == lNegVer) { wsprintf(szDebug,"Negotiated TAPI 1.4 on line %d.",lLine); debugString(8,"openLine",szDebug,_where()); } else { wsprintf(szDebug,"Failed to Negotiate TAPI 1.4 on line %d.",lLine); debugString(4,"openLine",szDebug,_where()); return -1; } lRc = lineOpen(g_hTAPI, lLine, &hLine, lNegVer, lUnused, lLine, LINECALLPRIVILEGE_OWNER, LINEMEDIAMODE_AUTOMATEDVOICE, 0); wsprintf(szDebug,"lineOpen on line %d returned with %d",lLine, lRc); if(lRc < 0) { debugString(4,"openLine",szDebug,_where()); return lRc; } else debugString(8,"openLine",szDebug,_where()); sizeBuffer = sizeof(lpLineDevCaps) + 1024; lpLineDevCaps = (LINEDEVCAPS *) malloc(sizeBuffer); memset(lpLineDevCaps, 0, sizeBuffer); lpLineDevCaps->dwTotalSize = sizeBuffer; lRc = lineGetDevCaps(g_hTAPI, lLine, lNegVer, 0, lpLineDevCaps); wsprintf(szDebug,"lineGetDevCaps returned -> %d",lRc); debugString(8,"openLine",szDebug,_where()); if(0 == lRc) { if(lpLineDevCaps->dwLineNameSize > 0) { // lpLineDevCaps holds the name of the terminal, push that name up // to Java. long lpName = (long)lpLineDevCaps + lpLineDevCaps->dwLineNameOffset; jstring oName = pEnv->NewStringUTF((const char *)lpName); jclass cls; jmethodID mid; cls = pEnv->GetObjectClass (oTerminalName); mid = pEnv->GetMethodID(cls,"append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;"); pEnv->CallObjectMethod (oTerminalName, mid, oName); } lRc = lineSetStatusMessages(hLine,lpLineDevCaps->dwLineStates,0); if(lRc != 0) { debugString(4,"openLine","lineSetStatusMessages failed",_where()); hLine = (HLINE)-1; } } free(lpLineDevCaps); return (long)hLine; }