Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename CHIPConnection to CHIPUdpExchange #711

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ using namespace chip::Encoding;

ChipDeviceController::ChipDeviceController()
{
mState = kState_NotInitialized;
AppState = NULL;
mConState = kConnectionState_NotConnected;
mDeviceCon = NULL;
mCurReqMsg = NULL;
mOnError = NULL;
mDeviceAddr = IPAddress::Any;
mDevicePort = CHIP_PORT;
mDeviceId = 0;
mState = kState_NotInitialized;
AppState = NULL;
mConState = kConnectionState_NotConnected;
mUdpExchange = NULL;
mCurReqMsg = NULL;
mOnError = NULL;
mDeviceAddr = IPAddress::Any;
mDevicePort = CHIP_PORT;
mDeviceId = 0;
memset(&mOnComplete, 0, sizeof(mOnComplete));
}

Expand Down Expand Up @@ -103,11 +103,11 @@ CHIP_ERROR ChipDeviceController::Shutdown()
CHIP_ERROR err = CHIP_NO_ERROR;
mState = kState_NotInitialized;

if (mDeviceCon != NULL)
if (mUdpExchange != NULL)
{
mDeviceCon->Close();
delete mDeviceCon;
mDeviceCon = NULL;
mUdpExchange->Close();
delete mUdpExchange;
mUdpExchange = NULL;
}
mSystemLayer->Shutdown();
mInetLayer->Shutdown();
Expand All @@ -128,7 +128,7 @@ CHIP_ERROR ChipDeviceController::ConnectDevice(uint64_t deviceId, IPAddress devi
{
CHIP_ERROR err = CHIP_NO_ERROR;

if (mState != kState_Initialized || mDeviceCon != NULL || mConState != kConnectionState_NotConnected)
if (mState != kState_Initialized || mUdpExchange != NULL || mConState != kConnectionState_NotConnected)
{
return CHIP_ERROR_INCORRECT_STATE;
}
Expand All @@ -137,27 +137,27 @@ CHIP_ERROR ChipDeviceController::ConnectDevice(uint64_t deviceId, IPAddress devi
mDeviceAddr = deviceAddr;
mDevicePort = devicePort;
mAppReqState = appReqState;
mDeviceCon = new ChipConnection();
mUdpExchange = new ChipUdpExchange();

mDeviceCon->Init(mInetLayer);
err = mDeviceCon->Connect(mDeviceId, mDeviceAddr, mDevicePort);
mUdpExchange->Init(mInetLayer);
err = mUdpExchange->Connect(mDeviceId, mDeviceAddr, mDevicePort);
SuccessOrExit(err);

mDeviceCon->OnMessageReceived = OnReceiveMessage;
mDeviceCon->OnReceiveError = OnReceiveError;
mDeviceCon->AppState = this;
mUdpExchange->OnMessageReceived = OnReceiveMessage;
mUdpExchange->OnReceiveError = OnReceiveError;
mUdpExchange->AppState = this;

mOnComplete.Response = onMessageReceived;
mOnError = onError;

mConState = kConnectionState_Connected;

exit:
if (err != CHIP_NO_ERROR && mDeviceCon != NULL)
if (err != CHIP_NO_ERROR && mUdpExchange != NULL)
{
mDeviceCon->Close();
delete mDeviceCon;
mDeviceCon = NULL;
mUdpExchange->Close();
delete mUdpExchange;
mUdpExchange = NULL;
}
return err;
}
Expand All @@ -171,10 +171,10 @@ CHIP_ERROR ChipDeviceController::DisconnectDevice()
return CHIP_ERROR_INCORRECT_STATE;
}

err = mDeviceCon->Close();
delete mDeviceCon;
mDeviceCon = NULL;
mConState = kConnectionState_NotConnected;
err = mUdpExchange->Close();
delete mUdpExchange;
mUdpExchange = NULL;
mConState = kConnectionState_NotConnected;
return err;
};

Expand All @@ -185,7 +185,7 @@ CHIP_ERROR ChipDeviceController::SendMessage(void * appReqState, PacketBuffer *
mAppReqState = appReqState;
if (mConState == kConnectionState_Connected)
{
err = mDeviceCon->SendMessage(buffer);
err = mUdpExchange->SendMessage(buffer);
}

return err;
Expand Down Expand Up @@ -254,7 +254,7 @@ void ChipDeviceController::ClearRequestState()
}
}

