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

Allow to use custom httpClient #2022

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions cpp/src/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Driver::Driver(string const& _controllerPath, ControllerInterface const& _interf
Options::Get()->GetOptionAsBool("IntervalBetweenPolls", &m_bIntervalBetweenPolls);

m_httpClient = new Internal::HttpClient(this);
m_httpClientIsExternal = false;

m_mfs = Internal::ManufacturerSpecificDB::Create();

Expand Down Expand Up @@ -295,7 +296,8 @@ Driver::~Driver()
m_eventMutex->Release();
delete this->AuthKey;
delete this->EncryptKey;
delete this->m_httpClient;
if(!m_httpClientIsExternal)
delete this->m_httpClient;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -6925,9 +6927,10 @@ void Driver::processConfigRevision(Internal::DNSLookup *result)

bool Driver::setHttpClient(Internal::i_HttpClient *client)
{
if (m_httpClient)
if (m_httpClient && !m_httpClientIsExternal)
delete m_httpClient;
m_httpClient = client;
m_httpClientIsExternal = true;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ namespace OpenZWave
bool refreshNodeConfig(uint8 node);
void processDownload(Internal::HttpDownload *);
Internal::i_HttpClient *m_httpClient;

bool m_httpClientIsExternal;
//-----------------------------------------------------------------------------
// Metadata Related
//-----------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions cpp/src/Http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ namespace OpenZWave
m_driver(driver)
{
}

i_HttpClient::i_HttpClient():
m_driver(NULL)
{

}
;

void i_HttpClient::FinishDownload(HttpDownload *transfer)
Expand All @@ -57,6 +63,11 @@ namespace OpenZWave
this->m_driver->SubmitEventMsg(event);
}

void i_HttpClient::SetDriver(Driver* driver)
{
m_driver = driver;
}

HttpClient::HttpClient(OpenZWave::Driver *drv) :
i_HttpClient(drv), m_exitEvent(new Internal::Platform::Event()), m_httpThread(new Internal::Platform::Thread("HttpThread")), m_httpThreadRunning(false), m_httpMutex(new Internal::Platform::Mutex()), m_httpDownloadEvent(new Internal::Platform::Event())
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/Http.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ namespace OpenZWave
{
public:
i_HttpClient(Driver *);
i_HttpClient();
virtual ~i_HttpClient()
{
}
;
virtual bool StartDownload(HttpDownload *transfer) = 0;
void FinishDownload(HttpDownload *transfer);
void SetDriver(Driver*);
private:
Driver* m_driver;
};
Expand Down
11 changes: 11 additions & 0 deletions cpp/src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "value_classes/ValueShort.h"
#include "value_classes/ValueString.h"
#include "value_classes/ValueBitSet.h"
#include "Http.h"

using namespace OpenZWave;

Expand Down Expand Up @@ -4898,3 +4899,13 @@ if (Driver *driver = GetDriver(_homeId))
return false;
}

bool Manager::setHttpClient(uint32 const _homeId, OpenZWave::Internal::i_HttpClient* httpClient)
{
if (Driver* driver = GetDriver(_homeId))
{
httpClient->SetDriver(driver);
driver->setHttpClient(httpClient);
return true;
}
return false;
}
3 changes: 3 additions & 0 deletions cpp/src/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace OpenZWave
class ValueStore;
}
class Msg;
class i_HttpClient;
}
class Options;
class Node;
Expand Down Expand Up @@ -2720,6 +2721,8 @@ namespace OpenZWave
*/
bool downloadLatestMFSRevision(uint32 const _homeId);


bool setHttpClient(uint32 const _homeId, OpenZWave::Internal::i_HttpClient*);
/*@}*/

};
Expand Down