Commit 79cd909a authored by Philippe Coval's avatar Philippe Coval

Merge branch '1.3-rel' (a7840d49)

Change-Id: I9ff7c633Signed-off-by: default avatarPhilippe Coval <philippe.coval@osg.samsung.com>
parents 1e70a844 a7840d49
......@@ -59,6 +59,7 @@ if env['CC'] == 'cl':
env.PrependUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'c_common', 'windows')])
env.PrependUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'oc_logger')])
env.PrependUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'csdk', 'resource-directory')])
env.PrependUnique(LIBPATH = ['#extlibs/mbedtls'])
env.AppendUnique(PATH = os.environ['PATH'])
env['PDB'] = '${TARGET.base}.pdb'
......
......@@ -308,6 +308,7 @@ typedef struct
std::mutex syncMutex;
std::condition_variable condVar;
IPCAStatus result;
bool callbackComplete;
} AsyncContext;
void IPCA_CALL AsyncCallback(
......@@ -318,6 +319,7 @@ void IPCA_CALL AsyncCallback(
OC_UNUSED(propertyBagHandle);
AsyncContext* async = reinterpret_cast<AsyncContext*>(context);
async->callbackComplete = true;
async->result = result;
async->condVar.notify_all();
}
......@@ -327,6 +329,7 @@ IPCAStatus IPCA_CALL IPCAFactoryReset(IPCADeviceHandle deviceHandle)
IPCAStatus status;
AsyncContext factoryResetContext;
factoryResetContext.callbackComplete = false;
std::unique_lock<std::mutex> lock { factoryResetContext.syncMutex };
IPCAPropertyBagHandle propertyBagHandle;
......@@ -356,7 +359,10 @@ IPCAStatus IPCA_CALL IPCAFactoryReset(IPCADeviceHandle deviceHandle)
if (status == IPCA_OK)
{
factoryResetContext.condVar.wait_for(lock, std::chrono::milliseconds{ INT_MAX });
factoryResetContext.condVar.wait_for(
lock,
std::chrono::milliseconds{ INT_MAX },
[&]{return factoryResetContext.callbackComplete;});
IPCAPropertyBagDestroy(propertyBagHandle);
return factoryResetContext.result;
}
......@@ -370,6 +376,7 @@ IPCAStatus IPCA_CALL IPCAReboot(IPCADeviceHandle deviceHandle)
IPCAStatus status;
AsyncContext rebootContext;
rebootContext.callbackComplete = false;
std::unique_lock<std::mutex> lock { rebootContext.syncMutex };
IPCAPropertyBagHandle propertyBagHandle;
......@@ -399,7 +406,10 @@ IPCAStatus IPCA_CALL IPCAReboot(IPCADeviceHandle deviceHandle)
if (status == IPCA_OK)
{
rebootContext.condVar.wait_for(lock, std::chrono::milliseconds{ INT_MAX });
rebootContext.condVar.wait_for(
lock,
std::chrono::milliseconds{ INT_MAX },
[&]{return rebootContext.callbackComplete;});
IPCAPropertyBagDestroy(propertyBagHandle);
return rebootContext.result;
}
......
......@@ -109,11 +109,7 @@ TEST(IoTivityDirect, IsIoTivityWorking)
// elevator server.
loopCount = 0;
const int TARGET_FLOOR = 3;
elevatorClient.SetTargetFloor(TARGET_FLOOR);
while ((loopCount++ < 20) && (g_testElevator1.GetCurrentFloor() != TARGET_FLOOR))
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
elevatorClient.SetTargetFloor(TARGET_FLOOR); // SetTargetFloor() is synchronous.
EXPECT_EQ(TARGET_FLOOR, g_testElevator1.GetCurrentFloor());
// Confirm able to get current floor using IoTivity client API. The current floor should be
......@@ -590,10 +586,11 @@ TEST_F(IPCAElevatorClient, SuccessfullyReceiveResourceChangeNotifications)
ASSERT_EQ(true, result);
// Wait until observed current floor is set to targeted floor.
// Outstanding requests should time out in 247 seconds (EXCHANGE_LIFETIME) per rfc 7252.
std::unique_lock<std::mutex> lock(m_resourceChangeCbMutex);
m_resourceChangeCbCV.wait_for(
lock,
std::chrono::seconds(10),
std::chrono::seconds(247),
[this] { return GetObservedCurrentFloor() == 10; });
EXPECT_EQ(10, GetObservedCurrentFloor()); // check it is at floor 10.
......
......@@ -83,12 +83,13 @@ bool ElevatorClient::StopObservation()
return result == OC_STACK_OK ? true : false;
}
const int DEFAULT_WAITTIME = 2000;
bool ElevatorClient::WaitForCallback(int waitingTime = DEFAULT_WAITTIME)
// Outstanding requests should time out in 247 seconds (EXCHANGE_LIFETIME) per rfc 7252.
const int DEFAULT_WAITTIME_MS = 247000;
bool ElevatorClient::WaitForCallback(int waitTimeMs = DEFAULT_WAITTIME_MS)
{
std::unique_lock<std::mutex> lock { syncMutex };
if (syncCV.wait_for(lock, std::chrono::milliseconds{ waitingTime }) != std::cv_status::timeout)
if (syncCV.wait_for(lock, std::chrono::milliseconds{ waitTimeMs }) != std::cv_status::timeout)
{
return true;
}
......
......@@ -37,6 +37,7 @@
#include "logger.h"
#include "oic_malloc.h"
#include "oic_string.h"
#include "iotivity_debug.h"
/**
* Logging tag for module name.
......@@ -331,6 +332,19 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
VERIFY_NON_NULL(handle, TAG, "thread pool handle");
#endif
#ifdef WSA_WAIT_EVENT_0
// Windows-specific initialization.
WORD wVersionRequested = MAKEWORD(2, 2);
WSADATA wsaData = {.wVersion = 0};
int err = WSAStartup(wVersionRequested, &wsaData);
if (0 != err)
{
OIC_LOG_V(ERROR, TAG, "%s: WSAStartup failed: %i", __func__, err);
return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "WSAStartup Succeeded");
#endif
g_networkChangeCallback = netCallback;
g_networkPacketCallback = networkPacketCallback;
g_errorCallback = errorCallback;
......@@ -534,6 +548,11 @@ void CATerminateIP()
CADeInitializeIPGlobals();
CAIPDeinitializeQueueHandles();
#endif
#ifdef WSA_WAIT_EVENT_0
// Windows-specific clean-up.
OC_VERIFY(0 == WSACleanup());
#endif
}
#ifndef SINGLE_THREAD
......
......@@ -479,7 +479,6 @@ static void CAFindReadyMessage()
if (caglobals.ip.terminate)
{
caglobals.ip.shutdownEvent = WSA_INVALID_EVENT;
WSACleanup();
}
}
......@@ -927,17 +926,6 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool)
{
return res;
}
#if defined (_WIN32)
WORD wVersionRequested = MAKEWORD(2, 2);
WSADATA wsaData ={.wVersion = 0};
int err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0)
{
OIC_LOG_V(ERROR, TAG, "WSAStartup failed: %i", err);
return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "WSAStartup Succeeded");
#endif
if (!IPv4MulticastAddress.s_addr)
{
(void)inet_pton(AF_INET, IPv4_MULTICAST, &IPv4MulticastAddress);
......@@ -987,7 +975,7 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool)
caglobals.ip.wsaRecvMsg = NULL;
GUID GuidWSARecvMsg = WSAID_WSARECVMSG;
DWORD copied = 0;
err = WSAIoctl(caglobals.ip.u4.fd, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidWSARecvMsg, sizeof(GuidWSARecvMsg), &(caglobals.ip.wsaRecvMsg), sizeof(caglobals.ip.wsaRecvMsg), &copied, 0, 0);
int err = WSAIoctl(caglobals.ip.u4.fd, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidWSARecvMsg, sizeof(GuidWSARecvMsg), &(caglobals.ip.wsaRecvMsg), sizeof(caglobals.ip.wsaRecvMsg), &copied, 0, 0);
if (0 != err)
{
OIC_LOG_V(ERROR, TAG, "WSAIoctl failed %i", WSAGetLastError());
......
......@@ -42,6 +42,7 @@
#ifdef __WITH_TLS__
#include "ca_adapter_net_ssl.h"
#endif
#include "iotivity_debug.h"
/**
* Logging tag for module name.
......@@ -344,6 +345,19 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
VERIFY_NON_NULL(handle, TAG, "thread pool handle");
#endif
#ifdef WSA_WAIT_EVENT_0
// Windows-specific initialization.
WORD wVersionRequested = MAKEWORD(2, 2);
WSADATA wsaData = {.wVersion = 0};
int err = WSAStartup(wVersionRequested, &wsaData);
if (0 != err)
{
OIC_LOG_V(ERROR, TAG, "%s: WSAStartup failed: %i", __func__, err);
return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "WSAStartup Succeeded");
#endif
g_networkChangeCallback = netCallback;
g_connectionChangeCallback = connCallback;
g_networkPacketCallback = networkPacketCallback;
......@@ -550,6 +564,11 @@ void CATerminateTCP()
{
CAStopTCP();
CATCPSetPacketReceiveCallback(NULL);
#ifdef WSA_WAIT_EVENT_0
// Windows-specific clean-up.
OC_VERIFY(0 == WSACleanup());
#endif
}
void CATCPSendDataThread(void *threadData)
......
......@@ -502,7 +502,6 @@ static void CAFindReadyMessage()
if (caglobals.tcp.terminate)
{
caglobals.tcp.updateEvent = WSA_INVALID_EVENT;
WSACleanup();
}
}
......
......@@ -220,6 +220,8 @@ if "!RUN_ARG!"=="server" (
REM Second: run tests if needed, using a single SCons thread.
if "!TEST!"=="1" (
echo.
echo Running Tests
echo.scons.bat -j 1 VERBOSE=1 TEST=1 %BUILD_OPTIONS%
call scons.bat -j 1 VERBOSE=1 TEST=1 %BUILD_OPTIONS%
if ERRORLEVEL 1 (
......
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment