int insert_cache(char *url, char *content, int size) { if (size > MAX_OBJECT_SIZE) { return -1; } while (current_cache_size + size > MAX_CACHE_SIZE) { remove_cache(); } cache_t* newcache = calloc(1, sizeof(cache_t)); // P(&access_cache); pthread_rwlock_wrlock(&lock); if (!cache_tail) { cache_head = newcache; cache_tail = cache_head; } else { cache_tail->next = newcache; newcache->prev = cache_tail; cache_tail = newcache; } newcache->url = calloc(strlen(url)+1, sizeof(char)); //including the NULL at the end newcache->content = calloc(size, sizeof(char)); strcpy(newcache->url, url); memcpy(newcache->content, content, size); newcache->size = size; current_cache_size += size; // V(&access_cache); pthread_rwlock_unlock(&lock); return 0; }
int Read_Kinect::control_running() { int rtn = 0; WaitForSingleObject(h1, INFINITE); //drawColor(h2); WaitForSingleObject(h3, INFINITE); drawDepth(h4); WaitForSingleObject(h5, INFINITE); //_depth.copyTo(_skeleton); //drawSkeleton(_skeleton); drawSkeleton(); if (_remove_num > 0) { remove_cache(); } fall_detection.falldetectiondistance(_avg_dis); _if_fall_down = fall_detection.get_fall_output_dis(); //visualization_update(); //imshow("Activity Recognition", _dispImg); return rtn; }
bool upload_file(char *path,char * filename,nsp_node &info,nsp_node &recv,bool simpletype=false,void *callfunc=NULL){ nsplog("上传文件",filename); char cfile[MAX_PATH]; char appid[33]; char server[32]; char tstr[32]; char secret[33]; nsp_node *nsp_search; nspAction *nA=NSPAction(); if(nA==NULL){return false;} nsp_file_info file_info; memset(file_info.filename,0,sizeof(file_info.filename)); file_info.nsi.next=NULL; int nspfsize = -1; //upauth information nsp_search = nA->searchNodeByStr(&info,"nsp_tapp"); if(nsp_search!=NULL){strcpy(appid,nsp_search->node_data.valuestring);}else{nsplog("内部错误","文件上传鉴权出错");goto upload_fail;} nsp_search = nA->searchNodeByStr(&info,"nsp_host"); if(nsp_search!=NULL){strcpy(server,nsp_search->node_data.valuestring);}else{nsplog("内部错误","文件上传鉴权出错");goto upload_fail;} nsp_search = nA->searchNodeByStr(&info,"nsp_tstr"); if(nsp_search!=NULL){sprintf(tstr,"%d",nsp_search->node_data.valueint);}else{nsplog("内部错误","文件上传鉴权出错");goto upload_fail;} nsp_search = nA->searchNodeByStr(&info,"secret"); if(nsp_search!=NULL){strcpy(secret,nsp_search->node_data.valuestring);}else{nsplog("内部错误","文件上传鉴权出错");goto upload_fail;} strcpy(cfile, filename); nspfsize = get_file_size(cfile); //get length of file if(nspfsize == -1){ nsplog("内部错误","获取上传文件大小出错"); goto upload_fail; } if(nspfsize>BIGFILESIZE){ file_info.isbigfile=true; } else{file_info.isbigfile=false;} // store file(>100M) seginfo // control big file size if(!abletoUpload(nspfsize)){ nsplog("内部错误","网盘空间已满或者无权限上传大文件"); goto upload_fail; } if(!load_fileinfo(file_info,filename)){ nsplog("内部错误","获取/计算文件信息出错"); goto upload_fail; } sent_bytes = 0; nsp_ret_t nsp_ret; if(!up_init(appid,server, tstr, secret, cfile, nspfsize, &nsp_ret ,file_info.pfileid )){ nsplog("内部错误","上传初始化失败"); goto upload_fail; } while(1){ switch (nsp_ret.nsp_upcmd){ case REQTCON: if(!up_retcon(appid,server, tstr, secret, cfile, nspfsize, &nsp_ret, &file_info)){ nsplog("内部错误","飞速上传出错"); goto upload_fail; } break; case REQTBLK: if(!up_blk(appid,server, tstr, secret, cfile, nspfsize, &nsp_ret, &file_info, callfunc)){ nsplog("内部错误","文件分块上传出错"); goto upload_fail; } break; case UPSTAT: if(nsp_ret.nsp_upstat == NONE){ nsplog("内部错误","未知的上传状态"); goto upload_fail; }else if(nsp_ret.nsp_upstat == FIN){ //begin to mkfile nA->appendMap_Str_Str(&recv,"nsp_fid",nsp_ret.nsp_fid); nA->appendMap_Str_Str(&recv,"nsp_path",nsp_ret.nsp_path); nA->appendMap_Str_Str(&recv,"nsp_size",nsp_ret.nsp_size); nA->appendMap_Str_Str(&recv,"nsp_sig",nsp_ret.nsp_sig); nA->appendMap_Str_Int(&recv,"nsp_ts",nsp_ret.nsp_ts); NSPActionDelete(nA); remove_cache(file_info.filename); if(file_info.isbigfile && file_info.nsi.next!=NULL){ nsp_bigfile_clean(file_info.nsi.next); } if(callfunc!=NULL){ callupload_func = (void (*)(double,double))callfunc; callupload_func((double)nspfsize,(double)nspfsize); } return true; } nsplog("内部错误","未知的上传状态"); goto upload_fail; case REQTSEG: if(!up_seginfo(appid,server, tstr, secret, cfile, nspfsize, &nsp_ret ,&file_info)){ nsplog("内部错误","文件分块信息出错"); goto upload_fail; } file_info.isbigfile=true; break; default: nsplog("内部错误","未知的上传状态"); goto upload_fail; } } return true; upload_fail: NSPActionDelete(nA); remove_cache(file_info.filename); if(file_info.isbigfile && file_info.nsi.next!=NULL){ nsp_bigfile_clean(file_info.nsi.next); } return false; }