connectivity/com.nokia.tcf/native/TCFNative/TCFClient/TCAPIConnectionJni.cpp
author chpeckha
Mon, 06 Apr 2009 15:18:48 -0500
changeset 60 9d2210c8eed2
child 914 46f36a149510
permissions -rw-r--r--
Commit changes for 2.1.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     1
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     3
* All rights reserved.
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     4
* This component and the accompanying materials are made available
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     6
* which accompanies this distribution, and is available
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     8
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     9
* Initial Contributors:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    11
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    12
* Contributors:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    13
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    14
* Description: 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    15
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    16
*/
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    17
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    18
#include "stdafx.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    19
#include "TCAPIConnectionJni.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    20
#include "TCConstants.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    21
#include "TCErrorConstants.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    22
#include "ClientManager.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    23
#include "ServerClient.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    24
#include "TCDebugLog.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    25
#include "InputStream.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    26
#include "ErrorMonitorData.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    27
#include <list>
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    28
#include <vector>
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    29
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    30
extern CClientManager* gManager;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    31
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    32
#ifdef _DEBUG
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    33
extern BOOL gDoLogging;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    34
char TCDebugMsg[100];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    35
#define TCDEBUGOPEN() if (gDoLogging) { gManager->m_DebugLog->WaitForAccess(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    36
#define TCDEBUGLOGS(s) if (gDoLogging) { sprintf(TCDebugMsg,"%s", s); gManager->m_DebugLog->log(TCDebugMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    37
#define TCDEBUGLOGA1(s, a1) if (gDoLogging) { sprintf(TCDebugMsg, s, a1); gManager->m_DebugLog->log(TCDebugMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    38
#define TCDEBUGLOGA2(s, a1, a2) if (gDoLogging) { sprintf(TCDebugMsg, s, a1, a2); gManager->m_DebugLog->log(TCDebugMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    39
#define TCDEBUGLOGA3(s, a1, a2, a3) if (gDoLogging) { sprintf(TCDebugMsg, s, a1, a2, a3); gManager->m_DebugLog->log(TCDebugMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    40
#define TCDEBUGCLOSE() if (gDoLogging) { gManager->m_DebugLog->ReleaseAccess(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    41
#else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    42
#define TCDEBUGOPEN()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    43
#define TCDEBUGLOGS(s)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    44
#define TCDEBUGLOGA1(s, a1)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    45
#define TCDEBUGLOGA2(s, a1, a2)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    46
#define TCDEBUGLOGA3(s, a1, a2, a3)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    47
#define TCDEBUGCLOSE()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    48
#endif
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    49
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    50
#ifdef _DEBUG
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    51
FILE* fLog1 = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    52
FILE* fLog2 = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    53
static void OpenLogFile1(char* filename);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    54
static void CloseLogFile1();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    55
static void OpenLogFile2(char* filename);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    56
static void CloseLogFile2();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    57
#define OPENLOGf1(f) OpenLogFile1(f)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    58
#define CLOSELOG1() CloseLogFile1()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    59
#define OPENLOGf2(f) OpenLogFile2(f)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    60
#define CLOSELOG2() CloseLogFile2()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    61
#else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    62
#define OPENLOGf1(f)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    63
#define CLOSELOG1()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    64
#endif
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    65
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    66
static void ConvertRealSerialSettingsToHost(char* pBaud, char* pDataBits, char* pParity, char* pStopBits, char* pFlowControl, pRealSerialConnectData pData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    67
static void ConvertRealSerialSettingsToServer(const char* pBaud, const char* pDataBits, const char* pParity, const char* pStopBits, const char* pFlowControl, pRealSerialConnectData pData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    68
static const char* GetErrorText(unsigned long error);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    69
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    70
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    71
 * Method:    nativeConnect
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    72
 * Signature: (Ljava/lang/String;[J[Ljava/lang/String;[JLjava/lang/String;[J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    73
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    74
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeConnect
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    75
  (JNIEnv *env, jobject pThis, jstring inType, jlongArray inOptions, jobjectArray inSettings, jlongArray inMessageOptions, jstring inFilePath, jlongArray outClientId)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    76
 {
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    77
 	// inOptions are connection options
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    78
 	// inMessageOptions are client's message options
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    79
	// inFilePath will be null if message destination is not DESTINATION_CLIENTFILE 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    80
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    81
	unsigned long osError = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    82
	long clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    83
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    84
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    85
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    86
	TCDEBUGLOGS("nativeConnect\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    87
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    88
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    89
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    90
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    91
		jboolean isCopy = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    92
		// options per connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    93
		jlong* pOptions = env->GetLongArrayElements(inOptions, &isCopy);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    94
		DWORD retryInterval = (DWORD)pOptions[0];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    95
		DWORD retryTimeout = (DWORD)pOptions[1];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    96
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    97
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    98
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    99
		env->ReleaseLongArrayElements(inOptions, pOptions, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   100
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   101
		pOptions = env->GetLongArrayElements(inMessageOptions, &isCopy);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   102
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   103
		// options per client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   104
		long unWrapFormat = pOptions[0];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   105
		long ostVersion = pOptions[1];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   106
		env->ReleaseLongArrayElements(inMessageOptions, pOptions, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   107
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   108
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   109
		TCDEBUGLOGA2(" retryInterval=%d, retryTimeout=%d\n", retryInterval, retryTimeout);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   110
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   111
		TCDEBUGLOGA3(" unWrapFormat=%d, ostVersion=%d destination=%s\n", unWrapFormat, ostVersion, ((inFilePath == NULL) ? "stream" : "file"));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   112
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   113
		char* pType = (char*)env->GetStringUTFChars(inType, &isCopy);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   114
		TCDEBUGLOGA1("  pType = %s\n", pType);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   115
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   116
		if (strcmp(pType, "musti") == 0 || strcmp(pType, "platsim") == 0) 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   117
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   118
			jstring addString = (jstring)env->GetObjectArrayElement(inSettings, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   119
			jstring portString = (jstring)env->GetObjectArrayElement(inSettings, 1);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   120
			jstring chanString = (jstring)env->GetObjectArrayElement(inSettings, 2);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   121
			jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 3);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   122
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   123
			const char* pAddress = env->GetStringUTFChars(addString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   124
			const char* pPort = env->GetStringUTFChars(portString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   125
			const char* pChan = env->GetStringUTFChars(chanString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   126
			const char* pDecode = env->GetStringUTFChars(decodeString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   127
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   128
			TCDEBUGLOGA2(" TCP: ipAddress=%s, ipPort=%s\n", pAddress, pPort);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   129
			TCDEBUGLOGA2(" TCP: channel=%s, decode=%s\n", pChan, pDecode);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   130
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   131
			ServerCommandData cmd;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   132
			cmd.command = eCmdConnect;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   133
			strncpy(cmd.connectSettings.connectType, pType, MAX_CONNECTION_TYPE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   134
			strncpy(cmd.connectSettings.tcpSettings.ipAddress, pAddress, MAX_IPADDRESS_SIZE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   135
			strncpy(cmd.connectSettings.tcpSettings.ipPort, pPort, MAX_PORT_SIZE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   136
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   137
			cmd.connectSettings.retryInterval = retryInterval;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   138
			cmd.connectSettings.retryTimeout = retryTimeout;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   139
			strncpy(cmd.connectSettings.decodeFormat, pDecode, MAX_DECODE_FORMAT);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   140
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   141
			if (pChan != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   142
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   143
				if (strcmp(pChan, "1") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   144
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   145
					cmd.connectSettings.traceBoxChannel = 1;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   146
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   147
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   148
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   149
					cmd.connectSettings.traceBoxChannel = 2;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   150
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   151
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   152
			else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   153
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   154
				cmd.connectSettings.traceBoxChannel = 2;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   155
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   156
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   157
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   158
			cmd.clientOptions.unWrapFormat = unWrapFormat;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   159
			cmd.clientOptions.ostVersion = ostVersion;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   160
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   161
			gManager->m_Server->SendCommand(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   162
			gManager->m_Server->GetResponse(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   163
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   164
			if (cmd.response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   165
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   166
				TCDEBUGLOGA1("  from server: ret = %d\n", cmd.error);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   167
				ret = cmd.error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   168
				osError = cmd.osError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   169
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   170
			else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   171
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   172
				TCDEBUGLOGA1("  from server: id = %d\n", cmd.clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   173
				clientId = cmd.clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   174
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   175
				gManager->WaitForErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   176
				TCDEBUGLOGS(" TODO: create error monitor storage if server connected\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   177
				CErrorMonitor* monitor = new CErrorMonitor(clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   178
				if (monitor != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   179
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   180
					monitor->CreateData();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   181
					gManager->AddErrorMonitor(monitor);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   182
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   183
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   184
				gManager->ReleaseErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   185
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   186
				TCDEBUGLOGA1(" clientId=%d\n", clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   187
				jlong jClientId = clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   188
				env->SetLongArrayRegion(outClientId, 0, 1, &jClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   189
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   190
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   191
			env->ReleaseStringUTFChars(addString, pAddress);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   192
			env->ReleaseStringUTFChars(portString, pPort);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   193
			env->ReleaseStringUTFChars(chanString, pChan);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   194
			env->ReleaseStringUTFChars(decodeString, pDecode);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   195
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   196
		else if (strcmp(pType, "tcp") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   197
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   198
			jstring addString = (jstring)env->GetObjectArrayElement(inSettings, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   199
			jstring portString = (jstring)env->GetObjectArrayElement(inSettings, 1);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   200
			jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 2);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   201
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   202
			const char* pAddress = env->GetStringUTFChars(addString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   203
			const char* pPort = env->GetStringUTFChars(portString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   204
			const char* pDecode = env->GetStringUTFChars(decodeString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   205
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   206
			TCDEBUGLOGA3(" TCP: ipAddress=%s, ipPort=%s decode=%s\n", pAddress, pPort, pDecode);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   207
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   208
			ServerCommandData cmd;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   209
			cmd.command = eCmdConnect;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   210
			strncpy(cmd.connectSettings.connectType, pType, MAX_CONNECTION_TYPE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   211
			strncpy(cmd.connectSettings.tcpSettings.ipAddress, pAddress, MAX_IPADDRESS_SIZE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   212
			strncpy(cmd.connectSettings.tcpSettings.ipPort, pPort, MAX_PORT_SIZE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   213
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   214
			cmd.connectSettings.retryInterval = retryInterval;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   215
			cmd.connectSettings.retryTimeout = retryTimeout;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   216
			strncpy(cmd.connectSettings.decodeFormat, pDecode, MAX_DECODE_FORMAT);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   217
			cmd.clientOptions.unWrapFormat = unWrapFormat;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   218
			cmd.clientOptions.ostVersion = ostVersion;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   219
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   220
			gManager->m_Server->SendCommand(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   221
			gManager->m_Server->GetResponse(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   222
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   223
			if (cmd.response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   224
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   225
				TCDEBUGLOGA1("  from server: ret = %d\n", cmd.error);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   226
				ret = cmd.error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   227
				osError = cmd.osError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   228
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   229
			else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   230
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   231
				TCDEBUGLOGA1("  from server: id = %d\n", cmd.clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   232
				clientId = cmd.clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   233
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   234
				gManager->WaitForErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   235
				TCDEBUGLOGS(" TODO: create error monitor storage if server connected\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   236
				CErrorMonitor* monitor = new CErrorMonitor(clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   237
				if (monitor != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   238
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   239
					monitor->CreateData();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   240
					gManager->AddErrorMonitor(monitor);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   241
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   242
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   243
				gManager->ReleaseErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   244
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   245
				TCDEBUGLOGA1(" clientId=%d\n", clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   246
				jlong jClientId = clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   247
				env->SetLongArrayRegion(outClientId, 0, 1, &jClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   248
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   249
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   250
			env->ReleaseStringUTFChars(addString, pAddress);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   251
			env->ReleaseStringUTFChars(portString, pPort);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   252
			env->ReleaseStringUTFChars(decodeString, pDecode);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   253
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   254
		else if (strcmp(pType, "virtualserial") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   255
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   256
			jstring portString = (jstring)env->GetObjectArrayElement(inSettings, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   257
			const char* pPort = env->GetStringUTFChars(portString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   258
			jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 1);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   259
			const char* pDecode = env->GetStringUTFChars(decodeString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   260
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   261
			TCDEBUGLOGA2(" vserial: pPort=%s decode=%s\n", pPort, pDecode);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   262
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   263
			ServerCommandData cmd;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   264
			cmd.command = eCmdConnect;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   265
			strncpy(cmd.connectSettings.connectType, pType, MAX_CONNECTION_TYPE); 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   266
			strncpy(cmd.connectSettings.virtualSerialSettings.comPort, pPort, MAX_COMPORT_SIZE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   267
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   268
			cmd.connectSettings.retryInterval = retryInterval;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   269
			cmd.connectSettings.retryTimeout = retryTimeout;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   270
			strncpy(cmd.connectSettings.decodeFormat, pDecode, MAX_DECODE_FORMAT);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   271
			cmd.clientOptions.unWrapFormat = unWrapFormat;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   272
			cmd.clientOptions.ostVersion = ostVersion;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   273
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   274
			gManager->m_Server->SendCommand(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   275
			gManager->m_Server->GetResponse(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   276
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   277
			if (cmd.response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   278
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   279
				TCDEBUGLOGA1("  from server: ret = %d\n", cmd.error);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   280
				ret = cmd.error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   281
				osError = cmd.osError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   282
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   283
			else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   284
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   285
				TCDEBUGLOGA1("  from server: id = %d\n", cmd.clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   286
				clientId = cmd.clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   287
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   288
				gManager->WaitForErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   289
				CErrorMonitor* monitor = new CErrorMonitor(clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   290
				if (monitor != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   291
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   292
					monitor->CreateData();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   293
					gManager->AddErrorMonitor(monitor);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   294
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   295
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   296
				gManager->ReleaseErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   297
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   298
				TCDEBUGLOGA1(" clientId=%d\n", clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   299
				jlong jClientId = clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   300
				env->SetLongArrayRegion(outClientId, 0, 1, &jClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   301
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   302
			env->ReleaseStringUTFChars(portString, pPort);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   303
			env->ReleaseStringUTFChars(decodeString, pDecode);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   304
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   305
		else if (strcmp(pType, "serial") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   306
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   307
			jstring portString = (jstring)env->GetObjectArrayElement(inSettings, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   308
			const char* pPort = env->GetStringUTFChars(portString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   309
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   310
			jstring baudString = (jstring)env->GetObjectArrayElement(inSettings, 1);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   311
			const char* pBaud = env->GetStringUTFChars(baudString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   312
			
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   313
			jstring dataBitsString = (jstring)env->GetObjectArrayElement(inSettings, 2);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   314
			const char* pDataBits = env->GetStringUTFChars(dataBitsString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   315
			
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   316
			jstring parityString = (jstring)env->GetObjectArrayElement(inSettings, 3);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   317
			const char* pParity = env->GetStringUTFChars(parityString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   318
			
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   319
			jstring stopBitsString = (jstring)env->GetObjectArrayElement(inSettings, 4);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   320
			const char* pStopBits = env->GetStringUTFChars(stopBitsString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   321
			
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   322
			jstring flowControlString = (jstring)env->GetObjectArrayElement(inSettings, 5);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   323
			const char* pFlowControl = env->GetStringUTFChars(flowControlString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   324
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   325
			jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 6);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   326
			const char* pDecode = env->GetStringUTFChars(decodeString, NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   327
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   328
			TCDEBUGLOGA3(" real serial: pPort=%s pBaud=%s pDataBits=%s\n", pPort, pBaud, pDataBits);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   329
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   330
			ServerCommandData cmd;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   331
			cmd.command = eCmdConnect;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   332
			strncpy(cmd.connectSettings.connectType, pType, MAX_CONNECTION_TYPE); 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   333
			strncpy(cmd.connectSettings.realSerialSettings.comPort, pPort, MAX_COMPORT_SIZE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   334
			ConvertRealSerialSettingsToServer(pBaud, pDataBits, pParity, pStopBits, pFlowControl, &cmd.connectSettings.realSerialSettings);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   335
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   336
			cmd.connectSettings.retryInterval = retryInterval;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   337
			cmd.connectSettings.retryTimeout = retryTimeout;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   338
			strncpy(cmd.connectSettings.decodeFormat, pDecode, MAX_DECODE_FORMAT);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   339
			cmd.clientOptions.unWrapFormat = unWrapFormat;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   340
			cmd.clientOptions.ostVersion = ostVersion;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   341
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   342
			gManager->m_Server->SendCommand(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   343
			gManager->m_Server->GetResponse(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   344
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   345
			if (cmd.response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   346
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   347
				TCDEBUGLOGA1("  from server: ret = %d\n", cmd.error);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   348
				ret = cmd.error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   349
				osError = cmd.osError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   350
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   351
			else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   352
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   353
				TCDEBUGLOGA1("  from server: id = %d\n", cmd.clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   354
				clientId = cmd.clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   355
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   356
				gManager->WaitForErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   357
				CErrorMonitor* monitor = new CErrorMonitor(clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   358
				if (monitor != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   359
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   360
					monitor->CreateData();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   361
					gManager->AddErrorMonitor(monitor);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   362
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   363
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   364
				gManager->ReleaseErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   365
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   366
				TCDEBUGLOGA1(" clientId=%d\n", clientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   367
				jlong jClientId = clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   368
				env->SetLongArrayRegion(outClientId, 0, 1, &jClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   369
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   370
			env->ReleaseStringUTFChars(portString, pPort);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   371
			env->ReleaseStringUTFChars(baudString, pBaud);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   372
			env->ReleaseStringUTFChars(dataBitsString, pDataBits);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   373
			env->ReleaseStringUTFChars(parityString, pParity);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   374
			env->ReleaseStringUTFChars(stopBitsString, pStopBits);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   375
			env->ReleaseStringUTFChars(flowControlString, pFlowControl);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   376
			env->ReleaseStringUTFChars(decodeString, pDecode);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   377
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   378
		else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   379
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   380
			TCDEBUGLOGS(" TCAPI_ERR_MEDIA_NOT_SUPPORTED\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   381
			ret = TCAPI_ERR_MEDIA_NOT_SUPPORTED;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   382
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   383
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   384
		env->ReleaseStringUTFChars(inType, pType);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   385
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   386
		
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   387
		// handle message destinations
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   388
		//  input stream is done by java on open input stream not here
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   389
		//  message file is done here
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   390
		if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   391
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   392
			long destination = DESTINATION_INPUTSTREAM;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   393
			char* pMessageFile = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   394
			if (inFilePath != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   395
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   396
				destination = DESTINATION_CLIENTFILE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   397
				jboolean isCopy=FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   398
				pMessageFile = (char*)env->GetStringUTFChars(inFilePath, &isCopy);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   399
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   400
				// send to TCFServer
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   401
				ServerCommandData cmd;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   402
				cmd.command = eCmdOpenMessageFile;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   403
				cmd.clientId = clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   404
				cmd.destinationOptions.destination = eDestinationFile;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   405
				strncpy(cmd.destinationOptions.destinationFile, pMessageFile, MAX_FILEPATH);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   406
				gManager->m_Server->SendCommand(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   407
				gManager->m_Server->GetResponse(&cmd);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   408
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   409
				env->ReleaseStringUTFChars(inFilePath, pMessageFile);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   410
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   411
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   412
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   413
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   414
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   415
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   416
	TCDEBUGLOGA3("nativeConnect return ret=%d, osError=%d : %s\n", ret, osError, GetErrorText(osError));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   417
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   418
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   419
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   420
	if (ret != TCAPI_ERR_NONE && osError > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   421
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   422
		jclass clazz = env->FindClass("Ljava/lang/Exception;");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   423
		env->ThrowNew(clazz, GetErrorText(osError));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   424
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   425
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   426
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   427
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   428
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   429
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   430
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   431
 * Method:    nativeDisconnect
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   432
 * Signature: (J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   433
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   434
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeDisconnect
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   435
  (JNIEnv *env, jobject pThis, jlong inClientId)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   436
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   437
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   438
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   439
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   440
	TCDEBUGLOGS("nativeDisconnect\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   441
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   442
	if (gManager->m_Server == NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   443
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   444
		TCDEBUGLOGS(" TCAPI_ERR_INVALID_HANDLE - gServer NULL\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   445
		ret = TCAPI_ERR_INVALID_HANDLE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   446
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   447
	else if (inClientId <= 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   448
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   449
		TCDEBUGLOGS(" TCAPI_ERR_INVALID_HANDLE - inClientId <= 0\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   450
		ret = TCAPI_ERR_INVALID_HANDLE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   451
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   452
	else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   453
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   454
		gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   455
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   456
		BOOL found = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   457
		long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   458
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   459
		TCDEBUGLOGA1(" look for clientId=%d\n", id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   460
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   461
		TCDEBUGLOGS(" TODO: tell server to disconnect this client\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   462
		ServerCommandData cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   463
		pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   464
		pCmdrsp->command = eCmdDisconnect;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   465
		pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   466
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   467
		gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   468
		gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   469
		if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   470
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   471
			ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   472
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   473
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   474
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   475
			gManager->WaitForErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   476
			TCDEBUGLOGS(" TODO: destroy error monitor for this client\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   477
			CErrorMonitor *monitor = gManager->FindErrorMonitor(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   478
			if (monitor != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   479
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   480
				gManager->RemoveErrorMonitor(monitor);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   481
				delete monitor;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   482
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   483
			gManager->ReleaseErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   484
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   485
		gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   486
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   487
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   488
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   489
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   490
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   491
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   492
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   493
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   494
 * Method:    nativeGetNumberConnections
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   495
 * Signature: ([J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   496
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   497
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetNumberConnections
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   498
  (JNIEnv *env, jobject pThis, jlongArray outNumber)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   499
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   500
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   501
	long number = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   502
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   503
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   504
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   505
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   506
	TCDEBUGLOGS("nativeGetNumberConnections\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   507
	ServerCommandData cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   508
	pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   509
	pCmdrsp->command = eCmdGetNumberConnections;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   510
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   511
	BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   512
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   513
	BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   514
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   515
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   516
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   517
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   518
	else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   519
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   520
		number = pCmdrsp->numConnections;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   521
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   522
		jlong jNumber = number;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   523
		env->SetLongArrayRegion(outNumber, 0, 1, &jNumber);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   524
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   525
		TCDEBUGLOGA1(" number=%d\n", number);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   526
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   527
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   528
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   529
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   530
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   531
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   532
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   533
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   534
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   535
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   536
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   537
 * Method:    nativeGetTypeOfConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   538
 * Signature: (J[Ljava/lang/String;)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   539
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   540
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetTypeOfConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   541
  (JNIEnv *env, jobject pThis, jlong inIndex, jobjectArray outType)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   542
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   543
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   544
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   545
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   546
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   547
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   548
	TCDEBUGLOGS("nativeGetTypeOfConnection\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   549
	ServerCommandData cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   550
	pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   551
	pCmdrsp->command = eCmdGetConnectionType;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   552
	pCmdrsp->index = inIndex;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   553
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   554
	BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   555
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   556
	BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   557
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   558
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   559
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   560
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   561
	else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   562
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   563
		env->SetObjectArrayElement(outType, 0, env->NewStringUTF(pCmdrsp->connectSettings.connectType));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   564
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   565
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   566
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   567
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   568
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   569
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   570
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   571
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   572
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   573
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   574
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   575
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   576
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   577
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   578
 * Method:    nativeGetConnectionSettings
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   579
 * Signature: (J[Ljava/lang/String;[J[Ljava/lang/String;)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   580
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   581
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetConnectionSettings
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   582
  (JNIEnv *env, jobject pThis, jlong inIndex, jobjectArray outType, jlongArray outOptions, jobjectArray outSettings)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   583
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   584
	long ret = TCAPI_ERR_FEATURE_NOT_IMPLEMENTED;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   585
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   586
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   587
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   588
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   589
	TCDEBUGLOGS("nativeGetConnectionSettings\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   590
	ServerCommandData cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   591
	pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   592
	pCmdrsp->command = eCmdGetConnection;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   593
	pCmdrsp->index = inIndex;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   594
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   595
	BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   596
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   597
	BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   598
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   599
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   600
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   601
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   602
	else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   603
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   604
		env->SetObjectArrayElement(outType, 0, env->NewStringUTF(pCmdrsp->connectSettings.connectType));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   605
		if (strcmp(pCmdrsp->connectSettings.connectType, "musti") == 0 || strcmp(pCmdrsp->connectSettings.connectType, "platsim") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   606
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   607
			env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.tcpSettings.ipAddress));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   608
			env->SetObjectArrayElement(outSettings, 1, env->NewStringUTF(pCmdrsp->connectSettings.tcpSettings.ipPort));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   609
			char *pChan = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   610
			if (pCmdrsp->connectSettings.traceBoxChannel == 1)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   611
				pChan = "1";
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   612
			else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   613
				pChan = "2";
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   614
			env->SetObjectArrayElement(outSettings, 2, env->NewStringUTF(pChan));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   615
			env->SetObjectArrayElement(outSettings, 3, env->NewStringUTF(pCmdrsp->connectSettings.decodeFormat));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   616
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   617
		else if (strcmp(pCmdrsp->connectSettings.connectType, "tcp") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   618
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   619
			env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.tcpSettings.ipAddress));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   620
			env->SetObjectArrayElement(outSettings, 1, env->NewStringUTF(pCmdrsp->connectSettings.tcpSettings.ipPort));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   621
			env->SetObjectArrayElement(outSettings, 2, env->NewStringUTF(pCmdrsp->connectSettings.decodeFormat));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   622
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   623
		else if (strcmp(pCmdrsp->connectSettings.connectType, "virtualserial") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   624
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   625
			env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.virtualSerialSettings.comPort));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   626
			env->SetObjectArrayElement(outSettings, 1, env->NewStringUTF(pCmdrsp->connectSettings.decodeFormat));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   627
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   628
		else if (strcmp(pCmdrsp->connectSettings.connectType, "serial") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   629
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   630
			env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.realSerialSettings.comPort));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   631
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   632
			char baud[10], databits[10], parity[10], stopbits[10], flowcontrol[15];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   633
			ConvertRealSerialSettingsToHost(baud, databits, parity, stopbits, flowcontrol, &pCmdrsp->connectSettings.realSerialSettings);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   634
			env->SetObjectArrayElement(outSettings, 1, env->NewStringUTF(baud));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   635
			env->SetObjectArrayElement(outSettings, 2, env->NewStringUTF(databits));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   636
			env->SetObjectArrayElement(outSettings, 3, env->NewStringUTF(parity));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   637
			env->SetObjectArrayElement(outSettings, 4, env->NewStringUTF(stopbits));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   638
			env->SetObjectArrayElement(outSettings, 5, env->NewStringUTF(flowcontrol));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   639
			env->SetObjectArrayElement(outSettings, 6, env->NewStringUTF(pCmdrsp->connectSettings.decodeFormat));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   640
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   641
		else if (strcmp(pCmdrsp->connectSettings.connectType, "usb") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   642
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   643
			env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.usbSettings.device));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   644
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   645
		jlong jRetryInterval = pCmdrsp->connectSettings.retryInterval;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   646
		env->SetLongArrayRegion(outOptions, 0, 1, &jRetryInterval);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   647
		jlong jRetryTimeout = pCmdrsp->connectSettings.retryTimeout;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   648
		env->SetLongArrayRegion(outOptions, 1, 1, &jRetryTimeout);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   649
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   650
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   651
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   652
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   653
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   654
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   655
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   656
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   657
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   658
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   659
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   660
 * Method:    nativePollError
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   661
 * Signature: (J[I[Z[J)Z
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   662
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   663
JNIEXPORT jboolean JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativePollError
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   664
  (JNIEnv *env, jobject pThis, jlong inClientId, jintArray outErrorCode, 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   665
	jbooleanArray outHasOSErrorCode, jlongArray outOSErrorCode)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   666
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   667
	jboolean foundError = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   668
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   669
	LONG tcfError = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   670
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   671
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   672
	TCDEBUGLOGS("nativePollError\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   673
//	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   674
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   675
	gManager->WaitForErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   676
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   677
	if (gManager->ErrorMonitorListSize() > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   678
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   679
//		TCDEBUGLOGA1(" size of gManager->ErrorMonitorListSize=%d\n", gManager->ErrorMonitorListSize());
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   680
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   681
		CErrorMonitor* errorMonitor = gManager->FindErrorMonitor(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   682
//		TCDEBUGLOGA1(" errorMonitor = %x\n", errorMonitor);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   683
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   684
		if (errorMonitor != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   685
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   686
//			TCDEBUGLOGS(" found client\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   687
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   688
			BOOL osErrorUsed = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   689
			DWORD osError = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   690
			BOOL found = errorMonitor->GetError(&tcfError, &osErrorUsed, &osError);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   691
			if (found)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   692
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   693
//				TCDEBUGLOGA1("nativePollError error for client=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   694
//				TCDEBUGLOGA3(" found tcfError=%d, osErrorUsed=%d, osError=%d\n",
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   695
//					tcfError, osErrorUsed, osError);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   696
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   697
				foundError = true;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   698
				jint jval = tcfError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   699
				env->SetIntArrayRegion(outErrorCode, 0, 1, &jval);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   700
				jboolean jos = osErrorUsed;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   701
				env->SetBooleanArrayRegion(outHasOSErrorCode, 0, 1, &jos);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   702
				jlong jlval = osError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   703
				env->SetLongArrayRegion(outOSErrorCode, 0, 1, &jlval);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   704
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   705
//				TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   706
//				TCDEBUGLOGS("nativePollError found error\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   707
//				TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   708
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   709
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   710
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   711
	gManager->ReleaseErrorMonitorListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   712
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   713
	TCDEBUGLOGA2(" return foundError=%d tcfError=%d\n", foundError, tcfError);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   714
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   715
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   716
	return foundError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   717
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   718
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   719
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   720
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   721
 * Method:    nativeGetNumberVersionEntities
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   722
 * Signature: (J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   723
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   724
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetNumberVersionEntities
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   725
  (JNIEnv *env, jobject pThis, jlong inClientId)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   726
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   727
	long number = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   728
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   729
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   730
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   731
	TCDEBUGLOGS("nativeGetNumberVersionEntities\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   732
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   733
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   734
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   735
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   736
	// eCmdGetNumberVersions
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   737
	ServerCommandData cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   738
	pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   739
	pCmdrsp->command = eCmdGetNumberVersions;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   740
	pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   741
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   742
	BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   743
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   744
	BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   745
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   746
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   747
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   748
	else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   749
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   750
		number = pCmdrsp->number + 1; // + 1 for DLL version
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   751
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   752
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   753
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   754
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   755
	TCDEBUGLOGA1(" numberVersions = %d\n", number);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   756
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   757
	return number;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   758
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   759
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   760
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   761
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   762
 * Method:    nativeGetVersion
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   763
 * Signature: (JJ[Ljava/lang/String;)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   764
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   765
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetVersion
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   766
  (JNIEnv *env, jobject pThis, jlong inClientId, jlong inNumToGet, jobjectArray outVersion)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   767
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   768
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   769
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   770
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   771
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   772
	TCDEBUGLOGS("nativeGetVersion\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   773
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   774
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   775
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   776
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   777
	// eCmdGetVersion
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   778
	ServerCommandData cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   779
	pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   780
	pCmdrsp->command = eCmdGetVersion;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   781
	pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   782
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   783
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   784
	// index = 0 ==> TCFClient.dll version
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   785
	env->SetObjectArrayElement(outVersion, 0, env->NewStringUTF(gManager->m_Version));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   786
	long numberGot = 1;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   787
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   788
	if (inNumToGet > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   789
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   790
		// index = 1 ==> TCFServer.exe version
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   791
		pCmdrsp->command = eCmdGetVersion;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   792
		pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   793
		pCmdrsp->index = 1;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   794
		BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   795
		BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   796
		if (pCmdrsp->response == eRspOK)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   797
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   798
			env->SetObjectArrayElement(outVersion, 1, env->NewStringUTF(pCmdrsp->version));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   799
			numberGot++;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   800
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   801
			if (inNumToGet > 1)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   802
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   803
				// index = 2 ==> connection version
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   804
				pCmdrsp->command = eCmdGetVersion;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   805
				pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   806
				pCmdrsp->index = 2;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   807
				BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   808
				BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   809
				if (pCmdrsp->response == eRspOK)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   810
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   811
					env->SetObjectArrayElement(outVersion, 2, env->NewStringUTF(pCmdrsp->version));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   812
					numberGot++;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   813
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   814
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   815
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   816
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   817
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   818
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   819
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   820
	TCDEBUGLOGA1(" return numberGot=%d\n", numberGot);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   821
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   822
	return numberGot;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   823
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   824
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   825
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   826
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   827
 * Method:    nativePollInputStream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   828
 * Signature: (J[J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   829
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   830
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativePollInputStream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   831
  (JNIEnv *env, jobject pThis, jlong inClientId, jlongArray outNumberMessages)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   832
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   833
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   834
	long number = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   835
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   836
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   837
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   838
	TCDEBUGLOGS("nativePollInputStream\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   839
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   840
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   841
	TCDEBUGLOGS(" TODO: get number from client's input stream\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   842
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   843
	gManager->WaitForStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   844
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   845
	CInputStream* inputStream = gManager->FindInputStream(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   846
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   847
	if (inputStream != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   848
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   849
		TCDEBUGLOGA1(" -- found id inputStream=%x\n", inputStream);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   850
		number = inputStream->GetNumberMessages();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   851
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   852
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   853
	gManager->ReleaseStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   854
	jlong jNumber = number;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   855
	env->SetLongArrayRegion(outNumberMessages, 0, 1, &jNumber);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   856
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   857
	TCDEBUGLOGA2(" numberMessages=%d ret=%d\n", number, ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   858
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   859
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   860
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   861
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   862
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   863
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   864
 * Method:    nativePollInputStream2
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   865
 * Signature: (JJ[J[J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   866
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   867
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativePollInputStream2
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   868
  (JNIEnv *env, jobject pThis, jlong inClientId, jlong inNumberMessagesToPeek, jlongArray outNumberMessagesPeeked, jlongArray outNumberBytesPeeked)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   869
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   870
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   871
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   872
	long numberToGet = inNumberMessagesToPeek;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   873
	long numberStored = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   874
	DWORD numberBytes = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   875
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   876
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   877
	TCDEBUGLOGS("nativePollInputStream2\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   878
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   879
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   880
	gManager->WaitForStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   881
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   882
	CInputStream* inputStream = gManager->FindInputStream(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   883
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   884
	if (inputStream != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   885
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   886
		TCDEBUGLOGA1(" -- found id inputStream=%x\n", inputStream);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   887
		numberStored = inputStream->GetNumberMessages();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   888
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   889
		if ((numberToGet == 0) || (numberToGet > numberStored))
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   890
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   891
			numberToGet = numberStored;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   892
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   893
		if (numberToGet > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   894
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   895
			inputStream->GetTotalMessageSize(numberToGet, numberBytes);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   896
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   897
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   898
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   899
	gManager->ReleaseStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   900
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   901
	jlong jNumber = numberToGet;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   902
	env->SetLongArrayRegion(outNumberMessagesPeeked, 0, 1, &jNumber);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   903
	jNumber = numberBytes;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   904
	env->SetLongArrayRegion(outNumberBytesPeeked, 0, 1, &jNumber);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   905
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   906
	TCDEBUGLOGA3(" numberMessages=%d numberBytes=%d ret=%d\n", numberToGet, numberBytes, ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   907
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   908
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   909
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   910
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   911
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   912
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   913
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   914
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   915
 * Method:    nativeGetInputStreamMessageBytes
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   916
 * Signature: (JJ[J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   917
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   918
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetInputStreamMessageBytes
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   919
  (JNIEnv *env, jobject pThis, jlong inClientId, jlong inNumberMessages, jlongArray outMessageSizes)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   920
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   921
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   922
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   923
	long numberToGet = inNumberMessages;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   924
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   925
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   926
	TCDEBUGLOGS("nativeGetInputStreamMessageBytes\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   927
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   928
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   929
	gManager->WaitForStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   930
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   931
	CInputStream* inputStream = gManager->FindInputStream(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   932
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   933
	if (inputStream != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   934
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   935
		TCDEBUGLOGA1(" -- found id inputStream=%x\n", inputStream);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   936
		DWORD* pSizes = new DWORD[numberToGet];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   937
		inputStream->GetMessageSizes(numberToGet, pSizes);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   938
		for (int i = 0; i < numberToGet; i++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   939
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   940
			TCDEBUGLOGA2(" -- message size[%d] = %d\n", i, pSizes[i]);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   941
			jlong jsize = pSizes[i];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   942
			env->SetLongArrayRegion(outMessageSizes, i, 1, &jsize);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   943
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   944
		delete[] pSizes;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   945
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   946
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   947
	gManager->ReleaseStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   948
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   949
	TCDEBUGLOGA1("nativeGetInputStreamMessageBytes ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   950
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   951
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   952
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   953
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   954
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   955
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   956
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   957
 * Method:    nativeReadInputStream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   958
 * Signature: (JJ[J[JJ[B)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   959
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   960
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeReadInputStream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   961
  (JNIEnv *env, jobject pThis, jlong inClientId, jlong inNumberMessages, jlongArray outNumberMessages, jlongArray outNumberBytesRead, jlong inNumberMaxBytes, jbyteArray outMessageData)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   962
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   963
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   964
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   965
	long numberToGet = inNumberMessages;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   966
	long numberMaxBytes = inNumberMaxBytes;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   967
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   968
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   969
	TCDEBUGLOGS("nativeReadInputStream start\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   970
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   971
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   972
	gManager->WaitForStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   973
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   974
	CInputStream* inputStream = gManager->FindInputStream(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   975
	if (inputStream != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   976
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   977
		long numberBytesRead = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   978
		long numberMessagesRead = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   979
#if (0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   980
		DWORD mSize = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   981
		DWORD outOffset = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   982
		BYTE* pData = new BYTE[64*1024];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   983
		for (int i = 0; i < numberToGet; i++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   984
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   985
			TCDEBUGLOGS("nativeReadInputStream 1\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   986
			mSize = inputStream->GetNextMessageSize();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   987
			if ((numberBytesRead + mSize) > numberMaxBytes)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   988
				break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   989
			if (mSize != 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   990
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   991
				mSize = inputStream->GetNextMessage(mSize, pData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   992
				TCDEBUGLOGA3("outOffset = %d mSize = %d pData[0] = %02.2x\n", outOffset, mSize, pData[0]);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   993
				jbyte* pByte = (jbyte*)pData;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   994
				env->SetByteArrayRegion(outMessageData, outOffset, mSize, pByte);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   995
				outOffset += mSize;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   996
				numberBytesRead += mSize;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   997
				numberMessagesRead++;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   998
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   999
				if ((i % 500) == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1000
					Sleep(1);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1001
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1002
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1003
		delete [] pData;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1004
#endif
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1005
		numberMessagesRead = inputStream->GetMessages(env, numberToGet, numberMaxBytes, numberBytesRead, numberMessagesRead, outMessageData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1006
		jlong jMsgs = numberMessagesRead;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1007
		env->SetLongArrayRegion(outNumberMessages, 0, 1, &jMsgs);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1008
		jlong jNum = numberBytesRead;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1009
		env->SetLongArrayRegion(outNumberBytesRead, 0, 1, &jNum);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1010
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1011
		TCDEBUGLOGS("nativeReadInputStream 2\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1012
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1013
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1014
	gManager->ReleaseStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1015
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1016
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1017
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1018
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1019
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1020
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1021
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1022
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1023
 * Method:    nativeOpenInputStream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1024
 * Signature: (JLjava/lang/String;JZ)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1025
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1026
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeOpenInputStream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1027
  (JNIEnv *env, jobject pThis, jlong inClientId, jstring inFileBaseName, jlong inStreamSize, jboolean inOverflowToFile)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1028
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1029
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1030
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1031
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1032
	TCDEBUGLOGS("nativeOpenInputStream\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1033
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1034
	TCDEBUGLOGA1(" inFileBaseName=%x\n", inFileBaseName);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1035
	TCDEBUGLOGA1(" inStreamSize=%d\n", inStreamSize);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1036
	TCDEBUGLOGA1(" inOverflowToFile=%d\n", inOverflowToFile);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1037
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1038
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1039
	gManager->WaitForStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1040
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1041
	char* pFileName = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1042
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1043
	if (inFileBaseName != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1044
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1045
		TCDEBUGLOGS("nativeOpenInputStream GetStringUTFChars on inFileBaseName\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1046
		jboolean isCopy=FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1047
		pFileName = (char*)env->GetStringUTFChars(inFileBaseName, &isCopy);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1048
		TCDEBUGLOGS("nativeOpenInputStream return GetStringUTFChars\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1049
		TCDEBUGLOGA1(" pFileName=%x\n", pFileName);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1050
//		if (pFileName != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1051
//		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1052
//			TCDEBUGLOGA1(" pFileName=%s\n", pFileName);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1053
//		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1054
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1055
	else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1056
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1057
		TCDEBUGLOGS("nativeOpenInputStream inFileBaseName == NULL\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1058
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1059
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1060
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1061
	TCDEBUGLOGS("nativeOpenInputStream continue after GetStringUTFChars\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1062
	DWORD streamSize = inStreamSize;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1063
	TCDEBUGLOGA1(" streamSize=%d\n", streamSize);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1064
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1065
	BOOL overflowOption = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1066
	TCDEBUGLOGA1(" overflowOption=%d\n", overflowOption);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1067
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1068
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1069
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1070
	TCDEBUGLOGA1(" gManager->InputStreamListSize=%d\n", gManager->InputStreamListSize());
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1071
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1072
	// create stream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1073
	CInputStream* stream = new CInputStream(pFileName, streamSize, overflowOption, id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1074
	stream->CreateStream();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1075
	gManager->AddInputStream(stream);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1076
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1077
	ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1078
	pCmdrsp->command = eCmdOpenStream;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1079
	pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1080
	pCmdrsp->destinationOptions.destination = eDestinationInputStream;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1081
	pCmdrsp->destinationOptions.streamSize = streamSize;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1082
	pCmdrsp->destinationOptions.overFlowToFile = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1083
	if (pFileName != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1084
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1085
		strncpy(pCmdrsp->destinationOptions.destinationFile, pFileName, MAX_FILEPATH);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1086
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1087
	else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1088
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1089
		pCmdrsp->destinationOptions.destinationFile[0] = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1090
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1091
	if (inFileBaseName != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1092
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1093
		TCDEBUGLOGS("nativeOpenInputStream ReleaseStringUTFChars on inFileBaseName\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1094
		env->ReleaseStringUTFChars(inFileBaseName, pFileName);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1095
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1096
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1097
	gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1098
	gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1099
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1100
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1101
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1102
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1103
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1104
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1105
	TCDEBUGLOGA1(" gManager->InputStreamListSize=%d\n", gManager->InputStreamListSize());
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1106
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1107
	gManager->ReleaseStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1108
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1109
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1110
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1111
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1112
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1113
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1114
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1115
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1116
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1117
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1118
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1119
 * Method:    nativeCloseInputStream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1120
 * Signature: (J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1121
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1122
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeCloseInputStream
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1123
  (JNIEnv *env, jobject pThis, jlong inClientId)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1124
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1125
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1126
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1127
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1128
	TCDEBUGLOGS("nativeCloseInputStream\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1129
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1130
	
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1131
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1132
	gManager->WaitForStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1133
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1134
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1135
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1136
	TCDEBUGLOGA1(" gManager->InputStreamListSize=%d\n", gManager->InputStreamListSize());
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1137
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1138
	TCDEBUGLOGS(" TODO: tell server to close this stream\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1139
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1140
	ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1141
	pCmdrsp->command = eCmdCloseStream;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1142
	pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1143
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1144
	gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1145
	gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1146
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1147
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1148
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1149
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1150
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1151
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1152
	CInputStream* inputStream = gManager->FindInputStream(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1153
	if (inputStream != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1154
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1155
		TCDEBUGLOGA1(" -- found id inputStream=%x\n", inputStream);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1156
		gManager->RemoveInputStream(inputStream);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1157
		delete inputStream;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1158
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1159
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1160
	TCDEBUGLOGA1(" gManager->InputStreamListSize=%d\n", gManager->InputStreamListSize());
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1161
	gManager->ReleaseStreamListAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1162
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1163
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1164
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1165
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1166
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1167
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1168
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1169
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1170
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1171
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1172
 * Method:    nativeSetMessageIds
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1173
 * Signature: (J[B)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1174
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1175
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeSetMessageIds
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1176
  (JNIEnv *env, jobject pThis, jlong inClientId, jbyteArray inIds)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1177
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1178
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1179
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1180
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1181
	TCDEBUGLOGS("nativeSetMessageIds\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1182
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1183
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1184
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1185
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1186
	ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1187
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1188
	pCmdrsp->command = eCmdSetMessageIds;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1189
	pCmdrsp->clientId = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1190
	jsize numberIds = env->GetArrayLength(inIds);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1191
	pCmdrsp->number = numberIds;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1192
	jboolean isCopy = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1193
	jbyte* bytes = env->GetByteArrayElements(inIds, &isCopy);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1194
	for (int i = 0; i < numberIds; i++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1195
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1196
		pCmdrsp->messageIds[i] = bytes[i];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1197
		TCDEBUGLOGA1(" -- msgId = 0x%02.2X\n",  pCmdrsp->messageIds[i]);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1198
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1199
	env->ReleaseByteArrayElements(inIds, bytes, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1200
	gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1201
	gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1202
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1203
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1204
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1205
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1206
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1207
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1208
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1209
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1210
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1211
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1212
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1213
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1214
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1215
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1216
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1217
 * Method:    nativeClearFile
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1218
 * Signature: (J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1219
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1220
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeClearFile
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1221
  (JNIEnv *env, jobject pThis, jlong inClientId)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1222
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1223
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1224
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1225
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1226
	long id = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1227
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1228
	ServerCommandData cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1229
	pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1230
	pCmdrsp->command = eCmdClearMessageFile;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1231
	pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1232
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1233
	gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1234
	gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1235
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1236
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1237
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1238
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1239
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1240
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1241
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1242
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1243
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1244
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1245
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1246
 * Method:    nativeSendMessage
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1247
 * Signature: (J[J[Ljava/lang/String;[B)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1248
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1249
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeSendMessage
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1250
  (JNIEnv *env, jobject pThis, jlong inClientId, jlongArray inFormattingOptions, jobjectArray inSettings, jbyteArray inMessage)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1251
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1252
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1253
	unsigned long osError = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1254
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1255
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1256
	TCDEBUGLOGS("nativeSendMessage\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1257
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1258
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1259
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1260
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1261
	jboolean isCopy = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1262
	// formatting options
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1263
	jlong* pOptions = env->GetLongArrayElements(inFormattingOptions, &isCopy);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1264
//	long encodeFormat = (long)pOptions[0];	// not used
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1265
	long encodeOption = (long)pOptions[1];	// formatting option for protocol
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1266
	long protocolVersion = (long)pOptions[2];	// OST version byte to use if protocol is OST
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1267
	BYTE myId = (BYTE)(pOptions[3] & 0xff);	// my message ID to use of adding protocol
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1268
	BOOL useMyId = (pOptions[4] == 1) ? TRUE : FALSE;	// use my ID or not
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1269
	env->ReleaseLongArrayElements(inFormattingOptions, pOptions, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1270
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1271
	jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1272
	const char* pDecode = env->GetStringUTFChars(decodeString, NULL); // not used
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1273
	env->ReleaseStringUTFChars(decodeString, pDecode);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1274
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1275
	jsize numberBytes = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1276
	if (inMessage != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1277
		numberBytes = env->GetArrayLength(inMessage);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1278
	long inLength = numberBytes;		// this can be null
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1279
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1280
	jbyte* inData = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1281
	if (inLength > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1282
		inData = env->GetByteArrayElements(inMessage, &isCopy);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1283
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1284
	ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1285
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1286
	pCmdrsp->command = eCmdSendMessage;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1287
	pCmdrsp->clientId = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1288
	pCmdrsp->encodeOption = encodeOption;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1289
	pCmdrsp->useMyId = useMyId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1290
	pCmdrsp->myId = myId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1291
	pCmdrsp->protocolVersion = protocolVersion & 0xff;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1292
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1293
	// send message to server
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1294
	pCmdrsp->osError = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1295
	gManager->m_Server->SendCommand(pCmdrsp, inLength, (BYTE*)inData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1296
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1297
	TCDEBUGLOGS(" nativeSendMessage  GetResponse\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1298
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1299
	// get response from server
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1300
	gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1301
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1302
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1303
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1304
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1305
		osError = pCmdrsp->osError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1306
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1307
	if (inData != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1308
		env->ReleaseByteArrayElements(inMessage, inData, 0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1309
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1310
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1311
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1312
	TCDEBUGLOGA3("nativeSendMessage return ret=%d, osError=%d : %s\n", ret, osError, GetErrorText(osError));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1313
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1314
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1315
	if (ret == TCAPI_ERR_COMM_ERROR && osError > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1316
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1317
		jclass clazz = env->FindClass("Ljava/lang/Exception;");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1318
		env->ThrowNew(clazz, GetErrorText(osError));
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1319
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1320
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1321
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1322
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1323
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1324
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1325
 * Method:    nativeStart
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1326
 * Signature: (J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1327
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1328
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeStart
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1329
  (JNIEnv *env, jobject pThis, jlong inClientId)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1330
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1331
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1332
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1333
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1334
	TCDEBUGLOGS("nativeStart\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1335
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1336
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1337
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1338
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1339
	TCDEBUGLOGS(" TODO: tell server to start this client\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1340
	ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1341
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1342
	pCmdrsp->command = eCmdStart;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1343
	pCmdrsp->clientId = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1344
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1345
	gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1346
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1347
	gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1348
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1349
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1350
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1351
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1352
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1353
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1354
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1355
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1356
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1357
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1358
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1359
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1360
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1361
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1362
 * Method:    nativeStop
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1363
 * Signature: (J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1364
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1365
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeStop
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1366
  (JNIEnv *env, jobject pThis, jlong inClientId)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1367
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1368
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1369
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1370
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1371
	TCDEBUGLOGS("nativeStop\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1372
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1373
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1374
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1375
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1376
	TCDEBUGLOGS(" TODO: tell server to stop this client\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1377
	ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1378
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1379
	pCmdrsp->command = eCmdStop;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1380
	pCmdrsp->clientId = inClientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1381
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1382
	gManager->m_Server->SendCommand(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1383
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1384
	gManager->m_Server->GetResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1385
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1386
	if (pCmdrsp->response == eRspError)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1387
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1388
		ret = pCmdrsp->error;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1389
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1390
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1391
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1392
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1393
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1394
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1395
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1396
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1397
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1398
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1399
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1400
 * Method:    nativeTestConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1401
 * Signature: (I[J[Ljava/lang/String;)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1402
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1403
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeTestConnection__I_3J_3Ljava_lang_String_2
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1404
  (JNIEnv *env, jobject pThis, jint inType, jlongArray inOptions, jobjectArray inSettings)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1405
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1406
	long ret = TCAPI_ERR_FEATURE_NOT_IMPLEMENTED;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1407
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1408
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1409
	TCDEBUGLOGS("nativeTestConnection\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1410
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1411
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1412
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1413
	TCDEBUGLOGS(" TODO: ask server to test this connection\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1414
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1415
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1416
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1417
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1418
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1419
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1420
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1421
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1422
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1423
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1424
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1425
 * Method:    nativeTestConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1426
 * Signature: (J)J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1427
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1428
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeTestConnection__J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1429
  (JNIEnv *env, jobject pThis, jlong inClientId)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1430
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1431
	long ret = TCAPI_ERR_FEATURE_NOT_IMPLEMENTED;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1432
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1433
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1434
	TCDEBUGLOGS("nativeTestConnection\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1435
	TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1436
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1437
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1438
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1439
	TCDEBUGLOGS(" TODO: ask server to test this client's connection\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1440
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1441
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1442
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1443
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1444
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1445
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1446
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1447
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1448
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1449
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1450
 * Method:    nativeStartServer
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1451
 * Signature: ()J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1452
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1453
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeStartServer
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1454
  (JNIEnv *env, jobject pThis)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1455
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1456
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1457
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1458
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1459
	TCDEBUGLOGS("nativeStartServer\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1460
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1461
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1462
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1463
	ret = gManager->StartServer();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1464
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1465
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1466
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1467
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1468
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1469
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1470
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1471
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1472
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1473
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1474
 * Class:     com_nokia_tcf_impl_TCAPIConnection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1475
 * Method:    nativeStopServer
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1476
 * Signature: ()J
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1477
 */
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1478
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeStopServer
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1479
  (JNIEnv *env, jobject pThis)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1480
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1481
	long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1482
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1483
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1484
	TCDEBUGLOGS("nativeStopServer\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1485
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1486
	gManager->m_Server->WaitforServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1487
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1488
	ret = gManager->StopServer();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1489
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1490
	gManager->m_Server->ReleaseServerPipeAccess();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1491
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1492
	TCDEBUGLOGA1(" return ret=%d\n", ret);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1493
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1494
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1495
	return ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1496
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1497
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1498
void ConvertRealSerialSettingsToServer(const char* pBaud, const char* pDataBits, const char* pParity, const char* pStopBits, const char* pFlowControl, pRealSerialConnectData pData)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1499
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1500
	// no error checking - all error checking is done at the Java level
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1501
	pData->baudRate = atol(pBaud);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1502
	pData->dataBits = atol(pDataBits);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1503
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1504
	pData->parity = eParityNone;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1505
	if (strcmp(pParity, "odd") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1506
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1507
		pData->parity = eParityOdd;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1508
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1509
	else if (strcmp(pParity, "even") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1510
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1511
		pData->parity = eParityEven;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1512
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1513
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1514
	pData->stopBits = eStopBits1;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1515
	if (strcmp(pStopBits, "1.5") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1516
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1517
		pData->stopBits = eStopBits15;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1518
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1519
	else if (strcmp(pStopBits, "2") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1520
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1521
		pData->stopBits = eStopBits2;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1522
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1523
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1524
	pData->flowControl = eFlowControlNone;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1525
	if (strcmp(pFlowControl, "software") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1526
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1527
		pData->flowControl = eFlowControlSW;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1528
	} 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1529
	else if (strcmp(pFlowControl, "hardware") == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1530
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1531
		pData->flowControl = eFlowControlHW;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1532
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1533
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1534
void ConvertRealSerialSettingsToHost(char* pBaud, char* pDataBits, char* pParity, char* pStopBits, char* pFlowControl, pRealSerialConnectData pData)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1535
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1536
	sprintf(pBaud, "%ld", pData->baudRate);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1537
	sprintf(pDataBits, "%ld", pData->dataBits);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1538
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1539
	switch (pData->parity)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1540
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1541
	default:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1542
	case eParityNone:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1543
		strcpy(pParity, "none");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1544
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1545
	case eParityEven:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1546
		strcpy(pParity, "even");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1547
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1548
	case eParityOdd:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1549
		strcpy(pParity, "odd");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1550
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1551
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1552
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1553
	switch (pData->stopBits)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1554
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1555
	default:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1556
	case eStopBits1:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1557
		strcpy(pStopBits, "1");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1558
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1559
	case eStopBits15:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1560
		strcpy(pStopBits, "1.5");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1561
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1562
	case eStopBits2:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1563
		strcpy(pStopBits, "2");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1564
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1565
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1566
	
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1567
	switch (pData->flowControl)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1568
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1569
	default:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1570
	case eFlowControlNone:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1571
		strcpy(pFlowControl, "none");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1572
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1573
	case eFlowControlHW:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1574
		strcpy(pFlowControl, "hardware");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1575
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1576
	case eFlowControlSW:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1577
		strcpy(pFlowControl, "software");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1578
		break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1579
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1580
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1581
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1582
#ifdef _DEBUG
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1583
void OpenLogFile1(char* filename)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1584
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1585
	if (fLog1 == NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1586
		fLog1 = _fsopen(filename, "at", _SH_DENYNO);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1587
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1588
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1589
void CloseLogFile1()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1590
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1591
	if (fLog1 != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1592
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1593
		fclose(fLog1);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1594
		fLog1 = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1595
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1596
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1597
void OpenLogFile2(char* filename)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1598
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1599
	if (fLog2 == NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1600
		fLog2 = _fsopen(filename, "at", _SH_DENYNO);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1601
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1602
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1603
void CloseLogFile2()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1604
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1605
	if (fLog2 != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1606
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1607
		fclose(fLog2);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1608
		fLog2 = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1609
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1610
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1611
void LogTime(FILE* f)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1612
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1613
	SYSTEMTIME sTime;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1614
	GetLocalTime(&sTime);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1615
	if (f)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1616
		fprintf(f, "%02.2d%02.2d-%02.2d:%02.2d:%02.2d.%03.3d: ", sTime.wDay, sTime.wMonth, sTime.wHour, sTime.wMinute, sTime.wSecond, sTime.wMilliseconds);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1617
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1618
#endif
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1619
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1620
static const char* GetErrorText(unsigned long error)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1621
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1622
	if (error == ERROR_FILE_NOT_FOUND)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1623
		return "Could not open the device\n";
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1624
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1625
	else if (error == ERROR_ACCESS_DENIED)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1626
		return "The device is currently in use\n";
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1627
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1628
	static char msg[256];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1629
	FormatMessage(
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1630
		FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1631
		NULL,
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1632
		error,
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1633
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1634
		(LPTSTR) &msg,
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1635
		sizeof(msg) - 1,
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1636
		NULL);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1637
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1638
	return msg;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1639
}