//------------------------------------------------------------------------------
void MobiCoreDriverDaemon::processCloseDevice(
    Connection  *connection
) {
	do
	{
		// there is no payload to read

		// Device required
		MobiCoreDevice *device = (MobiCoreDevice *) (connection->connectionData);
		if (NULL == device)
		{
			LOG_E("processCloseDevice(): no device");
			writeResult(connection, MC_DRV_RSP_DEVICE_NOT_OPENED);
			break;
		}

		// No command data will be read
		// Unregister device object with connection
		device->close(connection);

		// there is no payload
		writeResult(connection, MC_DRV_RSP_OK);

	} while (false);
}
//------------------------------------------------------------------------------
void MobiCoreDriverDaemon::dropConnection(
    Connection *connection
) {
	// Check if a Device has already been registered with the connection
	MobiCoreDevice *device = (MobiCoreDevice *) (connection->connectionData);

	if (device != NULL) {
		LOG_I("dropConnection(): closing still open device.");
		// A connection has been found and has to be closed
		device->close(connection);
	}
}
//------------------------------------------------------------------------------
void MobiCoreDriverDaemon::processCloseDevice(
    Connection  *connection
)
{
    // there is no payload to read

    // Device required
    MobiCoreDevice *device = (MobiCoreDevice *) (connection->connectionData);
    CHECK_DEVICE(device, connection);

    // No command data will be read
    // Unregister device object with connection
    device->close(connection);

    // there is no payload
    writeResult(connection, MC_DRV_OK);
}
//------------------------------------------------------------------------------
void MobiCoreDriverDaemon::dropConnection(
    Connection *connection
)
{
    // Check if a Device has already been registered with the connection
    MobiCoreDevice *device = (MobiCoreDevice *) (connection->connectionData);

    if (device != NULL) {
        // A connection has been found and has to be closed
        LOG_I("dropConnection(): closing still open device.");

        // Make sure nobody else writes the MCP, e.g. netlink/socket server, cleanup of TAs
        device->mutex_mcp.lock();
        device->close(connection);
        device->mutex_mcp.unlock();
    }
}