diff --git a/DeviceIdentification/DeviceIdentification.cpp b/DeviceIdentification/DeviceIdentification.cpp index 4914ae1a..c27dc799 100644 --- a/DeviceIdentification/DeviceIdentification.cpp +++ b/DeviceIdentification/DeviceIdentification.cpp @@ -160,6 +160,7 @@ namespace Plugin { } } #else + ASSERT(_service != nullptr); // extract DeviceId set by Thunder if (_service->SubSystems()->IsActive(PluginHost::ISubSystem::IDENTIFIER) == true) { @@ -180,6 +181,7 @@ namespace Plugin { void DeviceIdentification::Info(JsonData::DeviceIdentification::DeviceidentificationData& deviceInfo) const { + ASSERT(_identifier != nullptr); deviceInfo.Firmwareversion = _identifier->FirmwareVersion(); deviceInfo.Chipset = _identifier->Chipset(); diff --git a/DeviceInfo/DeviceInfoJsonRpc.cpp b/DeviceInfo/DeviceInfoJsonRpc.cpp index ae644183..fe1870d4 100644 --- a/DeviceInfo/DeviceInfoJsonRpc.cpp +++ b/DeviceInfo/DeviceInfoJsonRpc.cpp @@ -246,9 +246,10 @@ namespace Plugin { { uint32_t result = Core::ERROR_NONE; string serialNumber; - result = _deviceInfo->SerialNumber(serialNumber); + ASSERT(_deviceInfo != nullptr); + result = _deviceInfo->SerialNumber(serialNumber); - response.Serialnumber = serialNumber; + response.Serialnumber = serialNumber; return result; } @@ -259,7 +260,8 @@ namespace Plugin { uint32_t DeviceInfo::endpoint_get_modelid(ModelidData& response) const { string sku; - uint32_t result = _deviceInfo->Sku(sku); + ASSERT(_deviceInfo != nullptr); + uint32_t result = _deviceInfo->Sku(sku); if (result == Core::ERROR_NONE) { Core::EnumerateType value(sku.c_str(), false); if (value.IsSet()) { @@ -279,7 +281,8 @@ namespace Plugin { // - ERROR_GENERAL: uint32_t DeviceInfo::endpoint_get_make(MakeData& response) const { - string make; + string make; + ASSERT(_deviceInfo != nullptr); uint32_t result = _deviceInfo->Make(make); if (result == Core::ERROR_NONE) { Core::EnumerateType value(make.c_str(), false); @@ -300,6 +303,7 @@ namespace Plugin { uint32_t DeviceInfo::endpoint_get_modelname(ModelnameData& response) const { string modelName; + ASSERT(_deviceInfo != nullptr); uint32_t result = _deviceInfo->ModelName(modelName); response.Model = modelName; @@ -313,8 +317,9 @@ namespace Plugin { uint32_t DeviceInfo::endpoint_get_modelyear(ModelyearData& response) const { uint16_t year; + ASSERT(_deviceInfo != nullptr); uint32_t result = _deviceInfo->ModelYear(year); - response.Year = year; + response.Year = year; return result; } @@ -326,6 +331,7 @@ namespace Plugin { uint32_t DeviceInfo::endpoint_get_friendlyname(FriendlynameInfo& response) const { string name; + ASSERT(_deviceInfo != nullptr); uint32_t result = _deviceInfo->FriendlyName(name); response.Name = name; @@ -339,6 +345,7 @@ namespace Plugin { uint32_t DeviceInfo::endpoint_get_platformname(FriendlynameInfo& response) const { string name; + ASSERT(_deviceInfo != nullptr); uint32_t result = _deviceInfo->PlatformName(name); response.Name = name; @@ -353,6 +360,7 @@ namespace Plugin { { string deviceType; + ASSERT(_deviceInfo != nullptr); uint32_t result = _deviceInfo->DeviceType(deviceType); if (result == Core::ERROR_NONE) { Core::EnumerateType value(deviceType.c_str(), false); @@ -375,6 +383,7 @@ namespace Plugin { { string distributorId; + ASSERT(_deviceInfo != nullptr); uint32_t result = _deviceInfo->DistributorId(distributorId); if (result == Core::ERROR_NONE) { Core::EnumerateType value(distributorId.c_str(), false); diff --git a/DisplayInfo/DeviceSettings/Amlogic/SoC_abstraction.cpp b/DisplayInfo/DeviceSettings/Amlogic/SoC_abstraction.cpp index 028d9e70..45207911 100644 --- a/DisplayInfo/DeviceSettings/Amlogic/SoC_abstraction.cpp +++ b/DisplayInfo/DeviceSettings/Amlogic/SoC_abstraction.cpp @@ -96,7 +96,7 @@ static void getPrimaryPlane(int drm_fd, kms_ctx *kms, drmModePlane **plane) kms_get_plane(drm_fd, kms); cout << "Primary Plane ID : "<< kms->primary_plane_id << endl; *plane = drmModeGetPlane(drm_fd, kms->primary_plane_id ); - if(*plane) + if (*plane) printf("fb id : %d\n", (*plane)->fb_id); } @@ -113,21 +113,21 @@ static void getGraphicSize(uint32_t &w, uint32_t &h) /* Setup KMS */ kms = kms_setup(drm_fd); - if(!kms || !kms->crtc ) { + if (!kms || !kms->crtc) { cout << "[Amlogic] kms_setup fail" << endl; break; } /* Get primary buffer */ getPrimaryPlane(drm_fd, kms, &plane); - if( !plane) { + if (!plane) { cout << "[Amlogic] fail to getPrimaryPlane" << endl; break; } /* get fb */ drmModeFB *fb = drmModeGetFB(drm_fd, plane->fb_id); - while(!fb) { + while (!fb) { getPrimaryPlane(drm_fd, kms, &plane); fb = drmModeGetFB(drm_fd, plane->fb_id); if (trytimes++ > 100) { @@ -137,7 +137,7 @@ static void getGraphicSize(uint32_t &w, uint32_t &h) } /* Get the width and height */ - if(fb) { + if (fb) { w = fb->width; h = fb->height; drmModeFreeFB(fb); @@ -146,7 +146,7 @@ static void getGraphicSize(uint32_t &w, uint32_t &h) /* release */ /* Cleanup buffer info */ - if(kms) { + if (kms) { kms_cleanup_context(kms); free(kms); } diff --git a/DisplayInfo/DeviceSettings/Amlogic/kms.c b/DisplayInfo/DeviceSettings/Amlogic/kms.c index 71f859ab..519cf61a 100644 --- a/DisplayInfo/DeviceSettings/Amlogic/kms.c +++ b/DisplayInfo/DeviceSettings/Amlogic/kms.c @@ -23,32 +23,33 @@ #include #include "kms.h" -void kms_setup_encoder( int fd, kms_ctx *kms ) +void kms_setup_encoder(int fd, kms_ctx *kms) { - for( int i = 0; i < kms->res->count_encoders; i++ ) { + if (kms != NULL && kms->res != NULL) { + for (int i = 0; i < kms->res->count_encoders; i++) { - kms->encoder = drmModeGetEncoder(fd,kms->res->encoders[i]); + kms->encoder = drmModeGetEncoder(fd,kms->res->encoders[i]); - if( !kms->encoder ) { - return; - } + if (!kms->encoder) { + return; + } - if ( kms->encoder->encoder_id == kms->connector->encoder_id ) { - - kms->encoder_id = kms->encoder->encoder_id; - return; - } + if (kms->encoder->encoder_id == kms->connector->encoder_id) { + kms->encoder_id = kms->encoder->encoder_id; + return; + } - for( int j = 0; j < kms->res->count_crtcs; j++ ) { + for (int j = 0; j < kms->res->count_crtcs; j++) { - if( kms->encoder->possible_crtcs & ( 1 << j ) ) { + if (kms->encoder->possible_crtcs & (1 << j)) { - drmModeFreeEncoder( kms->encoder ); - kms->encoder = drmModeGetEncoder(fd, kms->res->encoders[j]); + drmModeFreeEncoder(kms->encoder); + kms->encoder = drmModeGetEncoder(fd, kms->res->encoders[j]); - kms->encoder->crtc_id = kms->crtc_id = j; - goto exit; + kms->encoder->crtc_id = kms->crtc_id = j; + goto exit; + } } } } @@ -60,39 +61,41 @@ void kms_setup_encoder( int fd, kms_ctx *kms ) -void kms_setup_connector( int fd, kms_ctx *kms ) +void kms_setup_connector(int fd, kms_ctx *kms) { int i = 0; drmModeConnector *connector = NULL; - for( i = 0; i < kms->res->count_connectors; i++ ) { + if (kms != NULL && kms->res != NULL) { + for (i = 0; i < kms->res->count_connectors; i++) { - connector = drmModeGetConnector(fd, kms->res->connectors[i]); - if( connector ) { + connector = drmModeGetConnector(fd, kms->res->connectors[i]); + if (connector) { - if( connector->count_modes && ( connector->connection == DRM_MODE_CONNECTED ) ) { - break; + if (connector->count_modes && (connector->connection == DRM_MODE_CONNECTED)) { + break; + } } } - } - if ( connector ) { + if (connector) { - kms->connector = connector; - kms->connector_id = connector->connector_id; + kms->connector = connector; + kms->connector_id = connector->connector_id; + } } return; } -void kms_setup_crtc( int fd, kms_ctx *kms ) +void kms_setup_crtc(int fd, kms_ctx *kms) { - if( kms->encoder ) { + if (kms != NULL && kms->encoder) { kms->crtc = drmModeGetCrtc(fd, kms->encoder->crtc_id); - if( kms->crtc && kms->crtc->mode_valid ) { + if (kms->crtc && kms->crtc->mode_valid) { kms->current_info = kms->crtc->mode; kms->crtc_id = kms->encoder->crtc_id; @@ -103,11 +106,11 @@ void kms_setup_crtc( int fd, kms_ctx *kms ) } -kms_ctx* kms_setup( int fd ) +kms_ctx* kms_setup(int fd) { kms_ctx *kms = NULL; kms = (kms_ctx*)calloc(1,sizeof(*kms)); - if( !kms ) + if (!kms) assert(0); kms->res = drmModeGetResources(fd); @@ -119,19 +122,25 @@ kms_ctx* kms_setup( int fd ) } -void kms_cleanup_context( kms_ctx *kms ) +void kms_cleanup_context(kms_ctx *kms) { - if( kms->connector ) - drmModeFreeConnector(kms->connector); + if (kms != NULL) { + if (kms->connector) { + drmModeFreeConnector(kms->connector); + } - if( kms->encoder ) - drmModeFreeEncoder(kms->encoder); + if (kms->encoder) { + drmModeFreeEncoder(kms->encoder); + } - if( kms->crtc ) - drmModeFreeCrtc(kms->crtc); + if (kms->crtc) { + drmModeFreeCrtc(kms->crtc); + } - if( kms->res ) - drmModeFreeResources(kms->res); + if (kms->res) { + drmModeFreeResources(kms->res); + } + } } @@ -139,24 +148,24 @@ uint32_t kms_get_properties(int fd, drmModeObjectProperties *props, const char * { drmModePropertyPtr property; uint32_t i, id = 0; + if (props) { + for (i = 0; i < props->count_props; i++) { - for (i = 0; i < props->count_props; i++) { + property = drmModeGetProperty(fd, props->props[i]); + if (!strcmp(property->name, name)) + id = property->prop_id; - property = drmModeGetProperty(fd, props->props[i]); - if (!strcmp(property->name, name)) - id = property->prop_id; + drmModeFreeProperty(property); - drmModeFreeProperty(property); - - if ( id ) - return id; + if (id) + return id; + } } return id; } - -void kms_get_plane( int fd, kms_ctx *kms ) +void kms_get_plane(int fd, kms_ctx *kms) { int n = 0, j = 0; @@ -167,46 +176,48 @@ void kms_get_plane( int fd, kms_ctx *kms ) drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); - kms->primary_plane_id = kms->overlay_plane_id = -1; + if (kms) { + kms->primary_plane_id = kms->overlay_plane_id = -1; + } - planeRes = drmModeGetPlaneResources( fd ); - if ( planeRes ) { + planeRes = drmModeGetPlaneResources(fd); + if (planeRes) { - for( n= 0; n < planeRes->count_planes; ++n ) { + for (n= 0; n < planeRes->count_planes; ++n) { - plane = drmModeGetPlane( fd, planeRes->planes[n] ); + plane = drmModeGetPlane(fd, planeRes->planes[n]); - if ( plane ) { + if (plane) { - props = drmModeObjectGetProperties( fd, planeRes->planes[n], DRM_MODE_OBJECT_PLANE ); - if ( props ) { + props = drmModeObjectGetProperties(fd, planeRes->planes[n], DRM_MODE_OBJECT_PLANE); + if (props) { - for( j= 0; j < props->count_props; ++j ) { + for (j= 0; j < props->count_props; ++j) { - prop = drmModeGetProperty( fd, props->props[j] ); - if ( prop ) { + prop = drmModeGetProperty(fd, props->props[j]); + if (prop) { - if ( !strcmp( prop->name, "type") ) { + if (!strcmp(prop->name, "type")) { - if ( ( props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY ) && ( kms->primary_plane_id == -1 ) ) + if ((props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY) && (kms && kms->primary_plane_id == -1)) kms->primary_plane_id = planeRes->planes[n]; - else if ( ( props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY ) && ( kms->overlay_plane_id == -1 ) ) + else if ((props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY) && (kms && kms->overlay_plane_id == -1)) kms->overlay_plane_id = planeRes->planes[n]; } } - drmModeFreeProperty( prop ); + drmModeFreeProperty(prop); } } - drmModeFreeObjectProperties( props ); + drmModeFreeObjectProperties(props); } - drmModeFreePlane( plane ); + drmModeFreePlane(plane); } } - drmModeFreePlaneResources( planeRes ); + drmModeFreePlaneResources(planeRes); } diff --git a/DisplayInfo/DeviceSettings/Broadcom/SoC_abstraction.cpp b/DisplayInfo/DeviceSettings/Broadcom/SoC_abstraction.cpp index 505f3ecd..ca2e35a4 100644 --- a/DisplayInfo/DeviceSettings/Broadcom/SoC_abstraction.cpp +++ b/DisplayInfo/DeviceSettings/Broadcom/SoC_abstraction.cpp @@ -96,14 +96,14 @@ string parse_proc_brcm_core(string columnHeader) { while (getline(procfile,line)) { - if(line.find(columnHeader) != string::npos) + if (line.find(columnHeader) != string::npos) { tokens.clear(); sanitizeLine(line); tokenize(line, tokens, ' '); column = find(tokens.begin(), tokens.end(), columnHeader) - tokens.begin(); //found the column where the data can be found } - if(line.find("GFX") != string::npos) + if (line.find("GFX") != string::npos) { tokens.clear(); sanitizeLine(line); @@ -132,7 +132,7 @@ string parse_proc_brcm_display() { while (getline(procfile,line)) { - if(line.find("graphics") != string::npos) + if (line.find("graphics") != string::npos) { tokens.clear(); sanitizeLine(line); @@ -189,7 +189,7 @@ uint32_t SoC_GetGraphicsWidth() string value = parse_proc_brcm_display(); LOGINFO("graphics plane dimensions returned from proc = %s" , value.c_str()); tokenize(value, resolution, 'x'); // graphics resolution is in the format 1280x720 - if(resolution.size() > WIDTH) + if (resolution.size() > WIDTH) { try { @@ -212,7 +212,7 @@ uint32_t SoC_GetGraphicsHeight() string value = parse_proc_brcm_display(); LOGINFO("graphics plane dimensions returned from proc = %s" , value.c_str()); tokenize(value, resolution, 'x'); // graphics resolution is in the format 1280x720 - if(resolution.size() > HEIGHT) + if (resolution.size() > HEIGHT) { try { @@ -225,4 +225,4 @@ uint32_t SoC_GetGraphicsHeight() } } return ret; -} \ No newline at end of file +} diff --git a/DisplayInfo/DeviceSettings/PlatformImplementation.cpp b/DisplayInfo/DeviceSettings/PlatformImplementation.cpp index 0feac4b9..d14241cb 100644 --- a/DisplayInfo/DeviceSettings/PlatformImplementation.cpp +++ b/DisplayInfo/DeviceSettings/PlatformImplementation.cpp @@ -68,7 +68,7 @@ class DisplayInfoImplementation : device::Manager::Initialize(); TRACE(Trace::Information, (_T("device::Manager::Initialize success"))); } - catch(...) + catch (...) { TRACE(Trace::Error, (_T("device::Manager::Initialize failed"))); } @@ -154,7 +154,7 @@ class DisplayInfoImplementation : } } - if(DisplayInfoImplementation::_instance) + if (DisplayInfoImplementation::_instance) { DisplayInfoImplementation::_instance->ResolutionChangeImpl(eventtype); } @@ -165,7 +165,7 @@ class DisplayInfoImplementation : _adminLock.Lock(); std::list::const_iterator index = _observers.begin(); - while(index != _observers.end()) { + while (index != _observers.end()) { (*index)->Updated(eventtype); index++; } @@ -253,7 +253,7 @@ class DisplayInfoImplementation : int hdcpversion = 1; string portname; PortName(portname); - if(!portname.empty()) + if (!portname.empty()) { try { @@ -266,7 +266,7 @@ class DisplayInfoImplementation : case dsHDCP_VERSION_MAX: value = IConnectionProperties::HDCPProtectionType::HDCP_AUTO; break; } } - catch(const device::Exception& err) + catch (const device::Exception& err) { TRACE(Trace::Error, (_T("Exception during DeviceSetting library call. code = %d message = %s"), err.getCode(), err.what())); } @@ -283,7 +283,7 @@ class DisplayInfoImplementation : dsHdcpProtocolVersion_t hdcpversion = dsHDCP_VERSION_MAX; string portname; PortName(portname); - if(!portname.empty()) + if (!portname.empty()) { switch(value) { @@ -295,12 +295,12 @@ class DisplayInfoImplementation : try { device::VideoOutputPort vPort = device::Host::getInstance().getVideoOutputPort(portname); - if(!vPort.SetHdmiPreference(hdcpversion)) + if (!vPort.SetHdmiPreference(hdcpversion)) { TRACE(Trace::Information, (_T("HDCPProtection: SetHdmiPreference failed"))); } } - catch(const device::Exception& err) + catch (const device::Exception& err) { TRACE(Trace::Error, (_T("Exception during DeviceSetting library call. code = %d message = %s"), err.getCode(), err.what())); } @@ -320,7 +320,7 @@ class DisplayInfoImplementation : if (Core::ERROR_NONE == ret) { std::string strVideoPort = device::Host::getInstance().getDefaultVideoPortName(); - if(edidVec.size() > EDID_MAX_VERTICAL_SIZE) + if (edidVec.size() > EDID_MAX_VERTICAL_SIZE) { width = edidVec[EDID_MAX_HORIZONTAL_SIZE]; TRACE(Trace::Information, (_T("Width in cm = %d"), width)); @@ -346,7 +346,7 @@ class DisplayInfoImplementation : vPort.getDisplay().getEDIDBytes(edidVec); - if(edidVec.size() > EDID_MAX_VERTICAL_SIZE) + if (edidVec.size() > EDID_MAX_VERTICAL_SIZE) { height = edidVec[EDID_MAX_VERTICAL_SIZE]; TRACE(Trace::Information, (_T("Height in cm = %d"), height)); @@ -391,7 +391,7 @@ class DisplayInfoImplementation : } //convert to base64 uint16_t size = min(edidVec.size(), (size_t)numeric_limits::max()); - if(edidVec.size() > (size_t)numeric_limits::max()) + if (edidVec.size() > (size_t)numeric_limits::max()) LOGERR("Size too large to use ToString base64 wpe api"); int i = 0; for (; i < length && i < size; i++) @@ -420,7 +420,7 @@ class DisplayInfoImplementation : } } } - catch(const device::Exception& err) + catch (const device::Exception& err) { TRACE(Trace::Error, (_T("Exception during DeviceSetting library call. code = %d message = %s"), err.getCode(), err.what())); } @@ -482,19 +482,19 @@ class DisplayInfoImplementation : device::FrameRate fr = resolution.getFrameRate(); if (fr == device::FrameRate::k24 ) { rate = FRAMERATE_24; - } else if(fr == device::FrameRate::k25) { + } else if (fr == device::FrameRate::k25) { rate = FRAMERATE_25; - } else if(fr == device::FrameRate::k30) { + } else if (fr == device::FrameRate::k30) { rate = FRAMERATE_30; - } else if(fr == device::FrameRate::k60) { + } else if (fr == device::FrameRate::k60) { rate = FRAMERATE_60; - } else if(fr == device::FrameRate::k23dot98) { + } else if (fr == device::FrameRate::k23dot98) { rate = FRAMERATE_23_976; - } else if(fr == device::FrameRate::k29dot97) { + } else if (fr == device::FrameRate::k29dot97) { rate = FRAMERATE_29_97; - } else if(fr == device::FrameRate::k50) { + } else if (fr == device::FrameRate::k50) { rate = FRAMERATE_50; - } else if(fr == device::FrameRate::k59dot94) { + } else if (fr == device::FrameRate::k59dot94) { rate = FRAMERATE_59_94; } else { rate = FRAMERATE_UNKNOWN; @@ -679,16 +679,16 @@ class DisplayInfoImplementation : TRACE(Trace::Error, (_T("getTVHDRCapabilities failure: HDMI not connected!"))); } } - catch(const device::Exception& err) + catch (const device::Exception& err) { TRACE(Trace::Error, (_T("Exception during DeviceSetting library call. code = %d message = %s"), err.getCode(), err.what())); } - if(!capabilities) hdrCapabilities.push_back(HDR_OFF); - if(capabilities & dsHDRSTANDARD_HDR10) hdrCapabilities.push_back(HDR_10); - if(capabilities & dsHDRSTANDARD_HLG) hdrCapabilities.push_back(HDR_HLG); - if(capabilities & dsHDRSTANDARD_DolbyVision) hdrCapabilities.push_back(HDR_DOLBYVISION); - if(capabilities & dsHDRSTANDARD_TechnicolorPrime) hdrCapabilities.push_back(HDR_TECHNICOLOR); - if(capabilities & dsHDRSTANDARD_Invalid)hdrCapabilities.push_back(HDR_OFF); + if (!capabilities) hdrCapabilities.push_back(HDR_OFF); + if (capabilities & dsHDRSTANDARD_HDR10) hdrCapabilities.push_back(HDR_10); + if (capabilities & dsHDRSTANDARD_HLG) hdrCapabilities.push_back(HDR_HLG); + if (capabilities & dsHDRSTANDARD_DolbyVision) hdrCapabilities.push_back(HDR_DOLBYVISION); + if (capabilities & dsHDRSTANDARD_TechnicolorPrime) hdrCapabilities.push_back(HDR_TECHNICOLOR); + if (capabilities & dsHDRSTANDARD_Invalid)hdrCapabilities.push_back(HDR_OFF); type = Core::ServiceType::Create(hdrCapabilities); @@ -707,17 +707,16 @@ class DisplayInfoImplementation : device::VideoDevice &device = device::Host::getInstance().getVideoDevices().at(0); device.getHDRCapabilities(&capabilities); } - catch(const device::Exception& err) + catch (const device::Exception& err) { TRACE(Trace::Error, (_T("Exception during DeviceSetting library call. code = %d message = %s"), err.getCode(), err.what())); } - if(!capabilities) hdrCapabilities.push_back(HDR_OFF); - if(capabilities & dsHDRSTANDARD_HDR10) hdrCapabilities.push_back(HDR_10); - if(capabilities & dsHDRSTANDARD_HLG) hdrCapabilities.push_back(HDR_HLG); - if(capabilities & dsHDRSTANDARD_DolbyVision) hdrCapabilities.push_back(HDR_DOLBYVISION); - if(capabilities & dsHDRSTANDARD_TechnicolorPrime) hdrCapabilities.push_back(HDR_TECHNICOLOR); - if(capabilities & dsHDRSTANDARD_Invalid)hdrCapabilities.push_back(HDR_OFF); - + if (!capabilities) hdrCapabilities.push_back(HDR_OFF); + if (capabilities & dsHDRSTANDARD_HDR10) hdrCapabilities.push_back(HDR_10); + if (capabilities & dsHDRSTANDARD_HLG) hdrCapabilities.push_back(HDR_HLG); + if (capabilities & dsHDRSTANDARD_DolbyVision) hdrCapabilities.push_back(HDR_DOLBYVISION); + if (capabilities & dsHDRSTANDARD_TechnicolorPrime) hdrCapabilities.push_back(HDR_TECHNICOLOR); + if (capabilities & dsHDRSTANDARD_Invalid)hdrCapabilities.push_back(HDR_OFF); type = Core::ServiceType::Create(hdrCapabilities); return (type != nullptr ? Core::ERROR_NONE : Core::ERROR_GENERAL); @@ -741,7 +740,7 @@ class DisplayInfoImplementation : TRACE(Trace::Information, (_T("IsOutputHDR failure: HDMI not connected!"))); } } - catch(const device::Exception& err) + catch (const device::Exception& err) { TRACE(Trace::Error, (_T("Exception during DeviceSetting library call. code = %d message = %s"), err.getCode(), err.what())); } diff --git a/DisplayInfo/DeviceSettings/Realtek/kms.c b/DisplayInfo/DeviceSettings/Realtek/kms.c index 80b1405e..b716598f 100644 --- a/DisplayInfo/DeviceSettings/Realtek/kms.c +++ b/DisplayInfo/DeviceSettings/Realtek/kms.c @@ -23,34 +23,35 @@ #include #include "kms.h" -void kms_setup_encoder( int fd, kms_ctx *kms ) +void kms_setup_encoder(int fd, kms_ctx *kms) { int crtcId = 0; + if (kms != NULL && kms->res != NULL) { + for (int i = 0; i < kms->res->count_encoders; i++) { - for( int i = 0; i < kms->res->count_encoders; i++ ) { + kms->encoder = drmModeGetEncoder(fd,kms->res->encoders[i]); - kms->encoder = drmModeGetEncoder(fd,kms->res->encoders[i]); - if (!kms->encoder) { - return; - } + if (!kms->encoder) { + return; + } - if ( kms->encoder->encoder_id == kms->connector->encoder_id ) { - - kms->encoder_id = kms->encoder->encoder_id; - return; - } + if (kms->encoder->encoder_id == kms->connector->encoder_id) { + kms->encoder_id = kms->encoder->encoder_id; + return; + } - for( int j = 0; j < kms->res->count_crtcs; j++ ) { + for (int j = 0; j < kms->res->count_crtcs; j++) { - if( kms->encoder->possible_crtcs & ( 1 << j ) ) { + if (kms->encoder->possible_crtcs & (1 << j)) { - drmModeFreeEncoder( kms->encoder ); - kms->encoder = drmModeGetEncoder(fd, kms->res->encoders[j]); + drmModeFreeEncoder(kms->encoder); + kms->encoder = drmModeGetEncoder(fd, kms->res->encoders[j]); - crtcId = kms->res->crtcs[j]; - kms->encoder->crtc_id = kms->crtc_id = j; - goto exit; + crtcId = kms->res->crtcs[j]; + kms->encoder->crtc_id = kms->crtc_id = j; + goto exit; + } } } } @@ -62,39 +63,41 @@ void kms_setup_encoder( int fd, kms_ctx *kms ) -void kms_setup_connector( int fd, kms_ctx *kms ) +void kms_setup_connector(int fd, kms_ctx *kms) { int i = 0, j = 0; - drmModeConnector *connector; + drmModeConnector *connector = NULL; - for( i = 0; i < kms->res->count_connectors; i++ ) { + if (kms != NULL && kms->res != NULL) { + for (i = 0; i < kms->res->count_connectors; i++) { - connector = drmModeGetConnector(fd, kms->res->connectors[i]); - if( connector ) { + connector = drmModeGetConnector(fd, kms->res->connectors[i]); + if (connector) { - if( connector->count_modes && ( connector->connection == DRM_MODE_CONNECTED ) ) { - break; + if (connector->count_modes && (connector->connection == DRM_MODE_CONNECTED)) { + break; + } } } - } - if ( connector ) { + if (connector) { - kms->connector = connector; - kms->connector_id = connector->connector_id; + kms->connector = connector; + kms->connector_id = connector->connector_id; + } } return; } -void kms_setup_crtc( int fd, kms_ctx *kms ) +void kms_setup_crtc(int fd, kms_ctx *kms) { - if( kms->encoder ) { + if (kms != NULL && kms->encoder) { kms->crtc = drmModeGetCrtc(fd, kms->encoder->crtc_id); - if( kms->crtc && kms->crtc->mode_valid ) { + if (kms->crtc && kms->crtc->mode_valid) { kms->current_info = kms->crtc->mode; kms->crtc_id = kms->encoder->crtc_id; @@ -105,11 +108,11 @@ void kms_setup_crtc( int fd, kms_ctx *kms ) } -kms_ctx* kms_setup( int fd ) +kms_ctx* kms_setup(int fd) { kms_ctx *kms = NULL; kms = (kms_ctx*)calloc(1,sizeof(*kms)); - if( !kms ) + if (!kms) assert(0); kms->res = drmModeGetResources(fd); @@ -121,19 +124,25 @@ kms_ctx* kms_setup( int fd ) } -void kms_cleanup_context( kms_ctx *kms ) +void kms_cleanup_context(kms_ctx *kms) { - if( kms->connector ) - drmModeFreeConnector(kms->connector); + if (kms != NULL) { + if (kms->connector) { + drmModeFreeConnector(kms->connector); + } - if( kms->encoder ) - drmModeFreeEncoder(kms->encoder); + if (kms->encoder) { + drmModeFreeEncoder(kms->encoder); + } - if( kms->crtc ) - drmModeFreeCrtc(kms->crtc); + if (kms->crtc) { + drmModeFreeCrtc(kms->crtc); + } - if( kms->res ) - drmModeFreeResources(kms->res); + if (kms->res) { + drmModeFreeResources(kms->res); + } + } } @@ -141,23 +150,25 @@ uint32_t kms_get_properties(int fd, drmModeObjectProperties *props, const char * { drmModePropertyPtr property; uint32_t i, id = 0; + if (props) { + for (i = 0; i < props->count_props; i++) { - for (i = 0; i < props->count_props; i++) { - - property = drmModeGetProperty(fd, props->props[i]); - if (!strcmp(property->name, name)) - id = property->prop_id; + property = drmModeGetProperty(fd, props->props[i]); + if (!strcmp(property->name, name)) + id = property->prop_id; - drmModeFreeProperty(property); + drmModeFreeProperty(property); - if ( id ) - return id; + if (id) + return id; + } } + return id; } -void kms_get_plane( int fd, kms_ctx *kms ) +void kms_get_plane(int fd, kms_ctx *kms) { int len = 0, n = 0, j = 0, plane_index = -1; @@ -168,47 +179,49 @@ void kms_get_plane( int fd, kms_ctx *kms ) drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); - kms->primary_plane_id = kms->overlay_plane_id = -1; + if (kms) { + kms->primary_plane_id = kms->overlay_plane_id = -1; + } - planeRes = drmModeGetPlaneResources( fd ); - if ( planeRes ) { + planeRes = drmModeGetPlaneResources(fd); + if (planeRes) { - for( n= 0; n < planeRes->count_planes; ++n ) { + for (n= 0; n < planeRes->count_planes; ++n) { - plane = drmModeGetPlane( fd, planeRes->planes[n] ); + plane = drmModeGetPlane(fd, planeRes->planes[n]); - if ( plane ) { + if (plane) { - props = drmModeObjectGetProperties( fd, planeRes->planes[n], DRM_MODE_OBJECT_PLANE ); - if ( props ) { + props = drmModeObjectGetProperties(fd, planeRes->planes[n], DRM_MODE_OBJECT_PLANE); + if (props) { - for( j= 0; j < props->count_props; ++j ) { + for (j= 0; j < props->count_props; ++j) { - prop = drmModeGetProperty( fd, props->props[j] ); - if ( prop ) { + prop = drmModeGetProperty(fd, props->props[j]); + if (prop) { len = strlen(prop->name); - if ( !strcmp( prop->name, "type") ) { + if (!strcmp(prop->name, "type")) { - if ( ( props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY ) && ( kms->primary_plane_id == -1 ) ) + if ((props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY) && (kms->primary_plane_id == -1)) kms->primary_plane_id = planeRes->planes[n]; - else if ( ( props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY ) && ( kms->overlay_plane_id == -1 ) ) + else if ((props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY) && (kms->overlay_plane_id == -1)) kms->overlay_plane_id = planeRes->planes[n]; } } - drmModeFreeProperty( prop ); + drmModeFreeProperty(prop); } } - drmModeFreeObjectProperties( props ); + drmModeFreeObjectProperties(props); } - drmModeFreePlane( plane ); + drmModeFreePlane(plane); } } - drmModeFreePlaneResources( planeRes ); + drmModeFreePlaneResources(planeRes); } diff --git a/DisplayInfo/DisplayInfo.h b/DisplayInfo/DisplayInfo.h index fc2669cd..7bab00e7 100644 --- a/DisplayInfo/DisplayInfo.h +++ b/DisplayInfo/DisplayInfo.h @@ -39,6 +39,7 @@ namespace Plugin { explicit Notification(DisplayInfo* parent) : _parent(*parent) + , _client(nullptr) { ASSERT(parent != nullptr); } diff --git a/DisplayInfo/Linux/PlatformImplementation.cpp b/DisplayInfo/Linux/PlatformImplementation.cpp index 4f311530..ad2a4f6f 100644 --- a/DisplayInfo/Linux/PlatformImplementation.cpp +++ b/DisplayInfo/Linux/PlatformImplementation.cpp @@ -99,7 +99,7 @@ namespace Plugin { ~UdevObserverType() override { - if(Core::SocketDatagram::IsOpen()) { + if (Core::SocketDatagram::IsOpen()) { Core::SocketDatagram::Close(Core::infinite); } } @@ -415,7 +415,7 @@ namespace Plugin { std::ifstream instream(_edidNode, std::ios::in); _edid.reserve(512); - if(instream.is_open()) { + if (instream.is_open()) { char asciiHexByte[2]; while(!instream.eof()) { instream.read(asciiHexByte, 2); @@ -457,7 +457,7 @@ namespace Plugin { : _config() , _udevObserver() , _callback([&](const std::string& devtype){ - if(devtype == "hdcp") { + if (devtype == "hdcp") { _eventQueue.Post(Exchange::IConnectionProperties::INotification::Source::HDCP_CHANGE); } else { _eventQueue.Post(Exchange::IConnectionProperties::INotification::Source::HDMI_CHANGE); @@ -739,7 +739,7 @@ namespace Plugin { bool Post(IConnectionProperties::INotification::Source type) { - if(_eventQueue.Post(type)) { + if (_eventQueue.Post(type)) { _arrived.SetEvent(); return true; } else { diff --git a/DisplayInfo/RPI/PlatformImplementation.cpp b/DisplayInfo/RPI/PlatformImplementation.cpp index 27d9975c..da6e621b 100644 --- a/DisplayInfo/RPI/PlatformImplementation.cpp +++ b/DisplayInfo/RPI/PlatformImplementation.cpp @@ -47,6 +47,7 @@ class DisplayInfoImplementation : public Exchange::IHDRProperties, , _audioPassthrough(false) , _EDID() , _value(HDCP_Unencrypted) + , _observers() , _adminLock() , _activity(*this) { diff --git a/LocationSync/LocationService.cpp b/LocationSync/LocationService.cpp index 6c8c6696..fedea0c9 100644 --- a/LocationSync/LocationService.cpp +++ b/LocationSync/LocationService.cpp @@ -385,6 +385,8 @@ POP_WARNING() } _tryInterval = retryTimeSpan * 1000; // Move from seconds to mS. + + ASSERT(_request.IsValid() == true); _request->Host = hostName; _request->Verb = Web::Request::HTTP_GET; _request->Path = _T("/"); @@ -433,7 +435,7 @@ POP_WARNING() _state = FAILED; } - if(_infoCarrier.IsValid() == true) { + if (_infoCarrier.IsValid() == true) { _infoCarrier.Release(); } @@ -443,6 +445,7 @@ POP_WARNING() // Methods to extract and insert data into the socket buffers void LocationService::LinkBody(Core::ProxyType& element) /* override */ { + ASSERT(element.IsValid() == true); if (element->ErrorCode == Web::STATUS_OK) { ASSERT(_infoCarrier.IsValid() == true); @@ -453,6 +456,7 @@ POP_WARNING() void LocationService::Received(Core::ProxyType& element) /* override */ { + ASSERT(element.IsValid() == true); Core::ProxyType textInfo = element->Body(); if (textInfo.IsValid() == false) { @@ -460,6 +464,7 @@ POP_WARNING() } else { + ASSERT(_infoCarrier.IsValid() == true); _infoCarrier->FromString(*textInfo); _adminLock.Lock(); @@ -501,8 +506,6 @@ POP_WARNING() _state = LOADING; } - ASSERT(_infoCarrier.IsValid() == true); - _infoCarrier.Release(); _adminLock.Unlock(); @@ -611,6 +614,8 @@ POP_WARNING() TRACE(Trace::Error, (_T("LocationSync: Network connectivity could *NOT* be established. Falling back to IPv4. %d"), __LINE__)); + + ASSERT(_infoCarrier.IsValid() == true); _infoCarrier.Release(); dispatch = true; @@ -620,6 +625,7 @@ POP_WARNING() } if (dispatch == true) { + ASSERT(_callback != nullptr); _callback->Dispatch(); } diff --git a/LocationSync/LocationSync.cpp b/LocationSync/LocationSync.cpp index cf17e8a3..21c4eba1 100644 --- a/LocationSync/LocationSync.cpp +++ b/LocationSync/LocationSync.cpp @@ -64,16 +64,17 @@ POP_WARNING() { string result; Config config; + ASSERT(service != nullptr); config.FromString(service->ConfigLine()); if (LocationService::IsSupported(config.Source.Value()) == Core::ERROR_NONE) { - if( ( config.TimeZone.IsSet() == true ) && ( config.TimeZone.Value().empty() == false ) ) { + if ((config.TimeZone.IsSet() == true) && (config.TimeZone.Value().empty() == false)) { _locationinfo.TimeZone(config.TimeZone.Value()); _timezoneoverriden = true; UpdateSystemTimeZone(config.TimeZone.Value()); } - if( ( config.Latitude.IsSet() == true ) && ( config.Longitude.IsSet() == true ) ) { + if ((config.Latitude.IsSet() == true) && (config.Longitude.IsSet() == true)) { _locationinfo.Latitude(config.Latitude.Value()); _locationinfo.Longitude(config.Longitude.Value()); } @@ -83,7 +84,7 @@ POP_WARNING() _activateOnFailure = config.ActivateOnFailure.Value(); _service = service; _service->AddRef(); - + _sink.Initialize(config.Source.Value(), config.Interval.Value(), config.Retries.Value()); RegisterAll(); @@ -112,13 +113,15 @@ POP_WARNING() Exchange::Controller::IConfiguration* controller = nullptr; if ( (_timezoneoverriden == true) && - ( _locationinfo.TimeZone() != config.TimeZone.Value() ) && - ( ( controller = _service->QueryInterfaceByCallsign(_T("")) ) != nullptr ) + ( _locationinfo.TimeZone() != config.TimeZone.Value()) && + ( ( controller = _service->QueryInterfaceByCallsign(_T(""))) != nullptr) ) { config.TimeZone = _locationinfo.TimeZone(); string newconfig; config.ToString(newconfig); _service->ConfigLine(newconfig); + + ASSERT(controller != nullptr); controller->Persist(); controller->Release(); } @@ -240,7 +243,7 @@ POP_WARNING() _timezoneoverriden = true; - if(_locationinfo.TimeZone() != timeZone) { + if (_locationinfo.TimeZone() != timeZone) { _locationinfo.TimeZone(timeZone); @@ -251,7 +254,7 @@ POP_WARNING() // let's check if we need to update the subsystem. As there is no support in this plugin for unsetting the Location subsystem that is not taken into account PluginHost::ISubSystem* subSystem = _service->SubSystems(); ASSERT(subSystem != nullptr); - if(subSystem != nullptr) { + if (subSystem != nullptr) { SetLocationSubsystem(*subSystem, true); subSystem->Release(); } @@ -282,13 +285,13 @@ POP_WARNING() } void LocationSync::SetLocationSubsystem(PluginHost::ISubSystem& subsystem, bool update) /* cannot be const due to subsystem Set*/ { - if(update == false) { + if (update == false) { _adminLock.Lock(); subsystem.Set(PluginHost::ISubSystem::LOCATION, &_locationinfo); _adminLock.Unlock(); } else { _adminLock.Lock(); - if(subsystem.IsActive(PluginHost::ISubSystem::LOCATION) == true) { + if (subsystem.IsActive(PluginHost::ISubSystem::LOCATION) == true) { subsystem.Set(PluginHost::ISubSystem::LOCATION, &_locationinfo); } _adminLock.Unlock(); @@ -300,42 +303,42 @@ POP_WARNING() if ((_sink.Location() != nullptr) && (_sink.Valid() == true)) { // _sink.Location() != nullptr basically is always true string newtimezone; _adminLock.Lock(); - if( (_locationinfo.Latitude() == std::numeric_limits::min()) || (_locationinfo.Longitude() == std::numeric_limits::min()) ) { + if ((_locationinfo.Latitude() == std::numeric_limits::min()) || (_locationinfo.Longitude() == std::numeric_limits::min())) { _locationinfo.Latitude(_sink.Location()->Latitude()); _locationinfo.Longitude(_sink.Location()->Longitude()); - } + } _locationinfo.Country(_sink.Location()->Country()); _locationinfo.Region(_sink.Location()->Region()); _locationinfo.City(_sink.Location()->City()); - if( (_sink.Location()->TimeZone().empty() == false) && (_timezoneoverriden == false) ) { + if ((_sink.Location()->TimeZone().empty() == false) && (_timezoneoverriden == false)) { newtimezone = _sink.Location()->TimeZone(); _locationinfo.TimeZone(newtimezone); } _adminLock.Unlock(); - if(newtimezone.empty() == false) { + if (newtimezone.empty() == false) { UpdateSystemTimeZone(newtimezone); NotifyTimeZoneChanged(newtimezone); } } else { _adminLock.Lock(); // if they are not overriden in the config and we cannot get them from the lookup, set them to default - if( (_locationinfo.Latitude() == std::numeric_limits::min()) || (_locationinfo.Longitude() == std::numeric_limits::min()) ) { + if ((_locationinfo.Latitude() == std::numeric_limits::min()) || (_locationinfo.Longitude() == std::numeric_limits::min())) { _locationinfo.Latitude(51977956); _locationinfo.Longitude(5726384); - } + } _adminLock.Unlock(); } PluginHost::ISubSystem* subSystem = _service->SubSystems(); ASSERT(subSystem != nullptr); - if (subSystem != nullptr) { - if( (_activateOnFailure == true) || (_sink.Location() == nullptr) || ( _sink.Valid() == true ) ) { // again _sink.Location() == nullptr should not happen but added to make it backards compatibe + if (subSystem != nullptr) { + if ((_activateOnFailure == true) || (_sink.Location() == nullptr) || (_sink.Valid() == true)) { // again _sink.Location() == nullptr should not happen but added to make it backards compatibe subSystem->Set(PluginHost::ISubSystem::INTERNET, _sink.Network()); SetLocationSubsystem(*subSystem, false); event_locationchange(); - } else if(_timezoneoverriden == true) { // if the probing failed but the timezone was explicitely set we only set the location subsystem to pass on the timezone info + } else if (_timezoneoverriden == true) { // if the probing failed but the timezone was explicitely set we only set the location subsystem to pass on the timezone info SetLocationSubsystem(*subSystem, false); event_locationchange(); } @@ -343,9 +346,9 @@ POP_WARNING() } } - void LocationSync::UpdateSystemTimeZone(const string& newtimezone) + void LocationSync::UpdateSystemTimeZone(const string& newtimezone) { - if( newtimezone != FactorySetTimeZone ) { + if (newtimezone != FactorySetTimeZone) { Core::SystemInfo::Instance().SetTimeZone(newtimezone, false); } } diff --git a/LocationSync/LocationSync.h b/LocationSync/LocationSync.h index b96e9d81..1db8e96d 100644 --- a/LocationSync/LocationSync.h +++ b/LocationSync/LocationSync.h @@ -85,6 +85,7 @@ PUSH_WARNING(DISABLE_WARNING_THIS_IN_MEMBER_INITIALIZER_LIST) POP_WARNING() ~Notification() { + ASSERT(_locator != nullptr); _locator->Release(); } @@ -285,13 +286,13 @@ POP_WARNING() void UpdateSystemTimeZone(const string& timezone); private: - using TimeZoneObservers = std::list; + using TimeZoneObservers = std::list; uint16_t _skipURL; string _source; Core::SinkType _sink; - PluginHost::IShell* _service; - bool _timezoneoverriden; + PluginHost::IShell* _service; + bool _timezoneoverriden; Core::SinkType _locationinfo; mutable Core::CriticalSection _adminLock; TimeZoneObservers _timezoneoberservers; diff --git a/MessageControl/MessageOutput.cpp b/MessageControl/MessageOutput.cpp index 2ede4f3a..eaae8143 100644 --- a/MessageControl/MessageOutput.cpp +++ b/MessageControl/MessageOutput.cpp @@ -60,7 +60,7 @@ namespace Publishers { ExtraOutputOptions options = _outputOptions; if ((AsNumber(options) & AsNumber(ExtraOutputOptions::PAUSED)) == 0) { - + if ((AsNumber(options) & AsNumber(ExtraOutputOptions::CATEGORY)) != 0) { data.Category = metadata.Category(); } @@ -114,6 +114,7 @@ namespace Publishers { : Core::SocketDatagram(false, nodeId.Origin(), nodeId, Messaging::MessageUnit::Instance().DataSize(), 0) , _loaded(0) { + ::memset(_sendBuffer, 0, sizeof(_sendBuffer)); } UDPOutput::Channel::~Channel() { Close(Core::infinite); diff --git a/Messenger/Messenger.cpp b/Messenger/Messenger.cpp index 3869a270..6c5aa188 100644 --- a/Messenger/Messenger.cpp +++ b/Messenger/Messenger.cpp @@ -57,7 +57,7 @@ namespace Plugin { _service->Register(static_cast(&_notification)); _roomAdmin = service->Root(_connectionId, 2000, _T("RoomMaintainer")); - if(_roomAdmin == nullptr) { + if (_roomAdmin == nullptr) { message = _T("RoomMaintainer couldnt be instantiated"); } else { @@ -124,11 +124,10 @@ namespace Plugin { roomId = GenerateRoomId(roomName, userName); ASSERT(roomId.empty() == false); - MsgNotification* sink = Core::ServiceType::Create(*this, roomId); - ASSERT(sink != nullptr); if (sink != nullptr) { - Exchange::IRoomAdministrator::IRoom* room = _roomAdmin->Join(roomName, userName, sink); + ASSERT(sink != nullptr); + MsgNotification* sink = Core::ServiceType::Create(*this, roomId); // Note: Join() can return nullptr if the user has already joined the room. if (room != nullptr) { diff --git a/Messenger/MessengerSecurity.cpp b/Messenger/MessengerSecurity.cpp index c8f19877..68f8c32a 100644 --- a/Messenger/MessengerSecurity.cpp +++ b/Messenger/MessengerSecurity.cpp @@ -32,6 +32,7 @@ namespace { { bool result = false; + ASSERT(service != nullptr); auto auth = service->QueryInterfaceByCallsign("SecurityAgent"); if (auth != nullptr) { string encoded; @@ -122,6 +123,7 @@ namespace Plugin { if (!aclSet) { TRACE(Trace::Information, (_T("Joining room '%s' w/o ACL"), room.c_str())); + ASSERT(_service != nullptr); if (!settingAcl || index.Count() == 0) { TRACE(Trace::Error, (_T("ACL is empty"))); diff --git a/Monitor/Monitor.cpp b/Monitor/Monitor.cpp index 69fd3042..ce04f58d 100644 --- a/Monitor/Monitor.cpp +++ b/Monitor/Monitor.cpp @@ -42,6 +42,7 @@ namespace Plugin { /* virtual */ const string Monitor::Initialize(PluginHost::IShell* service) { + ASSERT(service != nullptr); _config.FromString(service->ConfigLine()); @@ -63,6 +64,8 @@ namespace Plugin { /* virtual */ void Monitor::Deinitialize(PluginHost::IShell* service) { + ASSERT(service != nullptr); + UnregisterAll(); service->Unregister(&_monitor); diff --git a/Monitor/Monitor.h b/Monitor/Monitor.h index 3d92044d..2984e77f 100644 --- a/Monitor/Monitor.h +++ b/Monitor/Monitor.h @@ -107,6 +107,7 @@ namespace Plugin { void Measure(Exchange::IMemory* memInterface) { + ASSERT(memInterface != nullptr); _resident.Set(memInterface->Resident()); _allocated.Set(memInterface->Allocated()); _shared.Set(memInterface->Shared()); @@ -583,7 +584,7 @@ namespace Plugin { { Core::ProxyType source; _adminLock.Lock(); - if(_source != nullptr) { + if (_source != nullptr) { source = Core::ProxyType(*_source, *_source); } _adminLock.Unlock(); @@ -761,7 +762,6 @@ POP_WARNING() } void Deactivated (const string& callsign, PluginHost::IShell* service) override { - MonitorObjectContainer::iterator index(_monitor.find(callsign)); if (index != _monitor.end()) { @@ -788,7 +788,6 @@ POP_WARNING() } } } - } void Unavailable(const string&, PluginHost::IShell*) override { @@ -964,6 +963,7 @@ POP_WARNING() template void translate(const Core::MeasurementType& from, JsonData::Monitor::MeasurementInfo* to) const { + ASSERT(to != nullptr); to->Min = from.Min(); to->Max = from.Max(); to->Average = from.Average(); diff --git a/OpenCDMi/FrameworkRPC.cpp b/OpenCDMi/FrameworkRPC.cpp index 4641a2a6..5b46e483 100644 --- a/OpenCDMi/FrameworkRPC.cpp +++ b/OpenCDMi/FrameworkRPC.cpp @@ -279,13 +279,12 @@ namespace Plugin { class DataExchange : public Exchange::DataExchange, public Core::Thread { private: DataExchange() = delete; - DataExchange(const DataExchange - &) = delete; + DataExchange(const DataExchange&) = delete; DataExchange& operator=(const DataExchange&) = delete; public: DataExchange(CDMi::IMediaKeySession* mediaKeys, const string& name, const uint32_t defaultSize) - : Exchange::DataExchange(name, defaultSize) + : Exchange::DataExchange(name, defaultSize) , Core::Thread(Core::Thread::DefaultStackSize(), _T("DRMSessionThread")) , _mediaKeys(mediaKeys) , _mediaKeysExt(dynamic_cast(mediaKeys)) @@ -355,7 +354,7 @@ namespace Plugin { Size(clearContentSize); } - if(payloadBuffer != clearContent) { + if (payloadBuffer != clearContent) { // This wasn't a case of in-place decryption. So, make sure the decrypted buffer is copied to memory mapped file and released // Adjust the buffer on our side (this process) on what we will write back SetBuffer(0, clearContentSize, clearContent); @@ -394,6 +393,7 @@ namespace Plugin { : _parent(*parent) , _callback(callback) { + ASSERT(_callback != nullptr); _callback->AddRef(); } Sink(SessionImplementation* parent) @@ -573,6 +573,7 @@ POP_WARNING() std::string Metadata() const override { + ASSERT(_mediaKeySession != nullptr); return _mediaKeySession->GetMetadata(); } @@ -602,19 +603,18 @@ POP_WARNING() Exchange::OCDM_RESULT result = Exchange::OCDM_SUCCESS; _adminLock.Lock(); - if( _buffer == nullptr ) { + if (_buffer == nullptr ) { - if (_parent._administrator.AcquireBuffer(bufferID) == true) - { + if (_parent._administrator.AcquireBuffer(bufferID) == true) { _buffer = new DataExchange(_mediaKeySession, bufferID, _parent.DefaultSize()); _adminLock.Unlock(); - + ASSERT(_buffer != nullptr); if (_buffer->IsValid() == false) { SYSLOG(Logging::Fatal, ("Could not open session buffer %s", BufferId().c_str())); } - + if (_parent.Group().IsSet() == true) { _buffer->Group(_parent.Group().Value()); _buffer->Permission(OcdmAccessMode); @@ -641,10 +641,10 @@ POP_WARNING() { std::string bufferid; _adminLock.Lock(); - if( _buffer != nullptr ) { - _adminLock.Unlock(); + if (_buffer != nullptr) { bufferid = _buffer->Name(); } + _adminLock.Unlock(); return bufferid; } @@ -664,6 +664,7 @@ POP_WARNING() void Update(const uint8_t* keyMessage, const uint16_t keyLength) override { TRACE(Trace::Information, ("Update(%d)", keyLength)); + ASSERT(_mediaKeySession != nullptr); return (_mediaKeySession->Update(keyMessage, keyLength)); } @@ -671,6 +672,7 @@ POP_WARNING() Exchange::OCDM_RESULT Remove() override { TRACE(Trace::Information, ("Remove()")); + ASSERT(_mediaKeySession != nullptr); return (Exchange::OCDM_RESULT)(_mediaKeySession->Remove()); } @@ -678,12 +680,14 @@ POP_WARNING() void Close() override { TRACE(Trace::Information, ("Close()")); + ASSERT(_mediaKeySession != nullptr); _mediaKeySession->Close(); } void ResetOutputProtection() override { TRACE(Trace::Information, (_T("ResetOutputProtection! %p"), this)); + ASSERT(_mediaKeySession != nullptr); _mediaKeySession->ResetOutputProtection(); } @@ -694,16 +698,19 @@ POP_WARNING() uint32_t SessionIdExt() const override { + ASSERT(_mediaKeySession != nullptr); return _mediaKeySessionExt->GetSessionIdExt(); } Exchange::OCDM_RESULT SetDrmHeader(const uint8_t drmHeader[], uint16_t drmHeaderLength) override { + ASSERT(_mediaKeySession != nullptr); return (Exchange::OCDM_RESULT)_mediaKeySessionExt->SetDrmHeader(drmHeader, drmHeaderLength); } Exchange::OCDM_RESULT GetChallengeDataExt(uint8_t* challenge, uint16_t& challengeSize, uint32_t isLDL) override { + ASSERT(_mediaKeySession != nullptr); uint32_t resultSize = challengeSize; Exchange::OCDM_RESULT outcome = static_cast(_mediaKeySessionExt->GetChallengeDataExt(challenge, resultSize, isLDL)); challengeSize = (resultSize & 0xFFFF); @@ -712,21 +719,25 @@ POP_WARNING() Exchange::OCDM_RESULT CancelChallengeDataExt() override { + ASSERT(_mediaKeySession != nullptr); return (Exchange::OCDM_RESULT)_mediaKeySessionExt->CancelChallengeDataExt(); } Exchange::OCDM_RESULT StoreLicenseData(const uint8_t licenseData[], uint16_t licenseDataSize, unsigned char* secureStopId) override { + ASSERT(_mediaKeySession != nullptr); return (Exchange::OCDM_RESULT)_mediaKeySessionExt->StoreLicenseData(licenseData, licenseDataSize, secureStopId); } Exchange::OCDM_RESULT SelectKeyId(const uint8_t keyLength, const uint8_t keyId[]) override { + ASSERT(_mediaKeySession != nullptr); return (Exchange::OCDM_RESULT)_mediaKeySessionExt->SelectKeyId(keyLength, keyId); } Exchange::OCDM_RESULT CleanDecryptContext() override { + ASSERT(_mediaKeySession != nullptr); return (Exchange::OCDM_RESULT)_mediaKeySessionExt->CleanDecryptContext(); } @@ -735,7 +746,6 @@ POP_WARNING() INTERFACE_RELAY(Exchange::ISessionExt, _mediaKeySessionExt) END_INTERFACE_MAP - private: private: AccessorOCDM& _parent; mutable Core::CriticalSection _adminLock; @@ -759,13 +769,13 @@ POP_WARNING() { ASSERT(parent != nullptr); } - virtual ~AccessorOCDM() + ~AccessorOCDM() override { TRACE(Trace::Information, (_T("Released the AccessorOCDM server side [%d]"), __LINE__)); } public: - virtual bool IsTypeSupported( + bool IsTypeSupported( const std::string& keySystem, const std::string& mimeType) const override { @@ -773,7 +783,7 @@ POP_WARNING() return (_parent.IsTypeSupported(keySystem, mimeType) ? true : false); } - virtual Exchange::OCDM_RESULT Metadata( + Exchange::OCDM_RESULT Metadata( const std::string& keySystem, std::string& metadata) const override { @@ -811,7 +821,7 @@ POP_WARNING() } // Create a MediaKeySession using the supplied init data and CDM data. - virtual Exchange::OCDM_RESULT CreateSession( + Exchange::OCDM_RESULT CreateSession( const std::string& keySystem, const int32_t licenseType, const std::string& initDataType, @@ -823,56 +833,53 @@ POP_WARNING() std::string& sessionId, Exchange::ISession*& session) override { - CDMi::IMediaKeys *system = _parent.KeySystem(keySystem); - - session = nullptr; - if (system != nullptr) - { - CDMi::IMediaKeySession *sessionInterface = nullptr; - CommonEncryptionData keyIds(initData, initDataLength); - - // OKe we got a buffer machanism to transfer the raw data, now create - // the session. - if (system->CreateMediaKeySession(keySystem, licenseType, - initDataType.c_str(), initData, initDataLength, - CDMData, CDMDataLength, &sessionInterface) == 0) - { - if (sessionInterface != nullptr) - { - SessionImplementation *newEntry = - Core::ServiceType::Create(this, - keySystem, sessionInterface, - callback, &keyIds); - - session = newEntry; - sessionId = newEntry->SessionId(); - - _adminLock.Lock(); - - _sessionList.push_front(newEntry); - - if(false == keyIds.IsEmpty()) - { - CommonEncryptionData::Iterator index(keyIds.Keys()); - while (index.Next() == true) { - const CommonEncryptionData::KeyId& entry(index.Current()); - callback->OnKeyStatusUpdate( entry.Id(), entry.Length(), Exchange::ISession::StatusPending); - } + CDMi::IMediaKeys *system = _parent.KeySystem(keySystem); + + session = nullptr; + if (system != nullptr) { + CDMi::IMediaKeySession *sessionInterface = nullptr; + CommonEncryptionData keyIds(initData, initDataLength); + + // OKe we got a buffer machanism to transfer the raw data, now create + // the session. + if (system->CreateMediaKeySession(keySystem, licenseType, + initDataType.c_str(), initData, initDataLength, + CDMData, CDMDataLength, &sessionInterface) == 0) { + if (sessionInterface != nullptr) { + SessionImplementation *newEntry = + Core::ServiceType::Create(this, + keySystem, sessionInterface, + callback, &keyIds); + + ASSERT(newEntry != nullptr); + session = newEntry; + sessionId = newEntry->SessionId(); + + _adminLock.Lock(); + + _sessionList.push_front(newEntry); + + if (false == keyIds.IsEmpty()) { + CommonEncryptionData::Iterator index(keyIds.Keys()); + while (index.Next() == true) { + const CommonEncryptionData::KeyId& entry(index.Current()); + callback->OnKeyStatusUpdate( entry.Id(), entry.Length(), Exchange::ISession::StatusPending); } - _adminLock.Unlock(); - } - } - } + } + _adminLock.Unlock(); + } + } + } - if (session == nullptr) { - TRACE(Trace::Error, (_T("Could not create a DRM session! [%d]"), __LINE__)); - } + if (session == nullptr) { + TRACE(Trace::Error, (_T("Could not create a DRM session! [%d]"), __LINE__)); + } - return (session != nullptr ? Exchange::OCDM_RESULT::OCDM_SUCCESS : Exchange::OCDM_RESULT::OCDM_S_FALSE); + return (session != nullptr ? Exchange::OCDM_RESULT::OCDM_SUCCESS : Exchange::OCDM_RESULT::OCDM_S_FALSE); } // Set Server Certificate - virtual Exchange::OCDM_RESULT SetServerCertificate( + Exchange::OCDM_RESULT SetServerCertificate( const std::string& keySystem, const uint8_t* serverCertificate, const uint16_t serverCertificateLength) override @@ -890,7 +897,7 @@ POP_WARNING() return result; } - virtual uint64_t GetDrmSystemTime(const std::string& keySystem) const override + uint64_t GetDrmSystemTime(const std::string& keySystem) const override { CDMi::IMediaKeysExt* systemExt = dynamic_cast(_parent.KeySystem(keySystem)); if (systemExt) { @@ -1072,7 +1079,7 @@ POP_WARNING() string bufferid = session->BufferId(); - if( bufferid.empty() == false ) { + if (bufferid.empty() == false) { _administrator.ReleaseBuffer(bufferid); } @@ -1238,6 +1245,7 @@ POP_WARNING() uint32_t Initialize(PluginHost::IShell* service) override { uint32_t result = Core::ERROR_NONE; + ASSERT(service != nullptr); _shell = service; @@ -1250,6 +1258,7 @@ POP_WARNING() uint32_t InitializeAsync() { uint32_t result = Core::ERROR_NONE; + ASSERT(_shell != nullptr); // On activation subscribe, on deactivation un-subscribe PluginHost::ISubSystem* subSystem = _shell->SubSystems(); @@ -1334,12 +1343,14 @@ POP_WARNING() SYSLOG(Logging::Startup, (_T("No DRM factories specified. OCDM can not service any DRM requests."))); } - if((config.Group.IsSet() == true) && (config.Group.Value().empty() == false)){ + if ((config.Group.IsSet() == true) && (config.Group.Value().empty() == false)){ _group = config.Group.Value(); } _entryPoint = Core::ServiceType::Create(this, config.SharePath.Value(), config.ShareSize.Value()); + ASSERT(_entryPoint != nullptr); _engine = Core::ProxyType::Create(&Core::IWorkerPool::Instance()); + ASSERT(_engine != nullptr); _service = new ExternalAccess(Core::NodeId(config.Connector.Value().c_str()), _entryPoint, _shell->ProxyStubPath(), _engine); if (_service != nullptr) { diff --git a/OpenCDMi/OCDM.h b/OpenCDMi/OCDM.h index 4518a762..ca3bd104 100644 --- a/OpenCDMi/OCDM.h +++ b/OpenCDMi/OCDM.h @@ -45,7 +45,7 @@ namespace Plugin { ~Notification() override = default; public: - void Activated(RPC::IRemoteConnection* /* connection */) override + void Activated(RPC::IRemoteConnection* /* connection */) override { } void Deactivated(RPC::IRemoteConnection* connection) override @@ -139,7 +139,8 @@ namespace Plugin { PUSH_WARNING(DISABLE_WARNING_THIS_IN_MEMBER_INITIALIZER_LIST) OCDM() - : _connectionId(0) + : _skipURL(0) + , _connectionId(0) , _service(nullptr) , _opencdmi(nullptr) , _memory(nullptr) diff --git a/OpenCDMi/OCDMJsonRpc.cpp b/OpenCDMi/OCDMJsonRpc.cpp index 7dab5286..31c32952 100644 --- a/OpenCDMi/OCDMJsonRpc.cpp +++ b/OpenCDMi/OCDMJsonRpc.cpp @@ -45,6 +45,8 @@ namespace Plugin { bool OCDM::KeySystems(const string& name, Core::JSON::ArrayType& response) const { bool result = false; + + ASSERT(_opencdmi != nullptr); RPC::IStringIterator* keySystemsIter(_opencdmi->Designators(name)); if (keySystemsIter != nullptr) { string element; @@ -70,6 +72,7 @@ namespace Plugin { // - ERROR_NONE: Success uint32_t OCDM::get_drms(Core::JSON::ArrayType& response) const { + ASSERT(_opencdmi != nullptr); RPC::IStringIterator* drmsIter(_opencdmi->Systems()); if (drmsIter != nullptr) { string element; diff --git a/Packager/Packager.cpp b/Packager/Packager.cpp index f5b777a5..1f2e0d5e 100644 --- a/Packager/Packager.cpp +++ b/Packager/Packager.cpp @@ -167,6 +167,7 @@ namespace { void Packager::Deactivated(RPC::IRemoteConnection* connection) { + ASSERT(connection != nullptr); if (connection->Id() == _connectionId) { ASSERT(_service != nullptr); Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, diff --git a/Packager/PackagerImplementation.cpp b/Packager/PackagerImplementation.cpp index 0dbd522b..b4286177 100644 --- a/Packager/PackagerImplementation.cpp +++ b/Packager/PackagerImplementation.cpp @@ -34,6 +34,7 @@ namespace Plugin { void PackagerImplementation::UpdateConfig() const { ASSERT(!_configFile.empty() && !_tempPath.empty() && !_cachePath.empty()); + ASSERT(opkg_config != nullptr); opkg_config->conf_file = strdup(_configFile.c_str()); opkg_config->tmp_dir = strdup(_tempPath.c_str()); opkg_config->host_cache_dir = 1; @@ -59,6 +60,7 @@ namespace Plugin { Config config; ASSERT(_service == nullptr); + ASSERT(service != nullptr); _service = service; _service->AddRef(); @@ -122,6 +124,7 @@ namespace Plugin { PackagerImplementation::~PackagerImplementation() { FreeOPKG(); + ASSERT(_service != nullptr); _service->Release(); _service = nullptr; } @@ -203,6 +206,8 @@ namespace Plugin { if (command) { _inProgress.Install->SetState(Exchange::IPackager::INSTALLING); NotifyStateChange(); + + ASSERT(opkg_config != nullptr); opkg_config->pfm = command->pfm; std::unique_ptr targetCopy(new char [_inProgress.Package->Name().length() + 1]); std::copy_n(_inProgress.Package->Name().begin(), _inProgress.Package->Name().length(), targetCopy.get()); @@ -253,6 +258,8 @@ namespace Plugin { /* static */ void PackagerImplementation::InstallationProgessNoLock(const opkg_progress_data_t* progress, void* data) { + ASSERT(data != nullptr); + ASSERT(progress != nullptr); PackagerImplementation* self = static_cast(data); self->_inProgress.Install->SetProgress(progress->percentage); if (progress->action == OPKG_INSTALL && @@ -293,6 +300,8 @@ namespace Plugin { string PackagerImplementation::GetCallsignFromMetaDataFile(const string& appName) { string callsign = ""; + + ASSERT(opkg_config != nullptr); string metaDataFileName = (string(opkg_config->cache_dir) + "/" + appName + string(AppPath) + appName + string(PackageJSONFile)); TRACE(Trace::Information, (_T("[RDM]: Metadata is %s"), metaDataFileName.c_str())); Core::File metaDataFile(metaDataFileName); @@ -393,6 +402,7 @@ namespace Plugin { void PackagerImplementation::BlockingSetupLocalRepoNoLock(RepoSyncMode mode) { + ASSERT(opkg_config != nullptr); string dirPath = Core::ToString(opkg_config->lists_dir); Core::Directory dir(dirPath.c_str()); bool containFiles = false; diff --git a/Packager/PackagerImplementation.h b/Packager/PackagerImplementation.h index 411b7ce3..2f61938b 100644 --- a/Packager/PackagerImplementation.h +++ b/Packager/PackagerImplementation.h @@ -288,6 +288,7 @@ namespace Plugin { InstallThread(const InstallThread&) = delete; uint32_t Worker() override { + ASSERT(_parent != nullptr); while(IsRunning() == true) { _parent->_adminLock.Lock(); // The parent may have lock when this starts so wait for it to release. bool isInstall = _parent->_inProgress.Install != nullptr; diff --git a/PerformanceMetrics/PerformanceMetrics.cpp b/PerformanceMetrics/PerformanceMetrics.cpp index b7d92a66..9a0ff13d 100644 --- a/PerformanceMetrics/PerformanceMetrics.cpp +++ b/PerformanceMetrics/PerformanceMetrics.cpp @@ -45,19 +45,19 @@ namespace Plugin { string result; - if( ( config.ObservableCallsign.IsSet() == true ) && (config.ObservableClassname.IsSet() == true) ) { + if ((config.ObservableCallsign.IsSet() == true) && (config.ObservableClassname.IsSet() == true)) { result = _T("Both callsign and classname set to observe for metrics"); } - else if( ( config.ObservableCallsign.IsSet() == true ) && ( config.ObservableCallsign.Value().empty() == false ) ) { + else if ((config.ObservableCallsign.IsSet() == true) && ( config.ObservableCallsign.Value().empty() == false)) { _handler.reset(new CallsignPerfMetricsHandler(config.ObservableCallsign.Value())); } - else if( ( config.ObservableClassname.IsSet() == true ) && ( config.ObservableClassname.Value().empty() == false ) ) { + else if ((config.ObservableClassname.IsSet() == true) && ( config.ObservableClassname.Value().empty() == false)) { _handler.reset(new ClassnamePerfMetricsHandler(config.ObservableClassname.Value())); } else { result = _T("No callsign or classname set to observe for metrics"); } - if( result.empty() == true ) { + if (result.empty() == true) { ASSERT(_handler); _handler->Initialize(); service->Register(&_notification); @@ -68,6 +68,7 @@ namespace Plugin { void PerformanceMetrics::Deinitialize(PluginHost::IShell* service) { + ASSERT(service != nullptr); if (_handler) { service->Unregister(&_notification); // as we do this after the unregister the call to Deinitialize should be threadsafe, no more notifications can be received @@ -101,23 +102,23 @@ namespace Plugin { Exchange::IWebBrowser* webbrowser = service.QueryInterface(); PluginHost::IStateControl* statecontrol = service.QueryInterface(); - if( webbrowser != nullptr ) { - TRACE(Trace::Information, (_T("Start oberserving %s as webbrowser"), Callsign().c_str()) ); + if (webbrowser != nullptr) { + TRACE(Trace::Information, (_T("Start oberserving %s as webbrowser"), Callsign().c_str())); _observable = Core::ProxyType>::Create(*this, service, *webbrowser, statecontrol); webbrowser->Release(); } else { Exchange::IBrowser* browser = service.QueryInterface(); - if( browser != nullptr ) { - TRACE(Trace::Information, (_T("Start oberserving %s as browser"), Callsign().c_str()) ); + if (browser != nullptr) { + TRACE(Trace::Information, (_T("Start oberserving %s as browser"), Callsign().c_str())); _observable = Core::ProxyType>::Create(*this, service, *browser, statecontrol); browser->Release(); } - else if( statecontrol != nullptr ) { - TRACE(Trace::Information, (_T("Start oberserving %s as statecontrol"), Callsign().c_str()) ); + else if (statecontrol != nullptr) { + TRACE(Trace::Information, (_T("Start oberserving %s as statecontrol"), Callsign().c_str())); _observable = Core::ProxyType>::Create(*this, service, statecontrol); } else { - TRACE(Trace::Information, (_T("Start oberserving %s as basic"), Callsign().c_str()) ); + TRACE(Trace::Information, (_T("Start oberserving %s as basic"), Callsign().c_str())); _observable = Core::ProxyType>::Create(*this, service); } } @@ -125,7 +126,7 @@ namespace Plugin { ASSERT(_observable.IsValid() == true); _observable->Enable(); - if( statecontrol != nullptr ) { + if (statecontrol != nullptr) { statecontrol->Release(); } } diff --git a/PerformanceMetrics/PerformanceMetrics.h b/PerformanceMetrics/PerformanceMetrics.h index 2d2cace8..5bf91780 100644 --- a/PerformanceMetrics/PerformanceMetrics.h +++ b/PerformanceMetrics/PerformanceMetrics.h @@ -176,7 +176,7 @@ namespace Plugin { void Deinitialize() override { - if( _observable.IsValid() == true ) { + if (_observable.IsValid() == true) { _observable->Disable(); VARIABLE_IS_NOT_USED uint32_t result =_observable.Release(); ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED); @@ -186,7 +186,7 @@ namespace Plugin { void Activated(PluginHost::IShell& service) override { - if( service.Callsign() == _callsign ) { + if (service.Callsign() == _callsign) { ASSERT(_observable.IsValid() == false); CreateObservable(service); @@ -196,7 +196,7 @@ namespace Plugin { void Deactivated(PluginHost::IShell& service) override { - if( service.Callsign() == _callsign ) { + if (service.Callsign() == _callsign) { ASSERT(_observable.IsValid() == true); _observable->Deactivated(service); @@ -247,7 +247,7 @@ namespace Plugin { void Deinitialize() override { // no lock needed, no notification are possible here. - for( auto& observer : _observers ) { + for (auto& observer : _observers) { observer.second.Deinitialize(); } _observers.clear(); @@ -255,12 +255,12 @@ namespace Plugin { void Activated(PluginHost::IShell& service) override { - if( service.ClassName() == Classname() ) { + if (service.ClassName() == Classname()) { _adminLock.Lock(); auto result =_observers.emplace(std::piecewise_construct, std::forward_as_tuple(service.Callsign()), std::forward_as_tuple(service.Callsign())); - ASSERT( ( result.second == true ) && ( result.first != _observers.end() ) ); + ASSERT((result.second == true) && (result.first != _observers.end())); result.first->second.Initialize(); result.first->second.Activated(service); _adminLock.Unlock(); @@ -268,10 +268,10 @@ namespace Plugin { } void Deactivated(PluginHost::IShell& service) override { - if( service.ClassName() == Classname() ) { + if (service.ClassName() == Classname()) { _adminLock.Lock(); auto it =_observers.find(service.Callsign()); - if( it != _observers.end() ) { + if (it != _observers.end()) { it->second.Deactivated(service); it->second.Deinitialize(); _observers.erase(it); @@ -363,7 +363,7 @@ namespace Plugin { void Deactivated(PluginHost::IShell&) override { - Logger().Deactivated( Uptime() ); + Logger().Deactivated(Uptime()); } uint64_t ActivateTime() const @@ -373,7 +373,7 @@ namespace Plugin { uint32_t Uptime() const { - return ( Core::Time::Now().Ticks() - ActivateTime() ) / Core::Time::MicroSecondsPerSecond; + return (Core::Time::Now().Ticks() - ActivateTime()) / Core::Time::MicroSecondsPerSecond; } CallsignPerfMetricsHandler& Parent() const @@ -410,8 +410,8 @@ namespace Plugin { , _statecontrol(statecontrol) { // not very likely but it could happen that we have a Browser without StatControl - if(_statecontrol != nullptr) { - TRACE(Trace::Information, (_T("Observable supports Statecontrol")) ); + if (_statecontrol != nullptr) { + TRACE(Trace::Information, (_T("Observable supports Statecontrol"))); _statecontrol->AddRef(); } } @@ -425,7 +425,7 @@ namespace Plugin { { Base::Enable(); - if(_statecontrol != nullptr) { + if (_statecontrol != nullptr) { _statecontrol->Register(this); } @@ -439,9 +439,9 @@ namespace Plugin { void StateChange(const PluginHost::IStateControl::state state) override { - if( state == PluginHost::IStateControl::state::RESUMED ) { + if (state == PluginHost::IStateControl::state::RESUMED) { Logger().Resumed(); - } else if( state == PluginHost::IStateControl::state::SUSPENDED ) { + } else if (state == PluginHost::IStateControl::state::SUSPENDED) { Logger().Suspended(); } } @@ -453,7 +453,7 @@ namespace Plugin { private: void Cleanup() { - if(_statecontrol != nullptr) { + if (_statecontrol != nullptr) { _statecontrol->Unregister(this); _statecontrol->Release(); _statecontrol = nullptr; @@ -520,7 +520,7 @@ namespace Plugin { void LoadFinished(const string& URL) override { - if( URL != IBrowserMetricsLogger::startURL ) { + if (URL != IBrowserMetricsLogger::startURL) { ++_nbrloaded; } Logger().LoadFinished(URL, 0, true, _nbrloaded, 0); @@ -601,14 +601,14 @@ namespace Plugin { void LoadFinished(const string& URL, const int32_t httpstatus) override { - if( URL != IBrowserMetricsLogger::startURL ) { + if (URL != IBrowserMetricsLogger::startURL) { ++_nbrloadedsuccess; } Logger().LoadFinished(URL, httpstatus, true, _nbrloadedsuccess, _nbrloadedfailed); } void LoadFailed(const string& URL) override { - if( URL != IBrowserMetricsLogger::startURL ) { + if (URL != IBrowserMetricsLogger::startURL) { ++_nbrloadedfailed; } Logger().LoadFinished(URL, 0, false, _nbrloadedsuccess, _nbrloadedfailed); diff --git a/PlayerInfo/DeviceSettings/PlatformImplementation.cpp b/PlayerInfo/DeviceSettings/PlatformImplementation.cpp index 37d8e989..7a697c6f 100644 --- a/PlayerInfo/DeviceSettings/PlatformImplementation.cpp +++ b/PlayerInfo/DeviceSettings/PlatformImplementation.cpp @@ -84,7 +84,7 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch for (const GList* padTemplatesIterator = padTemplates; padTemplatesIterator; padTemplatesIterator = padTemplatesIterator->next) { GstStaticPadTemplate* padTemplate = static_cast(padTemplatesIterator->data); - if (padTemplate->direction == GST_PAD_SRC) { + if (padTemplate && padTemplate->direction == GST_PAD_SRC) { MediaTypes mediaTypes{gst_static_pad_template_get_caps(padTemplate)}; if (GstUtils::GstRegistryGetElementForMediaType(decoderFactories.get(), std::move(mediaTypes))) { codecIteratorList.push_back(index.second); @@ -226,7 +226,7 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch uint32_t Register(Exchange::Dolby::IOutput::INotification* notification) override { ASSERT(notification != nullptr); - + _adminLock.Lock(); std::list::iterator index(std::find(_observers.begin(), _observers.end(), notification)); @@ -267,16 +267,16 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch static void AudioModeHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len) { - if(PlayerInfoImplementation::_instance) + if (PlayerInfoImplementation::_instance) { dsAudioStereoMode_t amode = dsAUDIO_STEREO_UNKNOWN; Exchange::Dolby::IOutput::SoundModes mode = UNKNOWN; IARM_Bus_DSMgr_EventData_t *eventData = (IARM_Bus_DSMgr_EventData_t *)data; amode = static_cast(eventData->data.Audioport.mode); if (amode == device::AudioStereoMode::kSurround) mode = SURROUND; - else if(amode == device::AudioStereoMode::kStereo) mode = STEREO; - else if(amode == device::AudioStereoMode::kMono) mode = MONO; - else if(amode == device::AudioStereoMode::kPassThru) mode = PASSTHRU; + else if (amode == device::AudioStereoMode::kStereo) mode = STEREO; + else if (amode == device::AudioStereoMode::kMono) mode = MONO; + else if (amode == device::AudioStereoMode::kPassThru) mode = PASSTHRU; else mode = UNKNOWN; PlayerInfoImplementation::_instance->audiomodeChanged(mode, true); } @@ -288,7 +288,7 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch std::list::const_iterator index = _observers.begin(); - while(index != _observers.end()) { + while (index != _observers.end()) { (*index)->AudioModeChanged(mode, enable); index++; } @@ -307,7 +307,6 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch return (Core::ERROR_GENERAL); } - uint32_t AtmosMetadata(bool& supported /* @out */) const override { dsATMOSCapability_t atmosCapability = dsAUDIO_ATMOS_NOTSUPPORTED; @@ -321,7 +320,7 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch for (size_t i = 0; i < aPorts.size(); i++) { device::AudioOutputPort &aPort = aPorts.at(i); - if(aPort.getName().find("HDMI_ARC") != std::string::npos) + if (aPort.getName().find("HDMI_ARC") != std::string::npos) { //the platform supports HDMI_ARC. Get the sound mode of the ARC port audioPort = "HDMI_ARC0"; @@ -344,7 +343,7 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch TRACE(Trace::Error, (_T("Exception during DeviceSetting library call. code = %d message = %s"), err.getCode(), err.what())); } - if(atmosCapability == dsAUDIO_ATMOS_ATMOSMETADATA) supported = true; + if (atmosCapability == dsAUDIO_ATMOS_ATMOSMETADATA) supported = true; return (Core::ERROR_NONE); } @@ -376,7 +375,7 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch audioPort = "SPDIF0"; } /* Does this device support HDMI_ARC output and is the port connected? If yes, then that the audio port whose sound mode we'll return */ - if(aPort.getName().find("HDMI_ARC") != std::string::npos && device::Host::getInstance().getAudioOutputPort("HDMI_ARC0").isConnected()) + if (aPort.getName().find("HDMI_ARC") != std::string::npos && device::Host::getInstance().getAudioOutputPort("HDMI_ARC0").isConnected()) { //the platform supports HDMI_ARC. Get the sound mode of the ARC port LOGINFO(" HDMI ARC port detected on platform"); @@ -391,13 +390,13 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties, public Exch { soundmode = aPort.getStereoMode(); if (soundmode == device::AudioStereoMode::kSurround) mode = SURROUND; - else if(soundmode == device::AudioStereoMode::kStereo) mode = STEREO; - else if(soundmode == device::AudioStereoMode::kMono) mode = MONO; - else if(soundmode == device::AudioStereoMode::kPassThru) mode = PASSTHRU; + else if (soundmode == device::AudioStereoMode::kStereo) mode = STEREO; + else if (soundmode == device::AudioStereoMode::kMono) mode = MONO; + else if (soundmode == device::AudioStereoMode::kPassThru) mode = PASSTHRU; else mode = UNKNOWN; /* Auto mode applicable for HDMI Arc and SPDIF */ - if((aPort.getType().getId() == device::AudioOutputPortType::kARC || aPort.getType().getId() == device::AudioOutputPortType::kSPDIF) + if ((aPort.getType().getId() == device::AudioOutputPortType::kARC || aPort.getType().getId() == device::AudioOutputPortType::kSPDIF) && aPort.getStereoAuto()) { mode = SOUNDMODE_AUTO; diff --git a/PlayerInfo/GStreamer/PlatformImplementation.cpp b/PlayerInfo/GStreamer/PlatformImplementation.cpp index 89ed41a3..055e6455 100644 --- a/PlayerInfo/GStreamer/PlatformImplementation.cpp +++ b/PlayerInfo/GStreamer/PlatformImplementation.cpp @@ -71,7 +71,7 @@ class PlayerInfoImplementation : public Exchange::IPlayerProperties { for (const GList* padTemplatesIterator = padTemplates; padTemplatesIterator; padTemplatesIterator = padTemplatesIterator->next) { GstStaticPadTemplate* padTemplate = static_cast(padTemplatesIterator->data); - if (padTemplate->direction == GST_PAD_SRC) { + if (padTemplate && padTemplate->direction == GST_PAD_SRC) { MediaTypes mediaTypes{gst_static_pad_template_get_caps(padTemplate)}; if (GstUtils::GstRegistryGetElementForMediaType(decoderFactories.get(), std::move(mediaTypes))) { codecIteratorList.push_back(index.second); diff --git a/PlayerInfo/PlayerInfo.cpp b/PlayerInfo/PlayerInfo.cpp index 53d597a0..73a219e3 100644 --- a/PlayerInfo/PlayerInfo.cpp +++ b/PlayerInfo/PlayerInfo.cpp @@ -181,14 +181,14 @@ namespace Plugin { Core::JSON::EnumType audioCodec; _audioCodecs->Reset(0); Exchange::IPlayerProperties::AudioCodec audio; - while(_audioCodecs->Next(audio) == true) { + while (_audioCodecs->Next(audio) == true) { playerInfo.Audio.Add(audioCodec = static_cast(audio)); } Core::JSON::EnumType videoCodec; Exchange::IPlayerProperties::VideoCodec video; _videoCodecs->Reset(0); - while(_videoCodecs->Next(video) == true) { + while (_videoCodecs->Next(video) == true) { playerInfo.Video.Add(videoCodec = static_cast(video)); } } diff --git a/PlayerInfo/PlayerInfo.h b/PlayerInfo/PlayerInfo.h index c3acf055..84139379 100644 --- a/PlayerInfo/PlayerInfo.h +++ b/PlayerInfo/PlayerInfo.h @@ -69,6 +69,7 @@ namespace Plugin { explicit DolbyNotification(PlayerInfo* parent) : _parent(*parent) + , _client(nullptr) { ASSERT(parent != nullptr); } @@ -113,6 +114,7 @@ namespace Plugin { , _player(nullptr) , _audioCodecs(nullptr) , _videoCodecs(nullptr) + , _dolbyOut(nullptr) , _dolbyNotification(this) , _notification(this) , _service(nullptr) diff --git a/RustBridge/RustBridge.cpp b/RustBridge/RustBridge.cpp index faf24044..0e0ffb8a 100644 --- a/RustBridge/RustBridge.cpp +++ b/RustBridge/RustBridge.cpp @@ -268,6 +268,7 @@ namespace WPEFramework { void RustBridge::Deactivated(RPC::IRemoteConnection* connection) { + ASSERT(connection != nullptr); // This can potentially be called on a socket thread, so the deactivation (wich in turn kills this object) must be done // on a seperate thread. Also make sure this call-stack can be unwound before we are totally destructed. if (_connectionId == connection->Id()) { @@ -293,6 +294,7 @@ namespace WPEFramework { } void RustBridge::RustResponse(const uint32_t id, const string& response, const uint32_t error) { + ASSERT(_service != nullptr); // This is the response to an invoked method, Let's see who should get this repsonse :-) _adminLock.Lock(); @@ -300,6 +302,7 @@ namespace WPEFramework { if (index != _pendingRequests.end()) { Core::ProxyType message = Core::ProxyType(PluginHost::IFactories::Instance().JSONRPC()); + ASSERT(message != nullptr); message->Id = index->second.SequenceId(); diff --git a/RustBridge/RustBridgeImplementation.cpp b/RustBridge/RustBridgeImplementation.cpp index 1459265d..6f837413 100644 --- a/RustBridge/RustBridgeImplementation.cpp +++ b/RustBridge/RustBridgeImplementation.cpp @@ -273,6 +273,7 @@ namespace WPEFramework { uint32_t result = Core::ERROR_INCOMPLETE_CONFIG; Config config; + ASSERT(framework != nullptr); config.FromString(framework->ConfigLine()); if (callback != nullptr) { diff --git a/SecurityAgent/SecapiToken.cpp b/SecurityAgent/SecapiToken.cpp index 00c0267e..955f50a7 100644 --- a/SecurityAgent/SecapiToken.cpp +++ b/SecurityAgent/SecapiToken.cpp @@ -71,15 +71,18 @@ void JWTSecApi::SecApi::Mac(SEC_OBJECTID id, JWTSecApi::MacGenerator::MacGenerator() : secApi(make_shared(StorageDir)) { + ASSERT(secApi != nullptr); hmacKey = secApi->GenerateKey(SEC_KEYTYPE_HMAC_256, SEC_STORAGELOC_RAM); } JWTSecApi::MacGenerator::~MacGenerator() { + ASSERT(secApi != nullptr); secApi->DeleteKey(hmacKey); } void JWTSecApi::MacGenerator::Mac(const uint16_t sourceSize, const uint8_t *source, uint16_t &macSize, uint8_t *mac) { + ASSERT(secApi != nullptr); secApi->Mac(hmacKey, sourceSize, source, macSize, mac); } diff --git a/SecurityAgent/SecurityAgent.cpp b/SecurityAgent/SecurityAgent.cpp index b4cecd6b..83efa9c2 100644 --- a/SecurityAgent/SecurityAgent.cpp +++ b/SecurityAgent/SecurityAgent.cpp @@ -90,6 +90,7 @@ namespace Plugin { /* virtual */ const string SecurityAgent::Initialize(PluginHost::IShell* service) { + string message; string webPrefix = service->WebPrefix(); string callsign = service->Callsign(); @@ -166,9 +167,12 @@ namespace Plugin { } } } + else { + message = _T("SecurityAgent failed to create TokenDispatcher"); + } // On success return empty, to indicate there is no error text. - return _T(""); + return message; } /* virtual */ void SecurityAgent::Deinitialize(PluginHost::IShell* service VARIABLE_IS_NOT_USED) @@ -180,7 +184,7 @@ namespace Plugin { _engine.Release(); } - if (_dacDirCallback.IsValid()) { + if (_dacDirCallback.IsValid()) { Core::FileSystemMonitor::Instance().Unregister(&(*_dacDirCallback), _dacDir); _dacDirCallback.Release(); } @@ -211,6 +215,7 @@ namespace Plugin { if (token != _testtoken) { auto webToken = JWTFactory::Instance().Element(); + ASSERT(webToken != nullptr); uint16_t load = webToken->PayloadLength(token); // Validate the token @@ -287,6 +292,7 @@ namespace Plugin { if (request.WebToken.IsSet()) { auto webToken = JWTFactory::Instance().Element(); + ASSERT(webToken != nullptr); const string& token = request.WebToken.Value().Token(); uint16_t load = webToken->PayloadLength(token); diff --git a/SecurityAgent/SecurityAgent.h b/SecurityAgent/SecurityAgent.h index ed7b4359..c13825d9 100644 --- a/SecurityAgent/SecurityAgent.h +++ b/SecurityAgent/SecurityAgent.h @@ -47,14 +47,14 @@ namespace Plugin { : RPC::Communicator(source, proxyStubPath, Core::ProxyType(engine)) , _parentInterface(parentInterface) { - if(_parentInterface != nullptr){ + if (_parentInterface != nullptr){ _parentInterface->AddRef(); } Open(Core::infinite); } ~TokenDispatcher() override { - if(_parentInterface != nullptr){ + if (_parentInterface != nullptr){ _parentInterface->Release(); } diff --git a/SecurityAgent/SecurityAgentJsonRpc.cpp b/SecurityAgent/SecurityAgentJsonRpc.cpp index 749eb067..008ddefb 100644 --- a/SecurityAgent/SecurityAgentJsonRpc.cpp +++ b/SecurityAgent/SecurityAgentJsonRpc.cpp @@ -84,6 +84,7 @@ namespace Plugin { response.Valid = false; auto webToken = JWTFactory::Instance().Element(); + ASSERT(webToken != nullptr); uint16_t load = webToken->PayloadLength(token); // Validate the token diff --git a/WebKitBrowser/CookieJar.cpp b/WebKitBrowser/CookieJar.cpp index 7ea883a3..19a0d33b 100644 --- a/WebKitBrowser/CookieJar.cpp +++ b/WebKitBrowser/CookieJar.cpp @@ -449,11 +449,13 @@ CookieJar::~CookieJar() uint32_t CookieJar::Configure(const string& connector, const string& key) { + ASSERT(_priv != nullptr); return (_priv->Configure(connector, key)); } uint32_t CookieJar::Pack(uint32_t& version, uint32_t& checksum, string& payload) const { + ASSERT(_priv != nullptr); return _priv->Pack(_cookies, version, checksum, payload); } @@ -462,6 +464,7 @@ uint32_t CookieJar::Unpack(const uint32_t version, const uint32_t checksum, cons uint32_t rc; std::vector cookies; + ASSERT(_priv != nullptr); rc = _priv->Unpack(version, checksum, payload, cookies); if (rc == WPEFramework::Core::ERROR_NONE) { diff --git a/WebKitBrowser/Extension/IIdentifier.cpp b/WebKitBrowser/Extension/IIdentifier.cpp index 2a8c39a9..b66966c8 100644 --- a/WebKitBrowser/Extension/IIdentifier.cpp +++ b/WebKitBrowser/Extension/IIdentifier.cpp @@ -45,8 +45,11 @@ void InjectJS(WebKitScriptWorld* world, WebKitFrame* frame, Core::ProxyType(userData); PluginHost::IShell* controller = std::get<0>(identifierData); + ASSERT(controller != nullptr); const PluginHost::ISubSystem* subsysInterface = std::get<1>(identifierData); + ASSERT(subsysInterface != nullptr); const PluginHost::ISubSystem::IIdentifier* identifierInterface = std::get<2>(identifierData); + ASSERT(identifierInterface != nullptr); identifierInterface->Release(); subsysInterface->Release(); @@ -61,9 +64,12 @@ void InjectJS(WebKitScriptWorld* world, WebKitFrame* frame, Core::ProxyType gpointer { Core::ProxyType& comClient = *static_cast*>(userData); + ASSERT(comClient != nullptr); PluginHost::IShell* controller = comClient->Acquire(10000, _T("Controller"), ~0); + ASSERT(controller != nullptr); const PluginHost::ISubSystem* subsysInterface = controller->SubSystems(); + ASSERT(subsysInterface != nullptr); const PluginHost::ISubSystem::IIdentifier* identifierInterface = subsysInterface->Get(); auto* identifierData = new IIdentifierData(controller, subsysInterface, identifierInterface); @@ -84,6 +90,7 @@ void InjectJS(WebKitScriptWorld* world, WebKitFrame* frame, Core::ProxyType char* { IIdentifierData& identifierData = *static_cast(userData); const PluginHost::ISubSystem::IIdentifier* identifierInterface = std::get<2>(identifierData); + ASSERT(identifierInterface != nullptr); uint8_t buffer[64] = {}; buffer[0] = identifierInterface->Identifier(sizeof(buffer) - 1, &(buffer[1])); @@ -106,6 +113,7 @@ void InjectJS(WebKitScriptWorld* world, WebKitFrame* frame, Core::ProxyType char* { IIdentifierData& identifierData = *static_cast(userData); const PluginHost::ISubSystem::IIdentifier* identifierInterface = std::get<2>(identifierData); + ASSERT(identifierInterface != nullptr); string architecture = identifierInterface->Architecture(); if (architecture.length() > 0) { @@ -126,6 +134,7 @@ void InjectJS(WebKitScriptWorld* world, WebKitFrame* frame, Core::ProxyType char* { IIdentifierData& identifierData = *static_cast(userData); const PluginHost::ISubSystem::IIdentifier* identifierInterface = std::get<2>(identifierData); + ASSERT(identifierInterface != nullptr); string chipset = identifierInterface->Chipset(); if (chipset.length() > 0) { @@ -146,6 +155,7 @@ void InjectJS(WebKitScriptWorld* world, WebKitFrame* frame, Core::ProxyType char* { IIdentifierData& identifierData = *static_cast(userData); const PluginHost::ISubSystem::IIdentifier* identifierInterface = std::get<2>(identifierData); + ASSERT(identifierInterface != nullptr); string firmwareVersion = identifierInterface->FirmwareVersion(); if (firmwareVersion.length() > 0) { diff --git a/WebKitBrowser/Extension/WhiteListedOriginDomainsList.cpp b/WebKitBrowser/Extension/WhiteListedOriginDomainsList.cpp index 337d11ab..6369dc6c 100644 --- a/WebKitBrowser/Extension/WhiteListedOriginDomainsList.cpp +++ b/WebKitBrowser/Extension/WhiteListedOriginDomainsList.cpp @@ -84,6 +84,7 @@ namespace WebKit { /* static */unique_ptr WhiteListedOriginDomainsList::Parse(const char* whitelist) { unique_ptr whiteList(new WhiteListedOriginDomainsList()); + ASSERT(whiteList != nullptr); ParseWhiteList(whitelist, whiteList->_whiteMap); return whiteList; } diff --git a/WebKitBrowser/Extension/main.cpp b/WebKitBrowser/Extension/main.cpp index 7fd51360..fb86ac06 100644 --- a/WebKitBrowser/Extension/main.cpp +++ b/WebKitBrowser/Extension/main.cpp @@ -77,6 +77,7 @@ static class PluginHost { PluginHost() : _engine(Core::ProxyType>::Create()) , _comClient(Core::ProxyType::Create(GetConnectionNode(), Core::ProxyType(_engine))) + , _extension(nullptr) { } ~PluginHost() @@ -88,6 +89,7 @@ static class PluginHost { public: void Initialize(WebKitWebExtension* extension, const void* userData) { + ASSERT(_comClient.IsValid() == true); // We have something to report back, do so... uint32_t result = _comClient->Open(RPC::CommunicationTimeOut); if (result != Core::ERROR_NONE) { @@ -161,7 +163,7 @@ static class PluginHost { } private: - static void windowObjectClearedCallback(WebKitScriptWorld* world, WebKitWebPage* page VARIABLE_IS_NOT_USED, WebKitFrame* frame) + static void windowObjectClearedCallback(WebKitScriptWorld* world, WebKitWebPage* page VARIABLE_IS_NOT_USED, WebKitFrame* frame, VARIABLE_IS_NOT_USED PluginHost* host) { JavaScript::Milestone::InjectJS(world, frame); JavaScript::NotifyWPEFramework::InjectJS(world, frame); @@ -192,6 +194,7 @@ static class PluginHost { WebKitWebPage* page, PluginHost* host) { + ASSERT(host != nullptr); if (host->_logToSystemConsoleEnabled) { g_signal_connect(page, "console-message-sent", G_CALLBACK(consoleMessageSentCallback), host); @@ -210,6 +213,7 @@ static class PluginHost { PUSH_WARNING(DISABLE_WARNING_DEPRECATED_USE) static void consoleMessageSentCallback(VARIABLE_IS_NOT_USED WebKitWebPage* page, WebKitConsoleMessage* message, PluginHost* host) { + ASSERT(host != nullptr); string messageString = Core::ToString(webkit_console_message_get_text(message)); uint64_t line = static_cast(webkit_console_message_get_line(message)); diff --git a/WebKitBrowser/InjectedBundle/WhiteListedOriginDomainsList.cpp b/WebKitBrowser/InjectedBundle/WhiteListedOriginDomainsList.cpp index 78550aed..b5847408 100644 --- a/WebKitBrowser/InjectedBundle/WhiteListedOriginDomainsList.cpp +++ b/WebKitBrowser/InjectedBundle/WhiteListedOriginDomainsList.cpp @@ -107,6 +107,7 @@ namespace WebKit { string jsonString = WebKit::Utils::WKStringToString(returnedString); unique_ptr whiteList(new WhiteListedOriginDomainsList()); + ASSERT(whiteList != nullptr); ParseWhiteList(jsonString, whiteList->_whiteMap); WKRelease(returnData); diff --git a/WebKitBrowser/InjectedBundle/main.cpp b/WebKitBrowser/InjectedBundle/main.cpp index 91d23efc..ad4f302e 100644 --- a/WebKitBrowser/InjectedBundle/main.cpp +++ b/WebKitBrowser/InjectedBundle/main.cpp @@ -91,7 +91,6 @@ static class PluginHost { : _engine(Core::ProxyType>::Create()) , _comClient(Core::ProxyType::Create(GetConnectionNode(), Core::ProxyType(_engine))) { - _engine->Announcements(_comClient->Announcement()); } ~PluginHost() { @@ -102,6 +101,7 @@ static class PluginHost { public: void Initialize(WKBundleRef) { + ASSERT(_comClient.IsValid() == true); // We have something to report back, do so... uint32_t result = _comClient->Open(RPC::CommunicationTimeOut); if (result != Core::ERROR_NONE) { @@ -128,6 +128,10 @@ static class PluginHost { if (_comClient.IsValid() == true) { _comClient.Release(); } + if (_engine.IsValid() == true) { + _engine.Release(); + } + Core::Singleton::Dispose(); } diff --git a/WebKitBrowser/WebKitBrowser.cpp b/WebKitBrowser/WebKitBrowser.cpp index 4b377d47..56c9be0e 100644 --- a/WebKitBrowser/WebKitBrowser.cpp +++ b/WebKitBrowser/WebKitBrowser.cpp @@ -243,6 +243,7 @@ namespace Plugin { static_cast(_application)->Visible(visible); PluginHost::IStateControl::state currentState = stateControl->State(); Core::ProxyType> body(_jsonBodyDataFactory.Element()); + ASSERT(body.IsValid() == true); string url; static_cast(_browser)->URL(url); body->URL = url; @@ -304,6 +305,7 @@ namespace Plugin { void WebKitBrowser::LoadFinished(const string& URL, int32_t code) { + ASSERT(_service != nullptr); string message(string("{ \"url\": \"") + URL + string("\", \"loaded\":true, \"httpstatus\":") + Core::NumberType(code).Text() + string(" }")); TRACE(Trace::Information, (_T("LoadFinished: %s"), message.c_str())); _service->Notify(message); @@ -313,6 +315,7 @@ namespace Plugin { void WebKitBrowser::LoadFailed(const string& URL) { + ASSERT(_service != nullptr); string message(string("{ \"url\": \"") + URL + string("\" }")); TRACE(Trace::Information, (_T("LoadFailed: %s"), message.c_str())); _service->Notify(message); @@ -321,6 +324,7 @@ namespace Plugin { void WebKitBrowser::URLChange(const string& URL, bool loaded) { + ASSERT(_service != nullptr); string message(string("{ \"url\": \"") + URL + string("\", \"loaded\": ") + (loaded ? string("true") : string("false")) + string(" }")); TRACE(Trace::Information, (_T("URLChanged: %s"), message.c_str())); _service->Notify(message); @@ -329,6 +333,7 @@ namespace Plugin { void WebKitBrowser::VisibilityChange(const bool hidden) { + ASSERT(_service != nullptr); TRACE(Trace::Information, (_T("VisibilityChange: { \"hidden\": \"%s\"}"), (hidden ? "true" : "false"))); string message(string("{ \"hidden\": ") + (hidden ? _T("true") : _T("false")) + string("}")); _service->Notify(message); @@ -337,6 +342,7 @@ namespace Plugin { void WebKitBrowser::PageClosure() { + ASSERT(_service != nullptr); TRACE(Trace::Information, (_T("Closure: \"true\""))); _service->Notify(_T("{\"Closure\": true }")); Exchange::JWebBrowser::Event::PageClosure(*this); @@ -354,6 +360,7 @@ namespace Plugin { void WebKitBrowser::StateChange(const PluginHost::IStateControl::state state) { + ASSERT(_service != nullptr); TRACE(Trace::Information, (_T("StateChange: { \"State\": %d }"), state)); string message(string("{ \"suspended\": ") + (state == PluginHost::IStateControl::SUSPENDED ? _T("true") : _T("false")) + string(" }")); _service->Notify(message); @@ -362,6 +369,8 @@ namespace Plugin { void WebKitBrowser::Deactivated(RPC::IRemoteConnection* connection) { + ASSERT(_service != nullptr); + ASSERT(connection != nullptr); if (connection->Id() == _connectionId) { ASSERT(_service != nullptr); @@ -440,7 +449,7 @@ namespace WebKitBrowser { , _children(_main.Id()) , _startTime(connection == nullptr ? (TimePoint::min()) : (SteadyClock::now() + std::chrono::seconds(TYPICAL_STARTUP_TIME))) , _adminLock() - { + { } ~MemoryObserverImpl() override = default; diff --git a/WebKitBrowser/WebKitBrowser.h b/WebKitBrowser/WebKitBrowser.h index e8977be1..ab7c0099 100644 --- a/WebKitBrowser/WebKitBrowser.h +++ b/WebKitBrowser/WebKitBrowser.h @@ -134,6 +134,7 @@ namespace Plugin { Add(_T("path"), &Path); } ~Data() = default; + public: Core::JSON::String URL; Core::JSON::DecUInt32 FPS; diff --git a/WebKitBrowser/WebKitImplementation.cpp b/WebKitBrowser/WebKitImplementation.cpp index 7ab9bd20..dd42fc5e 100644 --- a/WebKitBrowser/WebKitImplementation.cpp +++ b/WebKitBrowser/WebKitImplementation.cpp @@ -1011,6 +1011,8 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); + const string& headers = std::get<1>(data); object->_adminLock.Lock(); @@ -1065,6 +1067,7 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); const string& useragent = std::get<1>(data); object->_adminLock.Lock(); @@ -1110,6 +1113,7 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); bool enabled = std::get<1>(data); object->_adminLock.Lock(); @@ -1220,6 +1224,7 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); #ifdef WEBKIT_GLIB_API WebKitCookieAcceptPolicy policy = std::get<1>(data); @@ -1277,6 +1282,7 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { BridgeMessageData& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); #ifdef WEBKIT_GLIB_API auto messageName = std::get<1>(data).c_str(); @@ -1309,6 +1315,7 @@ static GSourceFuncs _handlerIntervention = G_PRIORITY_DEFAULT, [](gpointer customdata) -> gboolean { WebKitImplementation* object = static_cast(customdata); + ASSERT(object != nullptr); #ifdef WEBKIT_GLIB_API WebKitWebContext* context = webkit_web_view_get_context(object->_view); webkit_web_context_garbage_collect_javascript_objects(context); @@ -1338,6 +1345,7 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); auto& script = std::get<1>(data); #ifdef WEBKIT_GLIB_API @@ -1374,6 +1382,7 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); const auto& scriptContent = std::get<1>(data); const bool topFrameOnly = std::get<2>(data); object->AddUserScriptImpl(scriptContent.c_str(), topFrameOnly); @@ -1396,6 +1405,7 @@ static GSourceFuncs _handlerIntervention = G_PRIORITY_DEFAULT, [](gpointer customdata) -> gboolean { WebKitImplementation* object = static_cast(customdata); + ASSERT(object != nullptr); #ifdef WEBKIT_GLIB_API auto* userContentManager = webkit_web_view_get_user_content_manager(object->_view); webkit_user_content_manager_remove_all_scripts(userContentManager); @@ -1756,6 +1766,7 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); string url = std::get<1>(data); object->_adminLock.Lock(); @@ -2119,6 +2130,7 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); + ASSERT(object != nullptr); Core::JSON::ArrayType array = std::get<1>(data); object->_adminLock.Lock(); @@ -2644,6 +2656,7 @@ static GSourceFuncs _handlerIntervention = _context, [](gpointer customdata) -> gboolean { WebKitImplementation* object = static_cast(customdata); + ASSERT(object != nullptr); #ifdef WEBKIT_GLIB_API webkit_web_view_hide(object->_view); #else @@ -2665,6 +2678,7 @@ static GSourceFuncs _handlerIntervention = _context, [](gpointer customdata) -> gboolean { WebKitImplementation* object = static_cast(customdata); + ASSERT(object != nullptr); #ifdef WEBKIT_GLIB_API webkit_web_view_show(object->_view); #else @@ -2689,6 +2703,7 @@ static GSourceFuncs _handlerIntervention = _context, [](gpointer customdata) -> gboolean { WebKitImplementation* object = static_cast(customdata); + ASSERT(object != nullptr); if (object->_config.LoadBlankPageOnSuspendEnabled.Value()) { const char kBlankURL[] = "about:blank"; if (object->_URL != kBlankURL) @@ -2722,6 +2737,7 @@ static GSourceFuncs _handlerIntervention = _context, [](gpointer customdata) -> gboolean { WebKitImplementation* object = static_cast(customdata); + ASSERT(object != nullptr); #ifdef WEBKIT_GLIB_API webkit_web_view_resume(object->_view); #else @@ -2739,6 +2755,7 @@ static GSourceFuncs _handlerIntervention = #ifdef WEBKIT_GLIB_API static void initializeWebExtensionsCallback(WebKitWebContext* context, WebKitImplementation* browser) { + ASSERT(browser != nullptr); webkit_web_context_set_web_extensions_directory(context, browser->_extensionPath.c_str()); // FIX it GVariant* data = g_variant_new("(smsb)", std::to_string(browser->_guid).c_str(), !browser->_config.Whitelist.Value().empty() ? browser->_config.Whitelist.Value().c_str() : nullptr, browser->_config.LogToSystemConsoleEnabled.Value()); @@ -2746,6 +2763,7 @@ static GSourceFuncs _handlerIntervention = } static void wpeNotifyWPEFrameworkMessageReceivedCallback(WebKitUserContentManager*, WebKitJavascriptResult* message, WebKitImplementation* browser) { + ASSERT(browser != nullptr); JSCValue* args = webkit_javascript_result_get_js_value(message); JSCValue* arrayLengthValue = jsc_value_object_get_property(args, "length"); int arrayLength = jsc_value_to_int32(arrayLengthValue); @@ -2764,6 +2782,7 @@ static GSourceFuncs _handlerIntervention = } static gboolean decidePolicyCallback(WebKitWebView*, WebKitPolicyDecision* decision, WebKitPolicyDecisionType type, WebKitImplementation* browser) { + ASSERT(browser != nullptr); if (type == WEBKIT_POLICY_DECISION_TYPE_RESPONSE) { auto *response = webkit_response_policy_decision_get_response(WEBKIT_RESPONSE_POLICY_DECISION(decision)); if (webkit_uri_response_is_main_frame(response)) { @@ -2775,10 +2794,12 @@ static GSourceFuncs _handlerIntervention = } static void uriChangedCallback(WebKitWebView* webView, GParamSpec*, WebKitImplementation* browser) { + ASSERT(browser != nullptr); browser->OnURLChanged(Core::ToString(webkit_web_view_get_uri(webView))); } static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebKitImplementation* browser) { + ASSERT(browser != nullptr); if (loadEvent == WEBKIT_LOAD_FINISHED) { if (browser->_ignoreLoadFinishedOnce) { browser->_ignoreLoadFinishedOnce = false; @@ -2796,6 +2817,8 @@ static GSourceFuncs _handlerIntervention = } static void loadFailedCallback(WebKitWebView*, WebKitLoadEvent loadEvent, const gchar* failingURI, GError* error, WebKitImplementation* browser) { + ASSERT(browser != nullptr); + ASSERT(error != nullptr); string message(string("{ \"url\": \"") + failingURI + string("\", \"Error message\": \"") + error->message + string("\", \"loadEvent\":") + Core::NumberType(loadEvent).Text() + string(" }")); SYSLOG(Logging::Notification, (_T("LoadFailed: %s"), message.c_str())); if (g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)) { @@ -2826,6 +2849,7 @@ static GSourceFuncs _handlerIntervention = } static void closeCallback(VARIABLE_IS_NOT_USED WebKitWebView* webView, WebKitImplementation* browser) { + ASSERT(browser != nullptr); browser->NotifyClosure(); } static gboolean decidePermissionCallback(VARIABLE_IS_NOT_USED WebKitWebView* webView, WebKitPermissionRequest* permissionRequest) @@ -2840,6 +2864,7 @@ static GSourceFuncs _handlerIntervention = } static WebKitWebView* createWebViewForAutomationCallback(VARIABLE_IS_NOT_USED WebKitAutomationSession* session, WebKitImplementation* browser) { + ASSERT(browser != nullptr); return browser->_view; } static void automationStartedCallback(VARIABLE_IS_NOT_USED WebKitWebContext* context, WebKitAutomationSession* session, WebKitImplementation* browser) @@ -2854,6 +2879,7 @@ static GSourceFuncs _handlerIntervention = } static gboolean userMessageReceivedCallback(WebKitWebView*, WebKitUserMessage* message, WebKitImplementation* browser) { + ASSERT(browser != nullptr); const char* name = webkit_user_message_get_name(message); if (g_strcmp0(name, Tags::BridgeObjectQuery) == 0) { GVariant* payload; @@ -2877,11 +2903,13 @@ static GSourceFuncs _handlerIntervention = } #if defined(ENABLE_CLOUD_COOKIE_JAR) static void cookieManagerChangedCallback(WebKitCookieManager* manager VARIABLE_IS_NOT_USED, WebKitImplementation* browser) { + ASSERT(browser != nullptr); browser->NotifyCookieJarChanged(); } #endif uint32_t Worker() override { + ASSERT(_service != nullptr); _context = g_main_context_new(); _loop = g_main_loop_new(_context, FALSE); g_main_context_push_thread_default(_context); @@ -3142,6 +3170,7 @@ static GSourceFuncs _handlerIntervention = if (_config.FPS.Value() == true) { frameDisplayedCallbackID = webkit_web_view_add_frame_displayed_callback(_view, [](WebKitWebView*, gpointer userData) { auto* browser = static_cast(userData); + ASSERT(browser != nullptr); browser->SetFPS(); }, this, nullptr); } @@ -3345,6 +3374,7 @@ static GSourceFuncs _handlerIntervention = // cookiesDidChange [](WKCookieManagerRef, const void* clientInfo) { WebKitImplementation* browser = const_cast(static_cast(clientInfo)); + ASSERT(browser != nullptr); browser->NotifyCookieJarChanged(); } }; @@ -3523,8 +3553,11 @@ static GSourceFuncs _handlerIntervention = g_free(filtersPath); GBytes* data = g_bytes_new(_config.ContentFilter.Value().c_str(), _config.ContentFilter.Value().size()); + ASSERT(_service != nullptr); webkit_user_content_filter_store_save(store, _service->Callsign().c_str(), data, nullptr, [](GObject* obj, GAsyncResult* result, gpointer data) { WebKitImplementation* webkit_impl = static_cast(data); + ASSERT(webkit_impl != nullptr); + WebKitUserContentFilter* filter = webkit_user_content_filter_store_save_finish(WEBKIT_USER_CONTENT_FILTER_STORE(obj), result, nullptr); auto* userContentManager = webkit_web_view_get_user_content_manager(webkit_impl->_view); webkit_user_content_manager_add_filter(userContentManager, filter); @@ -3552,6 +3585,7 @@ static GSourceFuncs _handlerIntervention = [](GObject* object, GAsyncResult* result, gpointer user_data) { bool isWebProcessResponsive = webkit_web_view_is_web_process_responsive_finish(WEBKIT_WEB_VIEW(object), result, nullptr); WebKitImplementation* webkit_impl = static_cast(user_data); + ASSERT(webkit_impl != nullptr); webkit_impl->DidReceiveWebProcessResponsivenessReply(isWebProcessResponsive); }, this); @@ -3561,6 +3595,7 @@ static GSourceFuncs _handlerIntervention = this, [](bool isWebProcessResponsive, void* customdata) { WebKitImplementation* object = static_cast(customdata); + ASSERT(object != nullptr); object->DidReceiveWebProcessResponsivenessReply(isWebProcessResponsive); }); #endif @@ -3638,6 +3673,7 @@ static GSourceFuncs _handlerIntervention = #ifdef WEBKIT_GLIB_API static void isWebProcessResponsiveCallback(WebKitWebView*, GParamSpec*, WebKitImplementation* self) { + ASSERT(self != nullptr); if (webkit_web_view_get_is_web_process_responsive(self->_view) == true) { if (self->_unresponsiveReplyNum > 0) { @@ -3728,6 +3764,7 @@ static GSourceFuncs _handlerIntervention = { int configLen = strlen(Tags::Config); const WebKitImplementation* browser = static_cast(clientInfo); + ASSERT(browser != nullptr); string name = WKStringToString(messageName); @@ -3759,6 +3796,7 @@ static GSourceFuncs _handlerIntervention = /* static */ void didStartProvisionalNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef /* userData */, const void* clientInfo) { WebKitImplementation* browser = const_cast(static_cast(clientInfo)); + ASSERT(browser != nullptr); WKURLRef urlRef = WKPageCopyActiveURL(page); WKStringRef urlStringRef = WKURLCopyString(urlRef); @@ -3776,6 +3814,7 @@ static GSourceFuncs _handlerIntervention = { if (type == kWKSameDocumentNavigationAnchorNavigation) { WebKitImplementation* browser = const_cast(static_cast(info)); + ASSERT(browser != nullptr); WKURLRef urlRef = WKPageCopyActiveURL(page); WKStringRef urlStringRef = WKURLCopyString(urlRef); @@ -3793,6 +3832,7 @@ static GSourceFuncs _handlerIntervention = { WebKitImplementation* browser = const_cast(static_cast(clientInfo)); + ASSERT(browser != nullptr); WKURLRef urlRef = WKPageCopyActiveURL(page); WKStringRef urlStringRef = WKURLCopyString(urlRef); @@ -3818,6 +3858,7 @@ static GSourceFuncs _handlerIntervention = /* static */ void onNotificationShow(WKPageRef /* page */, WKNotificationRef notification, const void* clientInfo) { const WebKitImplementation* browser = static_cast(clientInfo); + ASSERT(browser != nullptr); WKStringRef titleRef = WKNotificationCopyTitle(notification); WKStringRef bodyRef = WKNotificationCopyBody(notification); @@ -3838,18 +3879,21 @@ static GSourceFuncs _handlerIntervention = /* static */ void onFrameDisplayed(WKViewRef /* view */, const void* clientInfo) { WebKitImplementation* browser = const_cast(static_cast(clientInfo)); + ASSERT(browser != nullptr); browser->SetFPS(); } /* static */ void didRequestAutomationSession(WKContextRef context, WKStringRef sessionID, const void* clientInfo) { WebKitImplementation* browser = const_cast(static_cast(clientInfo)); + ASSERT(browser != nullptr); browser->OnRequestAutomationSession(context, sessionID); } /* static */ WKPageRef onAutomationSessionRequestNewPage(WKWebAutomationSessionRef, const void* clientInfo) { WebKitImplementation* browser = const_cast(static_cast(clientInfo)); + ASSERT(browser != nullptr); return browser->GetPage(); } @@ -3858,6 +3902,8 @@ static GSourceFuncs _handlerIntervention = WKFramePolicyListenerUse(listener); if (WKNavigationResponseIsMainFrame(response)) { WebKitImplementation* browser = const_cast(static_cast(clientInfo)); + ASSERT(browser != nullptr); + WKURLResponseRef urlResponse = WKNavigationResponseGetURLResponse(response); browser->SetResponseHTTPStatusCode(WKURLResponseHTTPStatusCode(urlResponse)); // WKRelease(urlResponse); @@ -3890,6 +3936,7 @@ static GSourceFuncs _handlerIntervention = } WebKitImplementation* browser = const_cast(static_cast(clientInfo)); + ASSERT(browser != nullptr); browser->OnLoadFailed(url); }