/** * This function executes action function on the supplied range. * * \param group pointer to image list * \param range index range on which to execute action * \param action pointer to action function which will be used for modification * \return OK if modification was successfull */ RCode group_execute_range(ImageGroup* group, Range range, ActionFn* action) { guint i = 0; RCode result = OK; ASSERT(NULL != group); ASSERT(NULL != group->list); TRACE_MESSAGE(IGRP, TL_INFO, "Executing action on range (name='%s',range=<%d,%d>)", group->name, range.start, range.end); // check if first index is in range if ( FAIL == range_check_bounds( range, 0, group->list->len - 1) ) { ERROR_SET(ERROR.OUT_OF_RANGE); ERROR_NOTE("Supplied range is out of bounds (group='%s',range=<%d,%d>,min=0,max=%d)", group->name, range.start,range.end,group->list->len-1); return FAIL; } for ( i = range.start; i <= range.end; i++) { ImageGroupRecord* record = &g_array_index(group->list, ImageGroupRecord, i); // execute action on record TRACE_MESSAGE(IGRP, TL_INFO, "Executing action (name='%s',index=%d,action=0x%x)", group->name, i, action); if ( FAIL == action(record) ) { ERROR_SET(ERROR.ACTION_FN_FAILED); ERROR_NOTE("Action failed on (group='%s',index=%d),action=0x%x", group->name, i, action); result = FAIL; } } return result; }
KLUPD::CoreError KLUPD::AdministrationKitProtocol::setupLowLevelConnectionIfNeed(const bool useMasterAdministrationServer) { #ifdef DISABLE_AK_FILETRANSFER TRACE_MESSAGE("Administration Kit Transport is not implemented"); return CORE_DOWNLOAD_ERROR; #else if(m_connected) return CORE_NO_ERROR; m_downloadProgress.updateSpeedStartTimer(); KLFT::ConnectResult connectResult = KLFT::CR_ConnectionServerError; if(useMasterAdministrationServer) { TRACE_MESSAGE("Connecting to master administration server"); connectResult = m_adminKitTransprot->ConnectToMasterServer(); } else { TRACE_MESSAGE("Connecting to administration server"); connectResult = m_adminKitTransprot->Connect(); } m_downloadProgress.updateSpeedStopTimer(); switch(connectResult) { // successfully connected case KLFT::CR_Ok: m_connected = true; return CORE_NO_ERROR; // invalid AdminKit Transport identifier: either receiver was // deleted or connect was already called for this receiver case KLFT::CR_WrongReceiverId: return CORE_AK_WrongReceiverId; // AdminKit server is busy and can not handle requests now case KLFT::CR_ServerBusy: return CORE_AK_ServerBusy; // physical connection to AdminKit error case KLFT::CR_ConnectionError: return CORE_AK_ConnectionError; // connection to AdminKit network agent physical error case KLFT::CR_ConnectionNagentError: return CORE_AK_ConnectionNagentError; // connection to master AdminKit server physical error case KLFT::CR_ConnectionServerError: return CORE_AK_ConnectionServerError; // unknown AdminKit connection error default: TRACE_MESSAGE2("Connecting to Administration Server failed with unknown code '%d'", connectResult); return CORE_AK_CannotConnectToServer; } #endif // DISABLE_AK_FILETRANSFER }
/** * This function executes action function on all record which have select flag * set to TRUE. * * \param group pointer to image list * \param action pointer to action function which will be used for modification * \return OK on success */ RCode group_execute_select(ImageGroup* group, ActionFn* action) { RCode result = OK; guint i = 0; ASSERT(NULL != group); ASSERT(NULL != group->list); TRACE_MESSAGE(IGRP, TL_INFO, "Executing action on selected (name='%s')", group->name); while ( i < group->list->len ) { ImageGroupRecord* record = &g_array_index(group->list, ImageGroupRecord, i); // check if record is selected if ( FALSE == record->select ) { i++; continue; } // execute action on record TRACE_MESSAGE(IGRP, TL_INFO, "Executing action on (name='%s',index=%d)", group->name,i); if ( FAIL == action(record) ) { ERROR_SET(ERROR.ACTION_FN_FAILED); ERROR_NOTE("Action failed on (group='%s',index=%d)", group->name, i); result = FAIL; } i++; } return result; }
/** * The function will deallocate all Image structures which are referenced only * from pile (ie having ref == 1 ) in pile and remove them from list. * * In case some Image structure is referenced not only from pile, function will * terminate prematurely and return error. Invocation can be repeated when all * references to the structure are removed. * * \return OK on success */ RCode pile_destroy() { GList* iterator = NULL; if ( NULL == pile_list_head ) { // no need to destroy empty pile return OK; } iterator = g_list_first(pile_list_head); while ( NULL != iterator ) { TRACE_MESSAGE(PILE, TL_DEBUG, "Deallocating %s", ((Image*)iterator->data)->name); if ( FAIL == image_unref((Image*)iterator->data) ) { ERROR_NOTE("Unable to deallocate image structure"); // attempt to leave image list in consistent state after failing to // free Image structure. Remove all elements of list which do not // point to Image structure anymore (ie previously freed) pile_list_head = g_list_remove_all(pile_list_head, NULL); return FAIL; } iterator->data = NULL; iterator = g_list_next(iterator); } TRACE_MESSAGE(PILE, TL_DEBUG, "Freeing image pile list"); g_list_free(pile_list_head); // This needs to be here since freed list elements are returned to glib // allocator but remain valid! So it will look as if we have one more // element in list. pile_list_head = NULL; return OK; }
void XMLObjectCache::dumpForeignCache() { TRACE_MESSAGE("****** Begin Foreign Object Instance Cache Dump ******"); gthread_mutex_lock(&m_csForeign); GHashIterator iter2(m_cacheForeignAlternate); while (iter2()) { DynamicXMLObject *pObj = (DynamicXMLObject *)iter2++; GString str; str.Format("Object In Alt-Index Cache - %s[%s]\n", pObj->GetObjectType(), pObj->GetObjectTag() ); TRACE_MESSAGE((const char *)str); } TRACE_MESSAGE("-----------------------------------------------\n"); GHashIterator iter(m_cacheForeign); while (iter()) { DynamicXMLObject *pObj = (DynamicXMLObject *)iter++; GString str; str << "Object In Cache - " << (__int64)(void *)pObj; TRACE_MESSAGE((const char *)str); } gthread_mutex_unlock(&m_csForeign); TRACE_MESSAGE("****** End Foreign Object Instance Cache Dump ******"); }
double generate_uniform( double min, double max ) { TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "+sola::component::random::generate_uniform"); SERIALIZE_CALL(std::recursive_mutex, __random_lock); double result; std::uniform_real_distribution<double> uniform_dist; if(!__random_initialized) { THROW_RANDOM_EXCEPTION(RANDOM_EXCEPTION_UNINITIALIZED); } if(min > max) { THROW_RANDOM_EXCEPTION_MESSAGE( RANDOM_EXCEPTION_INVALID_PARAMETER, "min > max" ); } result = ((max - min) * uniform_dist(__random_generator)) + min; TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "-sola::component::random::generate_uniform, result. " << result); return result; }
/** * The function check what kind of specific view is linked from the generic * one and call appropriate update() function over appropriate object. * * The function does not return status since caller usually does not know how to * resolve the error (the function should be called from model notification * function). * * The function intercepts all errors comming from specific functions and logs * them for investigation. * * The sequence number should uniquely identify the change that triggered the * update. It can be used for checking if same update request was being sent * twice (and also for unit testing to make sure notification was received). * * \param view pointer to generic view structure * \param seq sequence number of the update */ RCode view_update(ViewGeneric *view, gint seq) { RCode result = OK; ASSERT( NULL != view ); // check if invalid or already known sequence number is being sent // in that case do not process the notification if ( view->last_sequence == seq || 0 == seq ) { return OK; } else { view->last_sequence = seq; } TRACE_MESSAGE(VIEW, TL_INFO, "Update view event received (view=%p, type=%d, seq=%d)", view, view->type, seq ); switch ( view->type ) { case VIEW_NONE: TRACE_MESSAGE(VIEW, TL_INFO, "No specific method for update() call (view=%p, type=%d)", view, view->type ); result = OK; break; case VIEW_APPLICATION: result = view_app_update(view, seq); break; case VIEW_IMAGE_DISPLAY: result = view_idv_update(view, seq); break; case VIEW_CONTAINER: result = view_cv_update(view, seq); break; case VIEW_LIST_STATUS: result = view_lsv_update(view, seq); break; default: TRACE_MESSAGE(VIEW, TL_INFO, "Unsupported view type (cntl=%p, type=%d)", view, view->type ); } if ( FAIL == result ) { ERROR_LOG(); } return result; }
/** * The function update position and dimension of the view in the application * window and then it will call appropriate view_*_resize() function for * specific view. * * The specific funtion is called with new region as a parameter, old region can * be retrievable from generic view. The view region is update after the call to * specific function finish. * * The new region dimensions are set only if there is no error in the specific * resize function invocation. * * \param view pointer to generic view structure * \param newRegion new area assigned to the view * \return OK on success */ RCode view_resize(ViewGeneric *view, GdkRectangle newRegion) { RCode result = OK; ASSERT( NULL != view ); // call update only if there is a difference between old and new region if ( view->region.x != newRegion.x || view->region.width != newRegion.width || view->region.y != newRegion.y || view->region.height != newRegion.height ) { TRACE_MESSAGE(VIEW, TL_DEBUG, "Resize view event received(view=%p, type=%d, [x=%d,y=%d,width=%d,height=%d])", view, view->type, newRegion.x, newRegion.y, newRegion.width, newRegion.height ); switch ( view->type ) { case VIEW_NONE: TRACE_MESSAGE(VIEW, TL_INFO, "No specific method for update() call (view=%p, type=%d)", view, view->type ); result = OK; break; case VIEW_APPLICATION: result = view_app_resize(view, newRegion); break; case VIEW_IMAGE_DISPLAY: result = view_idv_resize(view, newRegion); break; case VIEW_CONTAINER: result = view_cv_resize(view, newRegion); break; case VIEW_LIST_STATUS: result = view_lsv_resize(view, newRegion); break; default: TRACE_MESSAGE(VIEW, TL_INFO, "Unsupported view type (cntl=%p, type=%d)", view, view->type ); result = FAIL; } } // update view region if ( OK == result ) { view->region = newRegion; } return result; }
/** * The function check what kind of specific view is linked from the generic * one and call appropriate redraw() function over appropriate object. * * \param view pointer to generic view structure * \param region region of screen that need to be updated * \return OK on success */ RCode view_redraw(ViewGeneric *view, GdkRectangle *region) { RCode result = OK; GdkRectangle subregion; ASSERT( NULL != view ); ASSERT( NULL != region ); // check if updated region is in view region if ( ! gdk_rectangle_intersect(&(view->region), region, &subregion) ) { return result; } else { TRACE_MESSAGE(VIEW, TL_DEBUG, "Redraw view event received (view=%p, type=%d, region=[%d,%d,%d,%d])", view, view->type, subregion.x, subregion.y, subregion.width, subregion.height ); } switch ( view->type ) { case VIEW_NONE: TRACE_MESSAGE(VIEW, TL_INFO, "No specific method for update() call (view=%p, type=%d)", view, view->type ); result = OK; break; case VIEW_APPLICATION: result = view_app_redraw(view, &subregion); break; case VIEW_IMAGE_DISPLAY: result = view_idv_redraw(view, &subregion); break; case VIEW_CONTAINER: result = view_cv_redraw(view, &subregion); break; case VIEW_LIST_STATUS: result = view_lsv_redraw(view, &subregion); break; default: TRACE_MESSAGE(VIEW, TL_INFO, "Unsupported view type (cntl=%p, type=%d)", view, view->type ); result = FAIL; } return result; }
/** * This function adds images into image list. It is kinda special as it does not * use yank buffer as an input. It should be used at special occasions only, * like for loading image_group from image_pile. * * \param group image list into which images will be added * \param index position to which images will be added * \param data array containing list of image pointers * \param size number of pointers in array * \return OK on success */ extern RCode group_insert(ImageGroup* group, gint index, Image* data[], guint size) { unsigned int source_index = 0; unsigned int target_index = 0; ImageGroupRecord* buffer = NULL; ASSERT(NULL != group); ASSERT(NULL != group->list); /* check position into which images are being inserted * we do not fail if index = list length ( which is one record after the * last one to be able to add at the end of array */ if ( index < 0 || group->list->len < index ) { ERROR_SET(ERROR.OUT_OF_RANGE); ERROR_NOTE("Index %d out of range [0, %d]", index, group->list->len); return FAIL; } // allocate internal buffer for insertions TRACE_MESSAGE(IGRP, TL_DEBUG, "Allocate insert buffer (size=%d)", size); buffer = (ImageGroupRecord*) g_try_malloc0(size*sizeof(ImageGroupRecord)); if ( NULL == buffer ) { ERROR_SET(ERROR.MEMORY_FAILURE); return FAIL; } // prepare data in buffer for insertion TRACE_MESSAGE(IGRP, TL_DEBUG, "Preparing values into insert buffer (count=%d)",size); for ( source_index = 0, target_index = 0; source_index < size; source_index++ ) { TagList *tags = image_get_groups(data[source_index]); if ( FALSE == taglist_contains(tags, group->tag) ) { buffer[target_index].image = data[source_index]; buffer[target_index].select = FALSE; image_ref(buffer[target_index].image); taglist_insert(tags, group->tag); target_index++; } } // compute position into which to insert and insert the data TRACE_MESSAGE(IGRP, TL_INFO, "Inserting records into group (name='%s', index=%d, count=%d, filtered=%d)", group->name, index, target_index, (size - target_index) ); group->list = g_array_insert_vals(group->list, index, (gpointer)buffer, target_index); // deallocate insert buffer g_free( (gpointer)buffer ); return OK; }
bool Ini_UpdaterLists::readSingleFileInfoRollback(const TCHAR *iniFileName, TCHAR *fileSectionName, FileInfo &file) { if(!iniFileName || (*iniFileName == 0)) { TRACE_MESSAGE("Read rollback file information error: configuration file name is not specified"); return false; } if(!fileSectionName) { TRACE_MESSAGE("Read rollback file information error: configuration section is not specified"); return false; } TCHAR buffer[MAX_STR_BUFF + 1] = _T(""); // file name GetPrivateProfileString(fileSectionName, STRING(SS_KEY_RecentFileName).c_str(), _T(UNKNOWN_STRING), buffer, MAX_STR_BUFF, iniFileName); if(!_tcscmp(buffer, _T(UNKNOWN_STRING))) { TRACE_MESSAGE2("Read rollback file information error: no '%s' value found", STRING(SS_KEY_RecentFileName).to_string().c_str()); return false; } file.m_filename = buffer; // local path GetPrivateProfileString(fileSectionName, STRING(SS_KEY_RecentLocalPath).c_str(), _T(UNKNOWN_STRING), buffer, MAX_STR_BUFF, iniFileName); if(!_tcscmp(buffer, _T(UNKNOWN_STRING))) { TRACE_MESSAGE2("Read rollback file information error: no '%s' value found", STRING(SS_KEY_RecentLocalPath).to_string().c_str()); return false; } file.m_localPath = buffer; // change status GetPrivateProfileString(fileSectionName, STRING(SS_KEY_ChangeStatus).c_str(), _T(UNKNOWN_STRING), buffer, MAX_STR_BUFF, iniFileName); if(!_tcscmp(buffer, _T(UNKNOWN_STRING))) { TRACE_MESSAGE2("Read rollback file information error: no '%s' value found", STRING(SS_KEY_ChangeStatus).to_string().c_str()); return false; } file.m_rollbackChange = buffer; // md5 for consistency check GetPrivateProfileString(fileSectionName, STRING(kayw_MD5).c_str(), _T(UNKNOWN_STRING), buffer, MAX_STR_BUFF, iniFileName); if(_tcscmp(buffer, _T(UNKNOWN_STRING))) file.m_md5 = CBase64::decodeBuffer(STRING(buffer).to_string().c_str()); TRACE_MESSAGE2("Rollback information read: '%s'", file.toString().c_str()); return true; }
void XMLObjectCache::dumpStateCache() { TRACE_MESSAGE("****** Begin Object State Cache Dump ******"); gthread_mutex_lock(&m_csState); GHashIterator iter(m_cacheState); while (iter()) { GString *pObj = (GString *)iter++; GString str; str.Format("State In Cache - %s", pObj->StrVal()); TRACE_MESSAGE((const char *)str); } gthread_mutex_unlock(&m_csState); TRACE_MESSAGE("****** End Object State Cache Dump ******"); }
bool Ini_UpdaterLists::saveRollbackListEntry(const TCHAR *iniFileName, const TCHAR *parentSectionName, const long orderNumber, const STRING &newSectionName, const FileInfo &file) { if(!iniFileName || (*iniFileName == 0) || !parentSectionName || (*parentSectionName == 0)) { TRACE_MESSAGE("Unable to save rollback entry information: invalid parameter"); return false; } TCHAR szEntryKeyName[MAX_PATH+1]; _stprintf(szEntryKeyName,_T("entry%d"), orderNumber); WritePrivateProfileString(parentSectionName, szEntryKeyName, STRING(newSectionName).c_str(), iniFileName); TCHAR fullSectionName[MAX_PATH+MAX_PATH+1]; _tcscpy(fullSectionName, parentSectionName); _tcscat(fullSectionName, _T(":")); _tcscat(fullSectionName, STRING(newSectionName).c_str()); // file name WritePrivateProfileString(fullSectionName, STRING(SS_KEY_RecentFileName).c_str(), file.m_filename.c_str(), iniFileName); // local path WritePrivateProfileString(fullSectionName, STRING(SS_KEY_RecentLocalPath).c_str(), file.m_localPath.c_str(), iniFileName); // change status WritePrivateProfileString(fullSectionName, STRING(SS_KEY_ChangeStatus).c_str(), file.m_rollbackChange.c_str(), iniFileName); // md5 for consistency check if(!file.m_md5.empty()) { std::vector<char> md5 = CBase64::encodeBuffer(&file.m_md5[0], file.m_md5.size()); md5.insert(md5.end(), 0); WritePrivateProfileString(fullSectionName, STRING(kayw_MD5).c_str(), STRING(&md5[0]).c_str(), iniFileName); } return true; }
/** * The method resize updates the view internal variables to the changed region * size. * * \param view view to resize * \param newRegion the size of the new region * \return OK on success */ RCode view_lsv_resize(ViewGeneric *view, GdkRectangle newRegion) { ViewListStatus* lsv_data = NULL; ASSERT( NULL != view ); lsv_data = view_lsv_get_data_pointer(view); if ( NULL == lsv_data ) { return FAIL; } // check if buffer need to be resized if ( newRegion.x == view->region.x && newRegion.width == view->region.width && newRegion.y == view->region.y && newRegion.height == view->region.height ) { return OK; } TRACE_MESSAGE(VIEW, TL_DEBUG, "Image list status resize (view=%p, [x=%d,y=%d,width=%d,height=%d]", view, newRegion.x, newRegion.y, newRegion.width, newRegion.height ); // force redraw of view if ( NULL != view->window ) { gdk_window_invalidate_rect(view->window, &(newRegion), FALSE); } return OK; }
/** * Set new zoom type to the image display view structure and force internal * buffer content regeneration if new zoom type is different from old zoom type. * * \param view pointer to generic view structure * \param type new zoom type to set for image display view * \return OK on success */ RCode view_idv_set_zoom(ViewGeneric *view, ZoomType type) { ViewImageDisplay* idv_data = NULL; ASSERT( NULL != view ); idv_data = view_idv_get_data_pointer(view); if ( NULL == idv_data ) { return FAIL; } if ( type != idv_data->zoom_type ) { idv_data->zoom_type = type; // reset to original resultion if changing to custom zoom if ( ZOOM_FIT_CUSTOM == idv_data->zoom_type ) { idv_data->zoom_factor = 1.0f; } // reset offset to top left corner upon auto zoom type change idv_data->offset.x = 0; idv_data->offset.y = 0; TRACE_MESSAGE(CNTL, TL_DEBUG, "Zoom setup has changed to (view=%p, factor=%f, type=%d)", view, idv_data->zoom_factor, idv_data->zoom_type ); return view_idv_generate_buffer(view, idv_data, TRUE); } else { return OK; } }
/** * This function deletes number of entries from list specified by range * * \param group image group from which we will remove records * \param range range specifying entries * \return OK on success */ RCode group_delete_range(ImageGroup* group, Range range) { guint i = 0; ASSERT(NULL != group); ASSERT(NULL != group->list); TRACE_MESSAGE(IGRP, TL_INFO, "Removing range (group='%s',range=<%d,%d>)", group->name, range.start, range.end ); // check if index is in range if ( FAIL == range_check_bounds(range, 0, group->list->len - 1) ) { ERROR_SET(ERROR.OUT_OF_RANGE); ERROR_NOTE("Supplied range is out of bounds (group='%s',range=<%d,%d>,min=0,max=%d)", group->name, range.start,range.end,group->list->len-1 ); return FAIL; } // unreference images that will be removed for (i = range.start; i <= range.end; i++) { ImageGroupRecord record = g_array_index(group->list, ImageGroupRecord, i); /** \todo Check what to do with the call return code */ image_unref(record.image); } group->list = g_array_remove_range(group->list, range.start, range.end - range.start + 1); return OK; }
/** * This function deallocates all memory allocated for image list. * * \param group pointer to image list to deallocate * \return OK on success */ RCode group_destroy(ImageGroup* group) { RCode result; guint i; ASSERT( NULL != group); ASSERT( NULL != group->list); TRACE_MESSAGE(IGRP, TL_MINOR, "Destroying group (name='%s',tag='%c')", group->name, group->tag); // unreference all images that are stored in the buffer for (i = 0; i < group->list->len; i++ ) { ImageGroupRecord* record = &g_array_index(group->list, ImageGroupRecord, i); result = taglist_remove(image_get_groups(record->image), group->tag); if ( FAIL == result ) { ERROR_LOG(); } result = image_unref(record->image); if ( FAIL == result ) { ERROR_LOG(); } } g_array_free(group->list, TRUE); g_free( (gpointer)group->name); g_free( (gpointer)group); return OK; }
// reads proxy server string from registry bool ProxyDetectorNamespace::RegistryReader::readStringFromRegistry(std::string &proxyServer, KLUPD::Log *pLog) { const std::string internetSettings = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; HKEY key = 0; if(!WindowsRegistryWrapper::openCurrentThreadUserRegistryKey(internetSettings.c_str(), key, pLog)) { TRACE_MESSAGE2("Failed to open proxy settings registry key '%s'", internetSettings.c_str()); return false; } const char *proxyEnableLiteral = "ProxyEnable"; DWORD proxyEnabled = 0; if(!WindowsRegistryWrapper::readRegistryDword(key, proxyEnableLiteral, proxyEnabled, pLog)) { TRACE_MESSAGE2("Failed to read proxy settings registry key '%s'", proxyEnableLiteral); RegCloseKey(key); return false; } if(!proxyEnabled) { TRACE_MESSAGE("Proxy server is disabled based on 'ProxyEnable' value from registry"); RegCloseKey(key); return false; } // reading proxy server string from registry const bool result = WindowsRegistryWrapper::readRegistryString(key, "ProxyServer", proxyServer, pLog); RegCloseKey(key); return result; }
/** * Compute new offset from supplied direction and gc constant * and set it into image view structure. Return whenever the offset changed or * not. * * \param view pointer to image display view structure * \param data pointer to image display view data * \param direction dirction in which to pan image * \return TRUE if offset has changed */ gboolean view_idv_compute_offset(ViewGeneric* view, ViewImageDisplay *data, PanDirection direction) { gint limit, offset, delta; gint polarity = 1; ASSERT( NULL != view ); ASSERT( NULL != data ); switch (direction) { case PAN_UP: // only change polarity of following position shift polarity = -1; case PAN_DOWN: // compute maximum offset in y axis limit = data->dimension.y * data->zoom_factor - view->region.height; // compute actual shift in y value offset = data->offset.y + polarity * (gint)round(data->pan_percentage * view->region.height); // limit shift in x value to <0, limit.x> limits offset = ( offset > limit ) ? limit : offset; offset = ( offset < 0 ) ? 0 : offset; delta = data->offset.y - offset; data->offset.y = offset; break; case PAN_LEFT: // only change polarity of following position shift polarity = -1; case PAN_RIGHT: // compute maximum offset in x axis limit = data->dimension.x * data->zoom_factor - view->region.width; // compute actual shift in x value offset = data->offset.x + polarity * (gint)round(data->pan_percentage * view->region.width); // limit shift in x value to <0, limit.x> limits offset = ( offset > limit ) ? limit : offset; offset = ( offset < 0 ) ? 0 : offset; delta = data->offset.x - offset; data->offset.x = offset; break; default: delta = 0; } TRACE_MESSAGE(VIEW, TL_DEBUG, "Panning the image (view=%p, direction=%d, delta=%d)", view, direction, delta ); return 0 != delta; }
double generate_normalized( double mean, double sigma, double crop_min, double crop_max ) { TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "+sola::component::random::generate_normalized"); SERIALIZE_CALL(std::recursive_mutex, __random_lock); double result; std::normal_distribution<double> normal_dist(mean, sigma); if(!__random_initialized) { THROW_RANDOM_EXCEPTION(RANDOM_EXCEPTION_UNINITIALIZED); } if(sigma < 0.0) { THROW_RANDOM_EXCEPTION_MESSAGE( RANDOM_EXCEPTION_INVALID_PARAMETER, "spread < 0.0" ); } if(crop_min > crop_max) { THROW_RANDOM_EXCEPTION_MESSAGE( RANDOM_EXCEPTION_INVALID_PARAMETER, "crop_min > crop_max" ); } result = normal_dist(__random_generator); if(result < crop_min) { result = crop_min; } else if(result > crop_max) { result = crop_max; } TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "-sola::component::random::generate_normalized, result. " << result); return result; }
void XMLObjectCache::dumpCache() { TRACE_MESSAGE("****** Begin Object Instance Cache Dump ******"); // gthread_mutex_lock(&m_cs); XML_LOCK_MUTEX(&m_cs); GHashIterator iter(m_cache); while (iter()) { XMLObject *pObj = (XMLObject *)iter++; GString str; str.Format("Object In Cache - %s[%s](%s)RefCount=%d\n", pObj->GetObjectType(), pObj->GetObjectTag(), pObj->getOID(), pObj->GetRefCount()); TRACE_MESSAGE((const char *)str); } // gthread_mutex_unlock(&m_cs); XML_UNLOCK_MUTEX(&m_cs); TRACE_MESSAGE("****** End Object Instance Cache Dump ******"); }
bool Ini_UpdaterLists::saveRollbackInfo(const FileVector &rollbackList) { STRING section_name = SS_KEY_RollbackTree; long k = 0; STRING rollbackFileAndPath; if(!getProductFolder(m_useCurrentFolder, rollbackFileAndPath, pLog)) { TRACE_MESSAGE("Unable to save rollback information, because failed to get product folder"); return false; } rollbackFileAndPath += UPDATER_LISTS_FILENEME; TRACE_MESSAGE2("Saving rollback list to '%s'", rollbackFileAndPath.to_string().c_str()); removeRollbackSection(); // for output saved entries in rows and save space in trace file std::string savedEntries; unsigned long logLineSplitIndex = 0; for(FileVector::const_iterator iter = rollbackList.begin(); iter != rollbackList.end(); ++iter) { if(iter->m_rollbackChange == STRING(SS_KEY_RecentStatusAdded) || iter->m_rollbackChange == STRING(SS_KEY_RecentStatusModified) || iter->m_rollbackChange == STRING(SS_KEY_RecentStatusDeleted)) { STRING newSectionName; const long order_number = k++; makeNewSectionName(order_number, iter->m_filename, newSectionName); if(!saveRollbackListEntry(rollbackFileAndPath.c_str(), section_name.c_str(), order_number, newSectionName, *iter)) { TRACE_MESSAGE2("Unable to save rollback information for file entry '%s'", (iter->m_localPath + iter->m_filename).to_string().c_str()); return false; } // append comma before all items, but the very first one if(logLineSplitIndex++) savedEntries += ", "; // split line each 3 elements, but not before last element if(iter + 1 != rollbackList.end()) { if(!(logLineSplitIndex % 3)) savedEntries += "\n\t"; } savedEntries += (iter->m_localPath + iter->m_filename).to_string(); } } TRACE_MESSAGE3("Rollback information saved successfully to %s, entries: %s", rollbackFileAndPath.to_string().c_str(), savedEntries.c_str()); return true; }
void initialize( uint32_t seed ) { TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "+sola::component::random::initialize"); SERIALIZE_CALL(std::recursive_mutex, __random_lock); std::srand((uint32_t) std::time(NULL)); if(seed == GENERATE_RANDOM_SEED) { __random_generator.seed(rand()); } else { __random_generator.seed(seed); } __random_initialized = true; TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "-sola::component::random::initialize"); }
void KLUPD::HttpProtocol::closeSession() { if(!m_connected) return; TRACE_MESSAGE("Connection to HTTP server is closed by updater"); m_socket.close(); // SO_LINGER with 0 timeout assumed m_authorizationDriver.resetNtlmState(); m_connected = false; }
bool KLUPD::IniFile::save() { if(m_fileName.empty()) { TRACE_MESSAGE("Failed to save ini file, because no file name is specified"); return false; } FileStream file(pLog); if(!file.open(m_fileName, std::ios::out | std::ios::trunc)) { TRACE_MESSAGE2("Unable to save ini configuration file, because unable to open file '%S'", m_fileName.toWideChar()); return false; } for(std::vector<Section>::const_iterator sectionIter = m_sections.begin(); sectionIter != m_sections.end(); ++sectionIter) { bool wroteComment = false; if(!sectionIter->m_comment.empty()) { wroteComment = true; file.writeLine(NoCaseString(L"\n") + commentStr(sectionIter->m_comment)); } if(!sectionIter->m_name.empty()) { NoCaseString buffer = wroteComment ? L"\n" : L""; buffer += NoCaseString(L"[") + sectionIter->m_name + L"]"; file.writeLine(buffer); } for(std::vector<Key>::const_iterator keyIter = sectionIter->m_keys.begin(); keyIter != sectionIter->m_keys.end(); ++keyIter) { if(keyIter->m_key.empty()) continue; NoCaseString buffer = keyIter->m_comment.empty() ? L"" : L"\n"; buffer += commentStr(keyIter->m_comment); buffer += keyIter->m_comment.empty() ? L"" : L"\n"; buffer += keyIter->m_key.toWideChar(); buffer += s_equalIndicators[0]; buffer += keyIter->m_value; file.writeLine(buffer); } } m_dirty = false; return true; }
/** * This function executes user specified condition function on the specified * index. * * Since the function may fail from different reasons, we do not return boolean * value to indicate condition function result but store it to the destination * pointer by supplied pointer. * * \todo Find out better way for returning error * * \param group pointer to image list * \param index position of image in list * \param result pointer to storage for condition function result * \param test pointer to condition function * \param data pointer to data to be supplied into condition function * \return OK if condition function executed without fail */ RCode group_get_condition(ImageGroup* group, gint index, gboolean* result, ConditionFn* test, gpointer data) { ASSERT(NULL != group); ASSERT(NULL != group->list); TRACE_MESSAGE(IGRP, TL_INFO, "Checking condition (name='%s',index=%d,condition=0x%x)", group->name, index, test); if ( index < 0 || group->list->len <= index ) { ERROR_SET(ERROR.OUT_OF_RANGE); return FAIL; } ImageGroupRecord record = g_array_index(group->list, ImageGroupRecord, index); return test(&record,result, data); }
/** * This function yanks specified number of entries from group into yank buffer. * If the buffer is too small it will be reallocated * * \todo Yanking to non-empty yank buffer should result in buffer overwrite (ie * clear and insert) * * \param group image group from which images will be yanked * \param range index range which to yank * \return OK on success */ RCode group_yank_range(ImageGroup* group, Range range) { guint size = 0; guint i = 0; ASSERT(NULL != group); ASSERT(NULL != group->list); // check if yank buffer is clear and clear it if not if ( 0 != group_buffer_size() ) { if ( FAIL == group_buffer_clear() ) { ERROR_NOTE("Unable to clear internal yank buffer."); return FAIL; } } // check if index is in range if ( FAIL == range_check_bounds(range, 0, group->list->len - 1) ) { ERROR_SET(ERROR.OUT_OF_RANGE); ERROR_NOTE("Supplied range is out of bounds (group='%s',range=<%d,%d>,min=0,max=%d)", group->name, range.start,range.end,group->list->len-1); return FAIL; } size = range.end - range.start + 1; // realloc yank buffer if needed if ( group_buffer_max_size() < size ) { if ( OK != group_buffer_resize(size) ) { ERROR_NOTE("Image group yank buffer reallocation failed"); return FAIL; } } /* iterate over list until {size} records are yanked or list bounds are * reached */ TRACE_MESSAGE(IGRP, TL_INFO, "Yanking records from group (name='%s',range=<%d,%d>)", group->name, range.start, range.end ); for ( i = range.start; i <= range.end; i++) { ImageGroupRecord record = g_array_index(group->list, ImageGroupRecord, i ); // yank image from record into the buffer group_buffer_insert( record.image ); } return OK; }
/** * Compute new zoom from image dimensions and zoom type stored in image display * structure and return whenever the zoom has changed from original value. * * \param view pointer to image display view structure * \param data pointer to image display view data * \return TRUE if zoom has changed */ gboolean view_idv_compute_factor(ViewGeneric* view, ViewImageDisplay *data) { gdouble tmp_zoom1, tmp_zoom2; gboolean result; ASSERT( NULL != view ); ASSERT( NULL != data ); // compute zoom factor to be used in recomputation switch ( data->zoom_type ) { case ZOOM_FIT_CUSTOM: tmp_zoom1 = data->zoom_factor; break; case ZOOM_FIT_WIDTH: tmp_zoom1 = (gdouble)view->region.width / (gdouble)data->dimension.x; break; case ZOOM_FIT_HEIGHT: tmp_zoom1 = (gdouble)view->region.height / (gdouble)data->dimension.y; break; case ZOOM_FIT_IMAGE: tmp_zoom1 = (gdouble)view->region.width / (gdouble)data->dimension.x; tmp_zoom2 = (gdouble)view->region.height / (gdouble)data->dimension.y; // get lower value to achieve greater scale down or lesser scale up tmp_zoom1 = ( tmp_zoom1 < tmp_zoom2 ) ? tmp_zoom1 : tmp_zoom2; break; default: tmp_zoom1 = data->zoom_factor; } tmp_zoom1 = ( tmp_zoom1 < VIEW_ZOOM_MIN ) ? VIEW_ZOOM_MIN : tmp_zoom1; tmp_zoom1 = ( tmp_zoom1 > VIEW_ZOOM_MAX ) ? VIEW_ZOOM_MAX : tmp_zoom1; result = ! ZOOM_EQUAL(tmp_zoom1, data->zoom_factor); data->zoom_factor = tmp_zoom1; TRACE_MESSAGE(VIEW, TL_DEBUG, "Zoom factor has changed to (view=%p, zoom=%f)", view, data->zoom_factor ); return result; }
/** * The function uses view type to determine which data structure is * necessary for specific view of that type and allocates and initializes the * structure for view. * * \param view pointer to generic view structure * \return OK on success */ RCode view_create_specific_data(ViewGeneric *view) { RCode result = OK; ASSERT( NULL != view ); switch (view->type) { case VIEW_NONE: // this specific view does not have special data view->specific_data = NULL; break; case VIEW_APPLICATION: view->specific_data = (gpointer) view_app_create(view); result = ( NULL == view->specific_data ) ? FAIL : OK; break; case VIEW_IMAGE_DISPLAY: view->specific_data = (gpointer) view_idv_create(view); result = ( NULL == view->specific_data ) ? FAIL : OK; break; case VIEW_CONTAINER: view->specific_data = (gpointer) view_cv_create(view); result = ( NULL == view->specific_data ) ? FAIL : OK; break; case VIEW_LIST_STATUS: view->specific_data = (gpointer) view_lsv_create(view); result = ( NULL == view->specific_data ) ? FAIL : OK; break; default: // no need to fail, since no function can operate over specific data // of unknown view type TRACE_MESSAGE(VIEW, TL_INFO, "Unsupported view type (cntl=%p, type=%d)", view, view->type ); break; } return result; }
/** * The function requests application termination. * * \param model pointer to generic model structure * \return OK on success */ RCode model_app_quit(ModelGeneric *model) { ModelApplication* app_data = NULL; ASSERT( NULL != model ); app_data = model_app_get_data_pointer(model); if ( NULL == app_data ) { return FAIL; } if ( NULL != app_data->loop ) { TRACE_MESSAGE(MODL, TL_INFO, "Terminating GLIB event loop (model=%p)", model ); g_main_loop_quit(app_data->loop); return OK; } else { return FAIL; } }