You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
188 lines
6.5 KiB
188 lines
6.5 KiB
#include "protocolZLMEDIA.h"
|
|
#include "../json/json_tool.h"
|
|
#include <json/value.h>
|
|
#include <json/writer.h>
|
|
#include <json/reader.h>
|
|
|
|
#define LOG( X ) basicLogCollection::getInstance()->Log( "ZLMP", this, X )
|
|
#define LOG_ERROR( X ) basicLogCollection::getInstance()->Log( "ZLMP", this, _LOG_ERROR, X )
|
|
|
|
protocolZLMEDIA::protocolZLMEDIA( config_setting_t *Settings ): protocolHTTP( basicSettingsProvider::getInstance()->getSubNode(Settings, "ZLMEDIA_PROTOCOL") ){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "ZLMEDIA_PROTOCOL");
|
|
/*
|
|
if( m_pSettings != NULL ){
|
|
|
|
config_setting_t *pSetting;
|
|
|
|
if (!config_setting_lookup_string(m_pSettings, "SCANNER_NAME", (const char**)&m_pScannerName)){
|
|
strncpy( m_pScannerName, "LRF_2D_001", 64 );
|
|
LOG( m_pScannerName );
|
|
pSetting = config_setting_add(m_pSettings, "SCANNER_NAME", CONFIG_TYPE_STRING);
|
|
config_setting_set_string(pSetting, m_pScannerName);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_int(m_pSettings, "SCANNER_DIMENTIONS", &m_nScannerDimentions )){
|
|
m_nScannerDimentions = 2;
|
|
pSetting = config_setting_add(m_pSettings, "SCANNER_DIMENTIONS", CONFIG_TYPE_INT);
|
|
config_setting_set_int(pSetting, m_nScannerDimentions);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_string(m_pSettings, "LCU_IP_ADDRESS", (const char**)&m_pServerIP)){
|
|
strncpy( m_pServerIP, "192.168.200.204", 16 );
|
|
LOG( m_pServerIP );
|
|
pSetting = config_setting_add(m_pSettings, "LCU_IP_ADDRESS", CONFIG_TYPE_STRING);
|
|
config_setting_set_string(pSetting, m_pServerIP);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_int(m_pSettings, "LCU_IP_PORT", &m_nServerPort)){
|
|
m_nServerPort = 80;
|
|
pSetting = config_setting_add(m_pSettings, "LCU_IP_PORT", CONFIG_TYPE_INT);
|
|
config_setting_set_int(pSetting, m_nServerPort);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
|
|
basicSettingsProvider::getInstance()->validate();
|
|
|
|
}; //*/
|
|
};
|
|
|
|
protocolZLMEDIA::protocolZLMEDIA( CSTR key, CSTR host, CSTR ip, uint32_t port ): protocolHTTP( NULL ){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = NULL;
|
|
LOG("Param1");
|
|
strncpy( m_pSecret, key, 255 );
|
|
LOG("Param2");
|
|
strncpy( m_pAccessPoint, key, 255 );
|
|
LOG("Param3");
|
|
strncpy( m_pIP, ip, 16 );
|
|
LOG("Done!");
|
|
m_bSessionOnGo = false;
|
|
m_bServerIsPresent = false;
|
|
m_nPort = port;
|
|
m_bUseSSL = ( m_nPort == 433 );
|
|
LOG("Check Online!");
|
|
isOnline();
|
|
LOG("Done!");
|
|
};
|
|
|
|
protocolZLMEDIA::~protocolZLMEDIA(){
|
|
};
|
|
|
|
bool protocolZLMEDIA::packetHandler( protocolPackage *Package ){
|
|
LOG("Pack Handler!!");
|
|
if( Package == NULL ){
|
|
m_bSessionOnGo = false;
|
|
return false;
|
|
};
|
|
LOG("Pack not NULL");
|
|
if( Package->m_nSize == 0 ) {
|
|
m_bSessionOnGo = false;
|
|
return false;
|
|
};
|
|
LOG("Size not NULL");
|
|
if( Package->m_pData == NULL ){
|
|
m_bSessionOnGo = false;
|
|
return false;
|
|
};
|
|
LOG("Data not NULL");
|
|
if( Package->m_nCode != 200 ){
|
|
m_bSessionOnGo = false;
|
|
return false;
|
|
};
|
|
LOG("Code is 200");
|
|
m_bServerIsPresent = true;
|
|
try{
|
|
Json::Value root;
|
|
Json::Reader reader;
|
|
if( !reader.parse( (char *)Package->m_pData, root ) ){
|
|
LOG_ERROR( "Error parsing the string" );
|
|
m_bSessionOnGo = false;
|
|
return false;
|
|
};
|
|
for( Json::Value::const_iterator outer = root.begin() ; outer != root.end() ; outer++ ){
|
|
for( Json::Value::const_iterator inner = (*outer).begin() ; inner!= (*outer).end() ; inner++ ){
|
|
char tBuffer[256];
|
|
sprintf( tBuffer,"Data: %s: %s ", inner.key().asString().c_str(), (*inner).asString().c_str() );
|
|
LOG( tBuffer );
|
|
};
|
|
};
|
|
} catch (exception e ){
|
|
LOG_ERROR("Exception!!");
|
|
m_bSessionOnGo = false;
|
|
return false;
|
|
};
|
|
m_bSessionOnGo = false;
|
|
return true;
|
|
};
|
|
// Issue New Online Check but return current value
|
|
bool protocolZLMEDIA::isOnline(){
|
|
if( !m_bServerIsPresent ) { // Just First Time to set initial flag
|
|
if( !m_bSessionOnGo ) {
|
|
char URL[256];
|
|
uint8_t timeout = 100; // 1 sec.
|
|
m_bSessionOnGo = true;
|
|
if( m_bUseSSL ) {
|
|
sprintf(URL,"https://%s:%d/%s?secret=%s", m_pIP, m_nPort, ZL_LIST_API, m_pSecret );
|
|
} else {
|
|
sprintf(URL,"http://%s:%d/%s?secret=%s", m_pIP, m_nPort, ZL_LIST_API, m_pSecret ); //m_pAccessPoint
|
|
};
|
|
LOG( URL );
|
|
//ToDo: Check if OK to send nothing for checking Onlines
|
|
//int len = 0;
|
|
//issuePost( URL, NULL, len );
|
|
issueGet( URL );
|
|
while( m_bSessionOnGo && timeout-- ) SLEEP(10);
|
|
};
|
|
#ifdef DEBUG
|
|
if(m_bServerIsPresent) {
|
|
LOG("Server is Online");
|
|
} else {
|
|
LOG("Server is Onffline");
|
|
};
|
|
#endif
|
|
}
|
|
return m_bServerIsPresent;
|
|
};
|
|
bool protocolZLMEDIA::restartServer(){
|
|
return false;
|
|
};
|
|
bool protocolZLMEDIA::getConfig(){
|
|
return false;
|
|
};
|
|
CSTR protocolZLMEDIA::addStreamProxy(){
|
|
return NULL;
|
|
};
|
|
bool protocolZLMEDIA::delStreamProxy(CSTR key){
|
|
return false;
|
|
};
|
|
bool protocolZLMEDIA::listMedia(){
|
|
if( m_bServerIsPresent ) { // Just First Time to set initial flag
|
|
LOG("LIST MEDIA");
|
|
if( !m_bSessionOnGo ) {
|
|
char URL[256];
|
|
uint8_t timeout = 100; // 1 sec.
|
|
m_bSessionOnGo = true;
|
|
if( m_bUseSSL ) {
|
|
sprintf(URL,"https://%s:%d/%s?secret=%s", m_pIP, m_nPort, ZL_LIST_MEDIA, m_pSecret );
|
|
} else {
|
|
sprintf(URL,"http://%s:%d/%s?secret=%s", m_pIP, m_nPort, ZL_LIST_MEDIA, m_pSecret ); //m_pAccessPoint
|
|
};
|
|
LOG( URL );
|
|
//ToDo: Check if OK to send nothing for checking Onlines
|
|
//int len = 0;
|
|
//issuePost( URL, NULL, len );
|
|
issueGet( URL );
|
|
while( m_bSessionOnGo && timeout-- ) SLEEP(10);
|
|
return ( timeout > 0 );
|
|
} else LOG("LIST MEDIA - SESSION BUSY!");
|
|
};
|
|
return false;
|
|
};
|
|
bool protocolZLMEDIA::requestIsFinished(){
|
|
return (m_bSessionOnGo == false);
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|