/** * @param uri: The URI to read * @return Returns a widget displaying the URI contents or NULL on error * @brief Creates a widget to display the URI contents. Returns NULL on error */ Ewl_Widget * ewl_io_manager_uri_read(const char *uri) { Ewl_Widget *ret = NULL; Ewl_IO_Manager_Plugin *plugin = NULL; const char *mime; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET(uri, NULL); mime = ewl_io_manager_uri_mime_type_get(uri); if (!mime) { DWARNING("Unable to determine mime type for %s.", uri); DRETURN_PTR(NULL, DLEVEL_STABLE); } plugin = ewl_io_manager_plugin_get(mime); if (!plugin) { DWARNING("No plugin available to read mime type: %s.", mime); DRETURN_PTR(NULL, DLEVEL_STABLE); } ret = plugin->uri_read(uri); DRETURN_PTR(ret, DLEVEL_STABLE); }
static void node_response(ServicesData servicesData, struct Node *from, struct RequestData *request) { uint8_t *ptr = request->buffer; int type = GetFromBuffer8(&ptr); if (type == NODESERVICE_TYPE_TAKE) { size_t count = GetFromBuffer32(&ptr); if (request->len - 1 < count * ITEM_SIZE) { DWARNING("NODE SERVICE: node length is insufficient = %i\n", request->len - 1); return; } Array array = Array_init(0, sizeof(uint32_t)); for (size_t i = 0; i < count; i++) { uint32_t ip4addr = GetFromBuffer32NoOrder(&ptr); struct Node *client = nodes_get_node(ip4addr); if (!balancing_is_in_session(servicesData->balancer, ip4addr) && client && client->owned_by && nodes_is_me(client->owned_by)) { balancing_release_node(servicesData->balancer, client->ip4addr); Array_add(array, &ip4addr); } } if (Array_length(array) > 0) { NodeRequest request = { .type = NODESERVICE_TYPE_GIVE, .ip4array = array }; Services_Request(servicesData, NodeService_Get(), from, &request); }
void *shmat(int shmid, void *shmaddr, int shmflg) { PtrHandleChain dummy = start; DWORD dwDesiredAccess; HANDLE hFile = NULL; int res; DSECTION("shmat"); DSECTENTRYPOINT; if ((shmflg&SHM_RDONLY) == SHM_RDONLY) dwDesiredAccess = FILE_MAP_READ; else dwDesiredAccess = FILE_MAP_WRITE; while ((dummy != NULL) && (dummy->key != shmid)) dummy = dummy->next; if(dummy == NULL) { /* We have to open the mapping first. Hopefully someone else alredy created it...*/ res = shmget(shmid,0,0); if(res <0) { DWARNING("shmget failed for key"); DSECTLEAVE return (void *) -1; }
int timeout_wait(int fd, int timeout, int writing) { if (timeout <= 0) { // return TRUE; // true timeout = 0; } if (fd < 0) { DERROR("timeout_wait fd error: %d\n", fd); return FALSE; //error } // second to millisecond timeout = timeout * 1000; struct pollfd fds[1]; int ret; //struct timeval start, end; fds[0].fd = fd; while (1) { //gettimeofday(&start, NULL); if (writing) fds[0].events = POLLOUT; else fds[0].events = POLLIN; ret = poll(fds, 1, timeout); //DINFO("poll:%d\n", ret); if (ret < 0) { if (errno == EINTR) { /*gettimeofday(&end, NULL); unsigned int td = timediff(&start, &end); timeout -= td / 1000; if (timeout <= 0) return FALSE;*/ continue; } char errbuf[1024]; strerror_r(errno, errbuf, 1024); DWARNING("timeout_wait poll error: %d, %s\n", fds[0].fd, errbuf); return FALSE; } break; } /*DINFO("poll %x in:%d, out:%d, err:%d, hup:%d\n", fds[0].revents, fds[0].revents & POLLIN, fds[0].revents & POLLOUT, fds[0].revents & POLLERR, fds[0].revents & POLLHUP);*/ if ((fds[0].revents & POLLOUT) && writing) return TRUE; if ((fds[0].revents & POLLIN) && !writing) return TRUE; if ((fds[0].revents & POLLHUP) | (fds[0].revents & POLLERR)) return ERROR; return ERROR; }
/** * @param mime: The mime type to get the icon for * @return Returns the icon name for the given mime type or NULL if none found * @brief Retrives the icon name for the given mime type or NULL if none found */ const char * ewl_io_manager_mime_type_icon_name_get(const char *mime) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET(mime, NULL); DWARNING("NOT WRITTEN"); DRETURN_PTR(NULL, DLEVEL_STABLE); }
/** * @param ptr: the pointer to cast * @return The integer value of the pointer * * This function casts a pointer into an integer. If there should be an * information lost, i.e. the content of the pointer does not fit into * an integer, it will print a runtime warning. */ int ewl_cast_pointer_to_integer(void *ptr) { const unsigned int imask = ~0; const unsigned long int mask = ~((unsigned long int) imask); DENTER_FUNCTION(DLEVEL_STABLE); if (((unsigned long) ptr) & mask) DWARNING("Information lost while casting a pointer to an int"); DRETURN_INT((int)((long int)ptr), DLEVEL_STABLE); }
/** * @param string: The string to read * @param mime: The mime type to interpret the string as * @return Returns a widget representing the string in the given mime type * @brief Reads the given string and interprets it as the given mime type */ Ewl_Widget * ewl_io_manager_string_read(const char *string, const char *mime) { Ewl_IO_Manager_Plugin *plugin = NULL; Ewl_Widget *ret = NULL; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET(string, NULL); DCHECK_PARAM_PTR_RET(mime, NULL); plugin = ewl_io_manager_plugin_get(mime); if (!plugin) { DWARNING("No plugin available to read mime type: %s.", mime); DRETURN_PTR(NULL, DLEVEL_STABLE); } ret = plugin->string_read(string); DRETURN_PTR(ret, DLEVEL_STABLE); }
/** * readn - try to read n bytes with the use of a loop * * Return the bytes read. On error, -1 is returned. */ ssize_t readn(int fd, void *vptr, size_t n, int timeout) { size_t nleft; ssize_t nread; char *ptr; ptr = vptr; nleft = n; while (nleft > 0) { if (timeout_wait_read(fd, timeout) == FALSE) { DWARNING("read timeout.\n"); break; } nread = read(fd, ptr, nleft); //DINFO("read return:%d\n", nread); if (nread < 0) { char errbuf[1024]; strerror_r(errno, errbuf, 1024); //DERROR("nread: %d, error: %s\n", nread, errbuf); if (errno == EINTR) { nread = 0; }else { char errbuf[1024]; strerror_r(errno, errbuf, 1024); DERROR("readn error: %s\n", errbuf); //MEMLINK_EXIT; return -1; } }else if (nread == 0) { DERROR("read 0, maybe conn close.\n"); break; } nleft -= nread; ptr += nread; } return (n - nleft); }
/** * @param n: The Ewl_Notebook to get the tab widget from * @param page: The page to get the tab from * @return Returns the tab widget associated with the given page * @brief Retrieve the widget used as the tab for the page @p page */ Ewl_Widget * ewl_notebook_page_tab_widget_get(Ewl_Notebook *n, Ewl_Widget *page) { Ewl_Widget *t, *o; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET(n, NULL); DCHECK_PARAM_PTR_RET(page, NULL); DCHECK_TYPE_RET(n, EWL_NOTEBOOK_TYPE, NULL); DCHECK_TYPE_RET(page, EWL_WIDGET_TYPE, NULL); t = ewl_attach_widget_association_get(page); if (!t) { DWARNING("We have a notebook page with no tab, bad, very bad."); DRETURN_PTR(NULL, DLEVEL_STABLE); } o = ewl_container_child_get(EWL_CONTAINER(t), 0); DRETURN_PTR(o, DLEVEL_STABLE); }
/** * @param data: The data to write * @param string: Where to write * @param mime: The mime type to write as * @return Returns TRUE if the write is successful, FALSE otherwise * @brief Writes the given data into the given string pointer */ int ewl_io_manager_string_write(Ewl_Widget *data, char **string, const char *mime) { Ewl_IO_Manager_Plugin *plugin = NULL; int ret = 0; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET(data, FALSE); DCHECK_PARAM_PTR_RET(mime, FALSE); DCHECK_TYPE_RET(data, EWL_WIDGET_TYPE, FALSE); plugin = ewl_io_manager_plugin_get(mime); if (!plugin) { DWARNING("No plugin available to write mime type: %s.", mime); DRETURN_INT(FALSE, DLEVEL_STABLE); } ret = plugin->string_write(data, string); DRETURN_INT(ret, DLEVEL_STABLE); }
/** attempt to open any supported filetype */ Audio_File * Audio_File::from_file ( const char * filename ) { Block_Timer timer( "Opened audio file" ); Audio_File *a; if ( ( a = _open_files[ std::string( filename ) ] ) ) { ++a->_refs; return a; } if ( ( a = Audio_File_SF::from_file( filename ) ) ) goto done; // TODO: other formats DWARNING( "creating dummy source for \"%s\"", filename ); /* FIXME: wrong place for this? */ if ( ( a = Audio_File_Dummy::from_file( filename ) ) ) goto done; return NULL; done: ASSERT( ! _open_files[ std::string( filename ) ], "Programming errror" ); _open_files[ std::string( filename ) ] = a; a->_refs = 1; return a; }
bool IconCacheCreator::createCacheFile(const QString &cachePath, bool force) { QFileInfo themePath(m_path); if (!(themePath.exists() && themePath.isDir() && themePath.isReadable())) { DPRINT("theme path invaild."); return false; } QFile cacheFile(cachePath); if (cacheFile.exists()) { if (force) { cacheFile.remove(); } else { DPRINT("cache file existed and can not force."); return false; } } if (!cacheFile.open(QIODevice::WriteOnly)) { DPRINT("can not open cache file: %s", qPrintable(cachePath)); return false; } QFile indexFile(m_path + "/" + INDEX_FILE_NAME); if (!indexFile.open(QIODevice::ReadOnly)) { DPRINT("the index file of theme can not open."); return false; } QList<DirEntry *> dirEntryList; QSet<int> size; QSet<QString> cates; this->loadIndex(indexFile, dirEntryList, size, cates); QHash<QString, qint64> iconList; QStringList filters; filters.append("*.png"); filters.append("*.xpm"); filters.append("*.svg"); QDataStream out(&cacheFile); out.setByteOrder(QDataStream::LittleEndian); QString keystr("%1-%2-%3"); QString key; struct IconCache cache; out.writeRawData((const char *)&cache, sizeof(struct IconCache)); cache.sizeHdr.num = size.size(); cache.sizeHdr.sizes = out.device()->pos(); this->writeSizeToCache(out, size.toList()); cache.cateHdr.num = cates.size(); cache.cateHdr.cates = cacheFile.pos(); this->writeCatesToCache(out, cates.toList()); for (int i = 0; i < dirEntryList.size(); i++) { if (dirEntryList.at(i) == NULL) { continue; } QDir dir(m_path); if (!dir.cd(dirEntryList.at(i)->path)) { DWARNING("theme subdir can not enter: %s", qPrintable(dirEntryList.at(i)->path)); continue; } DPRINT("Dir in: %s", qPrintable(dir.canonicalPath())); QFileInfoList files = dir.entryInfoList(filters); for (int j = 0; j < files.size(); j++) { QFileInfo f = files.at(j); key = keystr.arg(QString::number(dirEntryList.at(i)->size), dirEntryList.at(i)->type, f.fileName()); qint64 iconOffset = cacheFile.pos(); if (!this->writeIconToCache(out, f)) { continue; } DPRINT("key: %s,%d", qPrintable(key), iconOffset); iconList.insert(key, iconOffset); } } DPRINT("Finished write icon data."); DPRINT("iconList: %d", iconList.size()); cache.hashHdr.num = iconList.size(); writeHashToCache(out, iconList, &(cache.hashHdr.data)); DPRINT("Finished write hash data."); cacheFile.seek(0); DPRINT("%lld", cacheFile.size()); out.writeRawData((const char *)&cache, sizeof(struct IconCache)); DPRINT("%lld", cacheFile.size()); if (out.byteOrder() == QDataStream::BigEndian) { DPRINT("big endian"); } cacheFile.close(); DPRINT("sizeof iconcahce: %d", sizeof(struct IconCache)); DPRINT("Finished write head."); for (int i = 0; i < dirEntryList.size(); i++) { delete dirEntryList.at(i); } return true; }
int tcp_socket_connect(char *host, int port, int timeout, int block) { int fd; int ret; fd = socket(AF_INET, SOCK_STREAM, 0); if (fd == -1) { char errbuf[1024]; strerror_r(errno, errbuf, 1024); DERROR("create socket error: %s\n", errbuf); return -1; } if (block == FALSE) set_noblock(fd); struct linger ling = {1, 0}; ret = setsockopt(fd, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling)); if (ret != 0) { char errbuf[1024]; strerror_r(errno, errbuf, 1024); DERROR("setsockopt LINGER error: %s\n", errbuf); return -1; } int flags = 1; ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&flags, sizeof(flags)); if (ret != 0) { char errbuf[1024]; strerror_r(errno, errbuf, 1024); DERROR("setsockopt NODELAY error: %s\n", errbuf); return -1; } ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags)); if (ret != 0) { char errbuf[1024]; strerror_r(errno, errbuf, 1024); DERROR("setsockopt KEEPALIVE error: %s\n", errbuf); return -1; } struct sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons((short)port); if (NULL == host || 0 == host[0]) { sin.sin_addr.s_addr = htonl(INADDR_ANY); }else{ sin.sin_addr.s_addr = inet_addr(host); } DINFO("connect to %s:%d\n", host, port); do { ret = connect(fd, (struct sockaddr*)&sin, sizeof(sin)); } while (ret == -1 && errno == EINTR); DINFO("ret: %d\n", ret); if (ret == -1) { if (errno == EINPROGRESS || errno == EALREADY || errno == EWOULDBLOCK || errno == 0 || errno == EISCONN) return fd; char errbuf[1024]; strerror_r(errno, errbuf, 1024); DWARNING("connect error: %s\n", errbuf); close(fd); return -1; } return fd; }
bool freespace_find( freespace* fs, basebox* boundary, int flags, int width, int height, int* resultx, int* resulty ) { *resultx = *resulty = -1; #ifdef FSDEBUG char* pstr = freespace_placement_to_str(flags); DMESSAGE("\n---------------------------\n" "flags:%s\tarea w:%d, h:%d\n" "boundary x:%d,y:%d, w:%d, h:%d\n", pstr, width, height, boundary->x, boundary->y, boundary->w, boundary->h); #endif if (width < 1 || width > boundary->w || height < 1 || height > boundary->h) { #ifdef FSDEBUG DWARNING("\ninvalid area or area does not fit in boundary\n"); #endif return false; } if (flags & FSPLACE_ROW_SMART) { if (flags & FSPLACE_LEFT_TO_RIGHT) { return row_smart_l2r(fs->row_buf, boundary->x, boundary->y, boundary->w, boundary->h, flags, width, height, resultx, resulty); } else { return row_smart_r2l(fs->row_buf, boundary->x, boundary->y, boundary->w, boundary->h, flags, width, height, resultx, resulty); } } else { /* the row smart algorithm can be used for column-smart by rotating 90 degrees clockwise... */ bool ret; int rx = FSWIDTH - boundary->y - boundary->h; int ry = boundary->x; int rflags = (flags & FSPLACE_LEFT_TO_RIGHT) ? FSPLACE_TOP_TO_BOTTOM : 0; rflags |= (flags & FSPLACE_TOP_TO_BOTTOM) ? 0 : FSPLACE_LEFT_TO_RIGHT; #ifdef FSDEBUG pstr = freespace_placement_to_str(rflags); DMESSAGE("\n---------------------------\n" "rflags:%s\tarea w:%d, h:%d\n" "boundary rx:%d, ry:%d, w:%d, h:%d\n", pstr, width, height, rx, ry, boundary->w, boundary->h); #endif if (rflags & FSPLACE_LEFT_TO_RIGHT) { ret = row_smart_l2r(fs->col_buf, rx, ry, boundary->h, boundary->w, rflags, height, width, resultx, resulty); } else { ret = row_smart_r2l(fs->col_buf, rx, ry, boundary->h, boundary->w, rflags, height, width, resultx, resulty); } if (!ret) return false; /* translate result back by 'rotation' 90 anti-clockwise */ rx = *resultx; *resultx = *resulty; *resulty = FSWIDTH - rx - height; return true; } WARNING("unrecognized placement flags:%d\n", flags); return false; }