void ChipDeviceController::OnReceiveMessage(ChipConnection * con, PacketBuffer * msgBuf, const IPPacketInfo * pktInfo)
void ChipDeviceController::OnReceiveMessage(ChipUdpExchange * con, PacketBuffer * msgBuf, const IPPacketInfo * pktInfo)
{
ChipDeviceController * mgr = (ChipDeviceController *) con->AppState;
if (mgr->mConState == kConnectionState_Connected && mgr->mOnComplete.Response != NULL && pktInfo != NULL)
Expand All @@ -263,7 +263,7 @@ void ChipDeviceController::OnReceiveMessage(ChipConnection * con, PacketBuffer *
}
}

void ChipDeviceController::OnReceiveError(ChipConnection * con, CHIP_ERROR err, const IPPacketInfo * pktInfo)
void ChipDeviceController::OnReceiveError(ChipUdpExchange * con, CHIP_ERROR err, const IPPacketInfo * pktInfo)
{
ChipDeviceController * mgr = (ChipDeviceController *) con->AppState;
if (mgr->mConState == kConnectionState_Connected && mgr->mOnError != NULL && pktInfo != NULL)
Expand Down
8 changes: 4 additions & 4 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <support/DLLUtil.h>
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
#include <core/CHIPConnection.h>
#include <core/CHIPUdpExchange.h>

namespace chip {
namespace DeviceController {
Expand Down Expand Up @@ -116,7 +116,7 @@ class DLL_EXPORT ChipDeviceController

System::Layer * mSystemLayer;
Inet::InetLayer * mInetLayer;
ChipConnection * mDeviceCon;
ChipUdpExchange * mUdpExchange;

ConnectionState mConState;
void * mAppReqState;
Expand All @@ -137,8 +137,8 @@ class DLL_EXPORT ChipDeviceController
void ClearRequestState();
void ClearOpState();

static void OnReceiveMessage(ChipConnection * con, PacketBuffer * msgBuf, const IPPacketInfo * pktInfo);
static void OnReceiveError(ChipConnection * con, CHIP_ERROR err, const IPPacketInfo * pktInfo);
static void OnReceiveMessage(ChipUdpExchange * con, PacketBuffer * msgBuf, const IPPacketInfo * pktInfo);
static void OnReceiveError(ChipUdpExchange * con, CHIP_ERROR err, const IPPacketInfo * pktInfo);
};

} // namespace DeviceController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
*
*/

#include <core/CHIPConnection.h>
#include <core/CHIPUdpExchange.h>
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>

#include <inttypes.h>

namespace chip {

ChipConnection::ChipConnection() : mState(kState_NotReady), mRefCount(1)
ChipUdpExchange::ChipUdpExchange() : mState(kState_NotReady), mRefCount(1)
{
mState = kState_NotReady;
mRefCount = 1;
Expand All @@ -45,7 +45,7 @@ ChipConnection::ChipConnection() : mState(kState_NotReady), mRefCount(1)
mPeerPort = 0;
}

void ChipConnection::Init(Inet::InetLayer * inetLayer)
void ChipUdpExchange::Init(Inet::InetLayer * inetLayer)
{
if (mState != kState_NotReady)
{
Expand All @@ -57,7 +57,7 @@ void ChipConnection::Init(Inet::InetLayer * inetLayer)

} // namespace chip

CHIP_ERROR ChipConnection::Connect(uint64_t peerNodeId, const IPAddress & peerAddr, uint16_t peerPort)
CHIP_ERROR ChipUdpExchange::Connect(uint64_t peerNodeId, const IPAddress & peerAddr, uint16_t peerPort)
{
CHIP_ERROR err = CHIP_NO_ERROR;

Expand All @@ -78,7 +78,7 @@ CHIP_ERROR ChipConnection::Connect(uint64_t peerNodeId, const IPAddress & peerAd
return err;
}

CHIP_ERROR ChipConnection::DoConnect()
CHIP_ERROR ChipUdpExchange::DoConnect()
{
CHIP_ERROR err = CHIP_NO_ERROR;

Expand Down Expand Up @@ -119,7 +119,7 @@ CHIP_ERROR ChipConnection::DoConnect()
return err;
}

CHIP_ERROR ChipConnection::SendMessage(PacketBuffer * msgBuf)
CHIP_ERROR ChipUdpExchange::SendMessage(PacketBuffer * msgBuf)
{
CHIP_ERROR err = CHIP_NO_ERROR;

Expand All @@ -143,10 +143,10 @@ CHIP_ERROR ChipConnection::SendMessage(PacketBuffer * msgBuf)
return err;
}

void ChipConnection::HandleDataReceived(IPEndPointBasis * endPoint, chip::System::PacketBuffer * msg, const IPPacketInfo * pktInfo)
void ChipUdpExchange::HandleDataReceived(IPEndPointBasis * endPoint, chip::System::PacketBuffer * msg, const IPPacketInfo * pktInfo)
{
UDPEndPoint * udpEndPoint = static_cast<UDPEndPoint *>(endPoint);
ChipConnection * connection = (ChipConnection *) udpEndPoint->AppState;
UDPEndPoint * udpEndPoint = static_cast<UDPEndPoint *>(endPoint);
ChipUdpExchange * connection = (ChipUdpExchange *) udpEndPoint->AppState;

// TODO this where where messages should be decoded
if (connection->StateAllowsReceive() && msg != NULL)
Expand All @@ -155,25 +155,25 @@ void ChipConnection::HandleDataReceived(IPEndPointBasis * endPoint, chip::System
}
}

void ChipConnection::HandleReceiveError(IPEndPointBasis * endPoint, CHIP_ERROR err, const IPPacketInfo * pktInfo)
void ChipUdpExchange::HandleReceiveError(IPEndPointBasis * endPoint, CHIP_ERROR err, const IPPacketInfo * pktInfo)
{
UDPEndPoint * udpEndPoint = static_cast<UDPEndPoint *>(endPoint);
ChipConnection * connection = (ChipConnection *) udpEndPoint->AppState;
UDPEndPoint * udpEndPoint = static_cast<UDPEndPoint *>(endPoint);
ChipUdpExchange * connection = (ChipUdpExchange *) udpEndPoint->AppState;
if (connection->StateAllowsReceive())
{
connection->OnReceiveError(connection, err, pktInfo);
}
}
/**
* Performs a non-blocking graceful close of the UDP based ChipConnection, delivering any
* Performs a non-blocking graceful close of the UDP based ChipUdpExchange, delivering any
* remaining outgoing data before resetting the connection.
*
* This method provides no strong guarantee that any outgoing message not acknowledged at the application
* protocol level has been received by the remote peer.
*
* Once Close() has been called, the ChipConnection object can no longer be used for further communication.
* Once Close() has been called, the ChipUdpExchange object can no longer be used for further communication.
*
* Calling Close() decrements the reference count associated with the ChipConnection object, whether or not
* Calling Close() decrements the reference count associated with the ChipUdpExchange object, whether or not
* the connection is open/active at the time the method is called. If this results in the reference count
* reaching zero, the resources associated with the connection object are freed. When this happens, the
* application must have no further interactions with the object.
Expand All @@ -183,20 +183,20 @@ void ChipConnection::HandleReceiveError(IPEndPointBasis * endPoint, CHIP_ERROR e
* @return #CHIP_NO_ERROR unconditionally.
*
*/
CHIP_ERROR ChipConnection::Close()
CHIP_ERROR ChipUdpExchange::Close()
{
// Perform a graceful close.
DoClose(CHIP_NO_ERROR);

// Decrement the ref count that was added when the ChipConnection object
// Decrement the ref count that was added when the ChipUdpExchange object
// was allocated.
VerifyOrDie(mRefCount != 0);
mRefCount--;

return CHIP_NO_ERROR;
}

void ChipConnection::DoClose(CHIP_ERROR err)
void ChipUdpExchange::DoClose(CHIP_ERROR err)
{
if (mState != kState_Closed)
{
Expand All @@ -223,26 +223,26 @@ void ChipConnection::DoClose(CHIP_ERROR err)
}

/**
* Reserve a reference to the ChipConnection object.
* Reserve a reference to the ChipUdpExchange object.
*
* The Retain() method increments the reference count associated with the ChipConnection object. For every
* The Retain() method increments the reference count associated with the ChipUdpExchange object. For every
* call to Retain(), the application is responsible for making a corresponding call to either Release(), Close()
* or Abort().
*/
void ChipConnection::Retain()
void ChipUdpExchange::Retain()
{
VerifyOrDie(mRefCount < UINT8_MAX);
++mRefCount;
}

/**
* Decrement the reference count on the ChipConnection object.
* Decrement the reference count on the ChipUdpExchange object.
*
* The Release() method decrements the reference count associated with the ChipConnection object. If
* The Release() method decrements the reference count associated with the ChipUdpExchange object. If
* this results in the reference count reaching zero, the connection is closed and the connection object
* is freed. When this happens, the application must have no further interactions with the object.
*/
void ChipConnection::Release()
void ChipUdpExchange::Release()
{
// If the only reference that will remain after this call is the one that was automatically added
// when the connection started, close the connection.
Expand All @@ -255,4 +255,4 @@ void ChipConnection::Release()
mRefCount--;
}

} // namespace chip
} // namespace chip
20 changes: 10 additions & 10 deletions src/lib/core/CHIPConnection.h → src/lib/core/CHIPUdpExchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*
*/

#ifndef __CHIPCONNECTION_H__
#define __CHIPCONNECTION_H__
#ifndef __CHIPUDPEXCHANGE_H__
#define __CHIPUDPEXCHANGE_H__

#include <core/CHIPCore.h>
#include <inet/IPAddress.h>
Expand All @@ -35,7 +35,7 @@ namespace chip {

using namespace System;

class DLL_EXPORT ChipConnection
class DLL_EXPORT ChipUdpExchange
{
public:
/**
Expand Down Expand Up @@ -90,7 +90,7 @@ class DLL_EXPORT ChipConnection

/**
* @brief
* Close an existing connection. Once close is called, the ChipConnection object can no longer be used
* Close an existing connection. Once close is called, the ChipUdpExchange object can no longer be used
*
* @return CHIP_ERROR The close result
*/
Expand All @@ -103,31 +103,31 @@ class DLL_EXPORT ChipConnection
* This function is the application callback that is invoked when a message is received over a
* Chip connection.
*
* @param[in] con A pointer to the ChipConnection object.
* @param[in] con A pointer to the ChipUdpExchange object.
*
* @param[in] msgBuf A pointer to the PacketBuffer object holding the message.
*
* @param[in] pktInfo A pointer to the IPPacketInfo object carrying sender details.
*
*/
typedef void (*MessageReceiveHandler)(ChipConnection * con, PacketBuffer * msgBuf, const IPPacketInfo * pktInfo);
typedef void (*MessageReceiveHandler)(ChipUdpExchange * con, PacketBuffer * msgBuf, const IPPacketInfo * pktInfo);
MessageReceiveHandler OnMessageReceived;

/**
* This function is the application callback invoked upon encountering an error when receiving
* a Chip message.
*
* @param[in] con A pointer to the ChipConnection object.
* @param[in] con A pointer to the ChipUdpExchange object.
*
* @param[in] err The CHIP_ERROR encountered when receiving data over the connection.
*
* @param[in] pktInfo A pointer to the IPPacketInfo object carrying sender details.
*
*/
typedef void (*ReceiveErrorHandler)(ChipConnection * con, CHIP_ERROR err, const IPPacketInfo * pktInfo);
typedef void (*ReceiveErrorHandler)(ChipUdpExchange * con, CHIP_ERROR err, const IPPacketInfo * pktInfo);
ReceiveErrorHandler OnReceiveError;

ChipConnection();
ChipUdpExchange();

private:
Inet::InetLayer * mInetLayer;
Expand All @@ -149,4 +149,4 @@ class DLL_EXPORT ChipConnection

} // namespace chip

#endif // __CHIPCONNECTION_H__
#endif // __CHIPUDPEXCHANGE_H__
Loading