inline void SimulatedBlock::executeFunction(GlobalSignalNumber gsn, Signal* signal){ ExecFunction f = theExecArray[gsn]; if(gsn <= MAX_GSN && f != 0){ #ifdef VM_TRACE clear_global_variables(); #endif (this->*f)(signal); return; } /** * This point only passed if an error has occurred */ char errorMsg[255]; if (!(gsn <= MAX_GSN)) { BaseString::snprintf(errorMsg, 255, "Illegal signal received (GSN %d too high)", gsn); ERROR_SET(fatal, NDBD_EXIT_PRGERR, errorMsg, errorMsg); } if (!(theExecArray[gsn] != 0)) { BaseString::snprintf(errorMsg, 255, "Illegal signal received (GSN %d not added)", gsn); ERROR_SET(fatal, NDBD_EXIT_PRGERR, errorMsg, errorMsg); } ndbrequire(false); }
/** * 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; }
/** * Setup one of the child nodes as a new focus node * * \param view pointer to container view structure * \param node new child node to set as focus * \return FAIL if current focus and new focus have different top */ RCode view_cv_node_set_focus(ViewGeneric *view, ContainerNode *node) { ViewContainer* cv_data = NULL; ContainerNode *new_top = NULL; ASSERT( NULL != view ); ASSERT( NULL != node ); if ( CONTAINER_LEAF != node->type ) { ERROR_SET(ERROR.INVALID_PARAM); ERROR_NOTE("Non-leaf node can't be set as focus node"); return FAIL; } cv_data = view_cv_get_data_pointer(view); if ( NULL == cv_data ) { return FAIL; } // find top node to which the top node is associated for ( new_top = node; new_top->parent != NULL; new_top = new_top->parent); if ( cv_data->top_node != new_top ) { ERROR_SET(ERROR.INVALID_PARAM); ERROR_NOTE("Topmost parent of new focus is not current top node"); return FAIL; } cv_data->focus_node = node; return OK; }
/** * 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; }
/** * Allocate memory for image display view structure and initialize it with * correct values. * * \return pointer to image display specific data */ ViewImageDisplay* view_idv_create(ViewGeneric *parent) { const ConfigStorage* conf; ViewImageDisplay *result = NULL; ASSERT( NULL != parent ); if ( NULL == ( result = (ViewImageDisplay*) g_try_malloc0(sizeof(ViewImageDisplay))) ) { ERROR_SET(ERROR.MEMORY_FAILURE); return result; } result->dimension.x = 0; result->dimension.y = 0; result->view_buffer = NULL; // either get parameters for zooming from configuration or get default if it // is not present conf = config_get(); if ( NULL == conf ) { ERROR_LOG(); result->zoom_factor = 1.0; result->zoom_type = ZOOM_FIT_CUSTOM; result->pan_percentage = VIEW_PAN_PERCENTAGE; } else { result->zoom_factor = conf->zoom; result->zoom_type = conf->auto_zoom; result->pan_percentage = conf->pan_percentage; } return result; }
/** * Allocate memory for generic view structure and setup the type correctly. * Depending on the type, call appropriate create() method for specific view and * let it handle specific view stuff. * * The reference count in the new structure is set to 1 to indicate that there * is only one place which references it - the variable storing pointer returned * from function. * * \param type which specific view to create * \return pointer to generic view structure */ ViewGeneric* view_create(ViewType type) { ViewGeneric *result = NULL; if ( NULL == ( result = (ViewGeneric*) g_try_malloc0(sizeof(ViewGeneric))) ) { ERROR_SET(ERROR.MEMORY_FAILURE); return result; } result->type = type; result->reference = 1; // all generic data must be set before specific data creation since the // function that creates specific data may need to update it. result->window = NULL; result->region.x = 0; result->region.y = 0; result->region.width = 0; result->region.height = 0; result->last_sequence = 0; result->specific_data = NULL; if ( FAIL == view_create_specific_data(result) ) { ERROR_NOTE("Unable to create view specific data"); g_free( (gpointer)result ); return NULL; } return result; }
void AsyncFile::doStart() { // Stacksize for filesystem threads #if !defined(DBUG_OFF) && defined (__hpux) // Empirical evidence indicates at least 32k const NDB_THREAD_STACKSIZE stackSize = 32768; #else // Otherwise an 8k stack should be enough const NDB_THREAD_STACKSIZE stackSize = 8192; #endif char buf[16]; numAsyncFiles++; BaseString::snprintf(buf, sizeof(buf), "AsyncFile%d", numAsyncFiles); theStartMutexPtr = NdbMutex_Create(); theStartConditionPtr = NdbCondition_Create(); NdbMutex_Lock(theStartMutexPtr); theStartFlag = false; theThreadPtr = NdbThread_Create(runAsyncFile, (void**)this, stackSize, (char*)&buf, NDB_THREAD_PRIO_MEAN); if (theThreadPtr == 0) ERROR_SET(fatal, NDBD_EXIT_MEMALLOC, "","Could not allocate file system thread"); NdbCondition_Wait(theStartConditionPtr, theStartMutexPtr); NdbMutex_Unlock(theStartMutexPtr); NdbMutex_Destroy(theStartMutexPtr); NdbCondition_Destroy(theStartConditionPtr); }
/** * 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; }
AsyncFile* Ndbfs::createAsyncFile(){ // Check limit of open files if (m_maxFiles !=0 && theFiles.size() == m_maxFiles) { // Print info about all open files for (unsigned i = 0; i < theFiles.size(); i++){ AsyncFile* file = theFiles[i]; ndbout_c("%2d (0x%lx): %s", i, (long) file, file->isOpen()?"OPEN":"CLOSED"); } ERROR_SET(fatal, NDBD_EXIT_AFS_MAXOPEN,""," Ndbfs::createAsyncFile"); } AsyncFile* file = new AsyncFile(* this); file->doStart(); // Put the file in list of all files theFiles.push_back(file); #ifdef VM_TRACE infoEvent("NDBFS: Created new file thread %d", theFiles.size()); #endif return file; }
/** * 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; }
//***************************************************************************** inline bool OpenFiles::insert(AsyncFile* file, Uint16 id){ // Check if file has already been opened for (unsigned i = 0; i < m_files.size(); i++){ if(m_files[i].m_file == NULL) continue; if(strcmp(m_files[i].m_file->theFileName.c_str(), file->theFileName.c_str()) == 0) { BaseString names; names.assfmt("open: >%s< existing: >%s<", file->theFileName.c_str(), m_files[i].m_file->theFileName.c_str()); ERROR_SET(fatal, NDBD_EXIT_AFS_ALREADY_OPEN, names.c_str(), "OpenFiles::insert()"); } } // Insert the file into vector OpenFileItem openFile; openFile.m_id = id; openFile.m_file = file; m_files.push_back(openFile); return true; }
/* * db_seq_insert() - This function inserts a value into a sequence at the * specified position. All elements starting from that position will be * shifted down to make room for the new element. As with other sequence * building functions, the domain of the value must be compatible with the * domain of the sequence. The sequence will automatically grow to make room * for the new value. Any existing slots that contain NULL will not be * reused because NULL is a valid sequence element. If the index is beyond * the length of the sequence, the sequence will grow and the value is * appended. * return : error code * set(in): sequence descriptor * index(in): element index * value(in): value to insert */ int db_seq_insert (DB_SET * set, int index, DB_VALUE * value) { int error = NO_ERROR; CHECK_CONNECT_ERROR (); CHECK_1ARG_ERROR (set); /* Check if modifications are disabled only if the set is owned */ if (set->owner != NULL) { CHECK_MODIFICATION_ERROR (); } if ((value != NULL) && (DB_VALUE_TYPE (value) > DB_TYPE_LAST)) { ERROR_SET (error, ER_OBJ_INVALID_ARGUMENTS); } else { error = set_insert_element (set, index, value); } return (error); }
Uint32 TimeQueue::getIndex() { Uint32 retValue = globalData.theFirstFreeTQIndex; globalData.theFirstFreeTQIndex = (Uint32)theFreeIndex[retValue]; if (retValue >= MAX_NO_OF_TQ) ERROR_SET(fatal, NDBD_EXIT_TIME_QUEUE_INDEX, "Index out of range", "TimeQueue.C" ); return retValue; }
/** * Allocate memory for application model structure and initialize it with * correct values. * * \return pointer to application model structure */ ModelApplication* model_app_create() { ModelApplication *result = NULL; if ( NULL == ( result = (ModelApplication*) g_try_malloc0(sizeof(ModelApplication))) ) { ERROR_SET(ERROR.MEMORY_FAILURE); return result; } result->loop = NULL; return result; }
/** * Allocate memory for list status view structure and initialize it with * correct values. * * \todo: All of the values are hardcoded now, but it should be possible to make * them used settable through configuration storage. It would mean to refactor * the configuration storage though (flag option list won't be sufficient * anymore, especially for colors). * * \return pointer to image display specific data */ ViewListStatus* view_lsv_create(ViewGeneric *parent) { const ConfigStorage* conf; ViewListStatus *result = NULL; GdkFont* font = NULL; ASSERT( NULL != parent ); font = gdk_font_load(DEFAULT_FONT_NAME); if ( NULL == font ) { ERROR_SET(ERROR.INVALID_PARAM); ERROR_NOTE("Font %s does not load", DEFAULT_FONT_NAME); return result; } if ( NULL == ( result = (ViewListStatus*) g_try_malloc0(sizeof(ViewListStatus))) ) { ERROR_SET(ERROR.MEMORY_FAILURE); return result; } result->border_size.x = 5; result->border_size.y = 2; /// \todo for now, we assume that the font is monospace and does not contain // wide characters result->text_size.x = gdk_char_width(font, 'A'); result->text_size.y = gdk_char_height(font, 'A'); result->color.fg.red = 65535; result->color.fg.green = 65535; result->color.fg.blue = 65535; result->color.bg.red = 0; result->color.bg.green = 0; result->color.bg.blue = 0; result->font = font; parent->region_hint.y = result->text_size.y + 2 * result->border_size.y; return result; }
void EmulatorData::create(){ /* Global jam() buffer, for non-multithreaded operation. For multithreaded ndbd, each thread will set a local jam buffer later. */ #ifndef NO_EMULATED_JAM void * jamBuffer = (void *)&theEmulatedJamBuffer; #else void * jamBuffer = 0; #endif NdbThread_SetTlsKey(NDB_THREAD_TLS_JAM, jamBuffer); NdbMem_Create(); theConfiguration = new Configuration(); theWatchDog = new WatchDog(); theThreadConfig = new ThreadConfig(); theSimBlockList = new SimBlockList(); m_socket_server = new SocketServer(); m_mem_manager = new Ndbd_mem_manager(); globalData.m_global_page_pool.setMutex(); if (theConfiguration == NULL || theWatchDog == NULL || theThreadConfig == NULL || theSimBlockList == NULL || m_socket_server == NULL || m_mem_manager == NULL ) { ERROR_SET(fatal, NDBD_EXIT_MEMALLOC, "Failed to create EmulatorData", ""); } if (!(theShutdownMutex = NdbMutex_Create())) { ERROR_SET(fatal, NDBD_EXIT_MEMALLOC, "Failed to create shutdown mutex", ""); } }
/** * This function returns pointer to the image on {index} position in image list * * \param group pointer to image list * \param index position of image in list * \return Image pointer on success, NULL otherwise */ Image* group_get_image(ImageGroup* group, gint index) { ASSERT(NULL != group); ASSERT(NULL != group->list); if ( 0 <= index && index <= group->list->len ) { ImageGroupRecord record = g_array_index(group->list, ImageGroupRecord, index); return record.image; } else { ERROR_SET(ERROR.OUT_OF_RANGE); ERROR_NOTE("Index %d is out of range <%d,%d>", index, 0, group->list->len - 1 ); return NULL; } }
/** * 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); }
/** * The function checks the type of the view and either cast the pointer to * correct type or return NULL to indicate error. * * This function can use NULL for error indication because list status view * should always have specific data. * * \param view pointer to list status view structure * \return ViewApplication pointer or NULL on error */ ViewListStatus* view_lsv_get_data_pointer(ViewGeneric* view) { ASSERT( NULL != view ); if ( VIEW_LIST_STATUS != view->type ) { return NULL; } if ( NULL == view->specific_data ) { ERROR_SET(ERROR.INVALID_OPERATION); ERROR_NOTE("Specific data pointer is NULL"); return NULL; } return (ViewListStatus*) view->specific_data; }
/** * This function creates new image list instace and set its name and tag. It * also creates emty array of ImageGroupRecord elements which will be used as * storage. * * \param groupName string with image list long identification * \param groupTag character with image list short identification * \return ImageGroup pointer on success, NULL otherwise */ ImageGroup* group_create(gchar* groupName, gchar groupTag) { ImageGroup* tmp_group = NULL; if ( NULL == groupName ) { groupName = "unknown"; } TRACE_MESSAGE(IGRP, TL_MINOR, "Creating group (name='%s',tag='%c')", groupName, groupTag); if ( NULL == ( tmp_group = (ImageGroup*) g_try_malloc(sizeof(ImageGroup))) ) { ERROR_SET(ERROR.MEMORY_FAILURE); return NULL; } if ( NULL == (tmp_group->name = g_strdup(groupName)) ) { ERROR_SET(ERROR.MEMORY_FAILURE); g_free((gpointer)tmp_group); return NULL; } tmp_group->list = g_array_new(FALSE, FALSE, sizeof(ImageGroupRecord)); tmp_group->tag = groupTag; return tmp_group; }
/** * The function checks the type of the view and either cast the pointer to * correct type or return NULL to indicate error. * * This function can use NULL for error indication because image display view * should always have specific data. * * \param view pointer to image display view structure * \return ViewApplication pointer or NULL on error */ ViewImageDisplay* view_idv_get_data_pointer(ViewGeneric* view) { ASSERT( NULL != view ); if ( VIEW_IMAGE_DISPLAY != view->type ) { return NULL; } if ( NULL == view->specific_data ) { ERROR_SET(ERROR.INVALID_OPERATION); ERROR_NOTE("Specific data pointer is NULL"); return NULL; } return (ViewImageDisplay*) view->specific_data; }
/** * The function checks the type of the view and either cast the pointer to * correct type or return NULL to indicate error. * * This function can use NULL for error indication because container view * should always have specific data. * * \param view pointer to container view structure * \return ViewContainer pointer or NULL on error */ ViewContainer* view_cv_get_data_pointer(ViewGeneric* view) { ASSERT( NULL != view ); if ( VIEW_CONTAINER != view->type ) { return NULL; } if ( NULL == view->specific_data ) { ERROR_SET(ERROR.INVALID_OPERATION); ERROR_NOTE("Specific data pointer is NULL"); return NULL; } return (ViewContainer*) view->specific_data; }
/** * The function checks the type of the model and either cast the pointer to * correct type or return NULL to indicate error. * * This function can use NULL for error indication because application model * should always have specific data. * * \param model pointer to generic model structure * \return ModelApplication pointer or NULL on error */ ModelApplication* model_app_get_data_pointer(ModelGeneric* model) { ASSERT( NULL != model ); if ( MODEL_APPLICATION != model->type ) { return NULL; } if ( NULL == model->specific_data ) { ERROR_SET(ERROR.INVALID_OPERATION); ERROR_NOTE("Specific data pointer is NULL"); return NULL; } return (ModelApplication*) model->specific_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; }
struct NdbThread* AsyncIoThread::doStart() { // Stacksize for filesystem threads const NDB_THREAD_STACKSIZE stackSize = 128*1024; char buf[16]; numAsyncFiles++; BaseString::snprintf(buf, sizeof(buf), "AsyncIoThread%d", numAsyncFiles); theStartMutexPtr = NdbMutex_Create(); theStartConditionPtr = NdbCondition_Create(); NdbMutex_Lock(theStartMutexPtr); theStartFlag = false; theThreadPtr = NdbThread_Create(runAsyncIoThread, (void**)this, stackSize, buf, NDB_THREAD_PRIO_MEAN); if (theThreadPtr == 0) { ERROR_SET(fatal, NDBD_EXIT_MEMALLOC, "","Could not allocate file system thread"); } do { NdbCondition_Wait(theStartConditionPtr, theStartMutexPtr); } while (theStartFlag == false); NdbMutex_Unlock(theStartMutexPtr); NdbMutex_Destroy(theStartMutexPtr); NdbCondition_Destroy(theStartConditionPtr); return theThreadPtr; }
/** * The function requests toggle of the fullscreen setting of the application * window. * * \param model pointer to generic model structure * \param window pointer to the window to toggle * \return OK on success */ RCode model_app_toggle_fullscreen(ModelGeneric *model, GdkWindow* window) { GdkWindowState window_state; ASSERT( NULL != model ); TRACE_MESSAGE(MODL, TL_INFO, "Toggle fullscreen mode (model=%p)", model); if ( NULL == window ) { ERROR_SET(ERROR.INVALID_PARAM); ERROR_NOTE("Pointer to window is NULL"); return FAIL; } window_state = gdk_window_get_state(window); if ( 0 == (GDK_WINDOW_STATE_FULLSCREEN & window_state) ) { gdk_window_fullscreen(window); } else { gdk_window_unfullscreen(window); } return OK; }
/** * This function executes action function on one record in image group specified * by its index. * * \param group pointer to image list * \param index index if image to be modified * \param action pointer to action function which will be used for modification * \return OK on success */ RCode group_execute_index(ImageGroup* group, gint index, ActionFn* action) { ImageGroupRecord* record = NULL; ASSERT(NULL != group); ASSERT(NULL != group->list); ASSERT(NULL != action ); TRACE_MESSAGE(IGRP, TL_INFO, "Executing action (name='%s',index=%d,action=0x%x)", group->name, index, action ); // check if index is in bounds if ( index < 0 || group->list->len <= index) { ERROR_SET(ERROR.OUT_OF_RANGE); return FAIL; } // get image record from the list record = &g_array_index(group->list, ImageGroupRecord, index); return action(record); }
/** * The method resize updates the view internal variables to the changed region * size. * * Resize the image view buffer to the new dimensions. * * \param view view to resize * \param newRegion the size of the new region * \return OK on success */ RCode view_idv_resize(ViewGeneric *view, GdkRectangle newRegion) { ViewImageDisplay* idv_data = NULL; ASSERT( NULL != view ); idv_data = view_idv_get_data_pointer(view); if ( NULL == idv_data ) { return FAIL; } // check if buffer need to be resized if ( newRegion.width != view->region.width || newRegion.height != view->region.height ) { if ( NULL != idv_data->view_buffer ) { g_object_unref( (gpointer)idv_data->view_buffer ); } // allocate pixbuf for view region idv_data->view_buffer = gdk_pixbuf_new( GDK_COLORSPACE_RGB, FALSE, VIEW_BITS_PER_COLOR, newRegion.width, newRegion.height ); if ( NULL == idv_data->view_buffer ) { ERROR_SET(ERROR.MEMORY_FAILURE); ERROR_NOTE("View image buffer allocation failed"); return FAIL; } // this is done in generic view, but we duplicate the code here since we // need to have view region updated prior buffer content regeneration view->region = newRegion; // re-generate content of the view buffer return view_idv_generate_buffer(view, idv_data, FALSE); } return OK; }
/** * Allocate memory for container view structure and initialize it with * correct values. * * \return pointer to container view structure */ ViewContainer* view_cv_create(ViewGeneric *parent) { ViewContainer *result = NULL; ContainerNode* node = NULL; ASSERT( NULL != parent ); node = container_node_create(CONTAINER_LEAF, NODE_VERTICAL); if ( NULL == node ) { ERROR_NOTE("Can't allocate root node for container view."); return NULL; } result = (ViewContainer*) g_try_malloc0(sizeof(ViewContainer)); if ( NULL == result ) { ERROR_SET(ERROR.MEMORY_FAILURE); container_node_destroy(node); return result; } result->top_node = node; result->focus_node = node; result->color.active.red = 0; result->color.active.green = 65535; result->color.active.blue = 65535; result->color.inactive.red = 0; result->color.inactive.green = 0; result->color.inactive.blue = 65535; result->color.bg.red = 0; result->color.bg.green = 0; result->color.bg.blue = 0; return result; }
/** * Call specific view destroy() function and then deallocate the generic view * and do a cleanup. * * \param view pointer to generic view structure * \return OK on success */ RCode view_destroy(ViewGeneric *view) { ASSERT( NULL != view ); // check reference count if ( 0 != view->reference ) { ERROR_SET(ERROR.INVALID_OPERATION); ERROR_NOTE("Reference count is non-zero"); return FAIL; } // remove links to the model and controller view_set_model(view, NULL); view_set_controller(view, NULL); // deallocate specific view data if some are present if ( NULL != view->specific_data ) { view_destroy_specific_data(view); } // destroy generic view structure g_free( (gpointer)view ); return OK; }