void ArpMenuField::ParametersChanged(const ArpParamSet* params) { if( params->GetChanges(parameters_menufield)&MENU_PROPS_CHANGED ) { if( MenuBar() ) { copy_attrs(MenuBar()); MenuBar()->SetFont(&PV_MenuFont); MenuBar()->SetHighColor(PV_MenuForeColor); MenuBar()->SetLowColor(PV_MenuBackColor); MenuBar()->SetViewColor(PV_MenuBackColor); } if( Menu() ) { copy_attrs(Menu()); } InvalidateView(); } inherited::ParametersChanged(params); }
void ArpMenuField::ComputeDimens(ArpDimens& cur_dimens) { BMenu* menu = MenuBar(); BMenu* popup = Menu(); if( menu ) { copy_attrs(menu); copy_attrs(popup); menu->SetFont(&PV_MenuFont); menu->InvalidateLayout(); } get_view_dimens(&cur_dimens, this, false); font_height fhs; BasicFont()->GetHeight(&fhs); const float fh = fhs.ascent+fhs.descent+fhs.leading; float fw = BasicFont()->StringWidth("WWWW"); float pref_w=0; if( popup ) { int32 num = popup->CountItems(); for( int32 i=0; i<num; i++ ) { BMenuItem* item = popup->ItemAt(i); if( item ) { const float w=BasicFont()->StringWidth(item->Label()); ArpD(cdb << ADH << "Dimensions for popup label " << item->Label() << ": " << w << endl); if( w > pref_w ) pref_w = w; } } } cur_dimens.Y().SetTo(0, fh+12, fh+12, fh+12, 0); float labelWidth = (Label() && *Label()) ? BasicFont()->StringWidth(Label()) + BasicFont()->StringWidth(" ") : 0; cur_dimens.X().SetTo(labelWidth, (fw < pref_w ? fw : pref_w) + 20, pref_w + 20, pref_w + 20, 0); }
CK_RV generate_named_key_pair(bee b, CK_ULONG len, const char *name, CK_OBJECT_HANDLE_PTR pub_key, CK_OBJECT_HANDLE_PTR priv_key) { CK_RV r; attrs *pub, *priv; pub = copy_attrs(*(b.default_pub_attrs)); priv = copy_attrs(*(b.default_priv_attrs)); if (pub == NULL_PTR || priv == NULL_PTR) { CKRLOG("generate_key_pair_with_mechanism: Cannot copy default asym attributes", (CK_RV) CKR_GENERAL_ERROR); return (CK_RV) CKR_GENERAL_ERROR; } add_attribute(pub, CKA_LABEL, (CK_VOID_PTR) name, strlen(name)); add_attribute(priv, CKA_LABEL, (CK_VOID_PTR) name, strlen(name)); add_gen_key_pair_attributes(pub, priv, len, b.default_asym_m); r = generate_key_pair_with_attrs(b, *pub, *priv, pub_key, priv_key); deep_free_attrs(pub, (CK_VOID_PTR) name, NULL_PTR); deep_free_attrs(priv, (CK_VOID_PTR) name, NULL_PTR); return r; }
CK_RV generate_key_pair_with_mechanism(bee b, CK_ULONG len, CK_MECHANISM_PTR m, CK_OBJECT_HANDLE_PTR pub_key, CK_OBJECT_HANDLE_PTR priv_key) { attrs *pub, *priv; pub = copy_attrs(*(b.default_pub_attrs)); priv = copy_attrs(*(b.default_priv_attrs)); CK_RV r; if (pub == NULL_PTR || priv == NULL_PTR) { CKRLOG("generate_key_pair_with_mechanism: Cannot copy default asym attributes", (CK_RV) CKR_GENERAL_ERROR); return (CK_RV) CKR_GENERAL_ERROR; } add_gen_key_pair_attributes(pub, priv, len, b.default_asym_m); r = generate_key_pair_with_attrs_and_mechanism(b, *pub, *priv, m, pub_key, priv_key); deep_free_attrs(pub, NULL_PTR, NULL_PTR); deep_free_attrs(priv, NULL_PTR, NULL_PTR); return r; }
CK_RV generate_key_with_mechanism(bee b, CK_MECHANISM_PTR m, CK_OBJECT_HANDLE_PTR key) { attrs *a; CK_RV r; a = copy_attrs(*(b.default_sym_attrs)); if (a == NULL_PTR) { CKRLOG("generate_key_with_mechanism: Cannot copy default symmetric attributes", (CK_RV) CKR_GENERAL_ERROR); return (CK_RV) CKR_GENERAL_ERROR; } add_gen_key_attributes(a, m); r = generate_key_with_attrs_and_mechanism(b, *a, m, key); deep_free_attrs(a, NULL_PTR, NULL_PTR); return r; }
void ArpMenuField::copy_attrs(BMenu* menu) { if( !menu ) return; int32 num = menu->CountItems(); for( int32 i=0; i<num; i++ ) { BMenu* child = menu->SubmenuAt(i); if( child ) { copy_attrs(child); // the menu doesn't seem to see this. child->SetFont(&PV_MenuFont); child->SetHighColor(PV_MenuForeColor); child->SetLowColor(PV_MenuBackColor); child->SetViewColor(PV_MenuBackColor); child->InvalidateLayout(); } } }
CK_RV generate_named_key(bee b, const char *name, CK_OBJECT_HANDLE_PTR key) { attrs *a; CK_RV r; a = copy_attrs(*(b.default_sym_attrs)); if (a == NULL_PTR) { CKRLOG("generate_named_key: Cannot copy default symmetric attributes", (CK_RV) CKR_GENERAL_ERROR); return (CK_RV) CKR_GENERAL_ERROR; } add_attribute(a, CKA_LABEL, (CK_VOID_PTR) name, strlen(name)); add_gen_key_attributes(a, b.default_sym_m); r = generate_key_with_attrs(b, *a, key); deep_free_attrs(a, (CK_VOID_PTR) name, NULL_PTR); return r; }
/* extract a variable from a netcdf file ant write it to another netcdf parallely, the function * will create new netcdf file if the output file does not exist. If the output file exists and the * output variable doesn't exist in the output file, the function creates a new variable or aborts.*/ int extract_unary(char *var,char *varOut,char **outDims,int outDimNum,size_t *begins,int beginNum,size_t *ends,int endNum,ptrdiff_t *strides,int strideNum,char *fileIn,char* fileOut){ int mpi_size,mpi_rank; MPI_Comm_size(MPI_COMM_WORLD,&mpi_size); MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank); MPI_Comm comm=MPI_COMM_WORLD; MPI_Info info=MPI_INFO_NULL; int ncid,vlid,ndims,dimids[NC_MAX_VAR_DIMS],nattrs; int ncidout,vlidout; int i,res; char varName[NC_MAX_NAME+1]; nc_type vtype; /* open input file */ if((res=nc_open_par(fileIn,NC_MPIIO,comm,info,&ncid))){ printf("Cannot open input file %s\n",fileIn); BAIL(res); } if((res=nc_inq_varid(ncid,var,&vlid))){ printf("Cannot query variable %s in input file %s\n",var,fileIn); BAIL(res); } if((res=nc_inq_var(ncid,vlid,varName,&vtype,&ndims,dimids,&nattrs))){ printf("Cannot query dimension info of varialbe %s in input file %s\n",var,fileIn); BAIL(res); } char **dimsName=(char **)malloc(sizeof(char *)*ndims); size_t *shape=(size_t *)malloc(sizeof(size_t)*ndims); for(i=0;i<ndims;++i){ dimsName[i]=(char *)malloc(NC_MAX_NAME+1); nc_inq_dim(ncid,dimids[i],dimsName[i],&shape[i]);//get dimsName and dimsLen } int is_strides_null=0; int is_begins_null=0; int is_ends_null=0; /* initialize begins ends and strides*/ init_begins_ends_strides(ndims,&begins,&beginNum,&is_begins_null,&ends,&endNum,&is_ends_null,&strides,&strideNum,&is_strides_null,shape); /* deal with -d and -r arguments */ dim_opts_handler(&global_attr,dimids,ncid,ndims,begins,ends,strides); /* check begins ends and strides */ if(-1==check_begins_ends_strides(ndims,begins,beginNum,ends,endNum,strides,strideNum,shape,dimsName)){return -1;} /* set independent parallel access for input file */ if((res=nc_var_par_access(ncid,vlid,NC_INDEPENDENT))){ printf("Cannot set parallel access for variable %s in input file %s\n",var,fileIn); BAIL(res); } /* create output file and define dims and var */ int *dimidsOut=(int *)malloc(sizeof(int)*ndims); if(-1== open_output_file_and_define_var(fileOut,&ncidout,&vlidout,dimidsOut,global_attr.append,ndims,vtype,dimsName,begins,ends,strides,shape,var,varOut,outDims,outDimNum)){return -1;} /* define attributes */ copy_attrs(ncid, vlid, ncidout, vlidout, nattrs); add_cmd_attr(ncidout,vlidout,global_attr.argc,global_attr.argv,mpi_size); if((res=nc_enddef(ncidout))){ printf("End define netcdf id %d in output file %s failed\n",ncidout,fileOut); BAIL(res); } if((res=nc_var_par_access(ncidout,vlidout,NC_INDEPENDENT))) { printf("Cannot set parallel access for variable %s in output file %s\n",var,fileOut); BAIL(res); } extract_unary_selector(mpi_rank,mpi_size,ncid,vlid,ncidout,vlidout,ndims,vtype,shape,begins,ends,strides,0L,NULL);// select reasonable parallel funtion /* free resources */ if(is_strides_null) free(strides); if(is_begins_null) free(begins); if(is_ends_null) free(ends); for(i=0;i<ndims;++i){ free(dimsName[i]); } free(dimsName); free(dimidsOut); free(shape); /*close file*/ if((res=nc_close(ncid))){ printf("Close input file %s failed\n",fileIn); BAIL(res); } if((res=nc_close(ncidout))){ printf("Close output file %s failed\n",fileOut); BAIL(res); } return 0; }
int transfer(const char *from, const char *to) { #define CLOSE(fd) { if (close(fd)) PERROR("error closing fd"); } int fdread, fdwrite; ssize_t readbytes; char buf[TRANSFER_SIZE]; int w_flags; pthread_mutex_lock(&m_transfer); if (from && to) { lock_set(t_state.job->path, LOCK_TRANSFER); VERBOSE("beginning transfer: '%s' -> '%s'", from, to); t_state.read_path = strdup(from); t_state.write_path = strdup(to); w_flags = O_WRONLY | O_CREAT | O_TRUNC; } else if (!t_state.active) { pthread_mutex_unlock(&m_transfer); return TRANSFER_FINISH; } else { VERBOSE("resuming transfer: '%s' -> '%s' at %ld", t_state.read_path, t_state.write_path, t_state.offset); w_flags = O_WRONLY | O_APPEND; } if (!t_state.read_path || !t_state.write_path) { ERROR("t_state.read_path or t_state.write_path is NULL"); lock_remove(t_state.job->path, LOCK_TRANSFER); goto failure; } /* open files */ if ((fdread = open(t_state.read_path, O_RDONLY)) == -1 || lseek(fdread, t_state.offset, SEEK_SET) == -1) { PERROR(t_state.read_path); goto failure; } if ((fdwrite = open(t_state.write_path, w_flags, 0666)) == -1 || lseek(fdwrite, t_state.offset, SEEK_SET) == -1) { PERROR(t_state.write_path); goto failure; } while (ONLINE && !worker_blocked()) { readbytes = read(fdread, buf, sizeof buf); if (readbytes && (readbytes < 0 || write(fdwrite, buf, readbytes) < readbytes || fsync(fdwrite))) { if (readbytes < 0) ERROR("failed to read from file"); else ERROR("failed or incomplete write"); goto failure; } /* copy completed, set mode and ownership */ if (readbytes < sizeof buf) { CLOSE(fdread); CLOSE(fdwrite); copy_attrs(t_state.read_path, t_state.write_path); VERBOSE("transfer finished: '%s' -> '%s'", t_state.read_path, t_state.write_path); lock_remove(t_state.job->path, LOCK_TRANSFER); pthread_mutex_unlock(&m_transfer); transfer_reset_state(); return TRANSFER_FINISH; } } t_state.offset = lseek(fdread, 0, SEEK_CUR); CLOSE(fdread); CLOSE(fdwrite); pthread_mutex_unlock(&m_transfer); return TRANSFER_OK; failure: pthread_mutex_unlock(&m_transfer); transfer_abort(); return TRANSFER_FAIL; #undef CLOSE }
int transfer_instant_pull(const char *path) { int res; char *pc, *pr; size_t p_len = strlen(path); bool path_equal = false; VERBOSE("instant_pulling %s", path); pthread_mutex_lock(&m_instant_pull); worker_block(); pr = remote_path2(path, p_len); pc = cache_path2(path, p_len); pthread_mutex_lock(&m_transfer); if (t_state.active) path_equal = !strcmp(path, t_state.job->path); pthread_mutex_unlock(&m_transfer); /* requested file is already being transfered (normally). just continue the transfer until it is finished */ if (path_equal) { /* continuing a running transfer() only works if !worker_blocked() */ worker_unblock(); do { res = transfer(NULL, NULL); } while (ONLINE && res == TRANSFER_OK); res = (res == TRANSFER_FINISH) ? 0 : 1; worker_block(); } else { res = copy_file(pr, pc); /* if copy_file failed, possibly because the file's directory didn't exist in the cache yet. create it and retry */ if (res && errno == ENOENT) { char *dir = dirname_r(path); if (dir) { transfer_pull_dir(dir); free(dir); res = copy_file(pr, pc); } } } worker_unblock(); copy_attrs(pr, pc); free(pr); free(pc); /* if copying failed, return error and dont set sync */ if (res) { ERROR("instant_pull on %s FAILED", path); pthread_mutex_unlock(&m_instant_pull); return -1; } /* file is in sync now */ job_delete(path, JOB_PULL); sync_set(path, 0); pthread_mutex_unlock(&m_instant_pull); return 0; }
int transfer_begin(struct job *j) { int res; char *pread = NULL, *pwrite = NULL; size_t p_len; pthread_mutex_lock(&m_transfer); if (t_state.active) { DEBUG("called transfer_begin while a transfer is active!"); pthread_mutex_unlock(&m_transfer); return TRANSFER_FAIL; } pthread_mutex_unlock(&m_transfer); p_len = strlen(j->path); if (j->op == JOB_PUSH) { pread = cache_path2(j->path, p_len); pwrite = remote_path2(j->path, p_len); } else if (j->op == JOB_PULL) { pread = remote_path2(j->path, p_len); pwrite = cache_path2(j->path, p_len); } if (!pread || !pwrite) { free(pread); free(pwrite); errno = ENOMEM; return -1; } if (is_reg(pread)) { if (!is_reg(pwrite) && !is_nonexist(pwrite)) { DEBUG("write target is non-regular file: %s", pwrite); free(pread); free(pwrite); return TRANSFER_FAIL; } pthread_mutex_lock(&m_transfer); t_state.active = true; t_state.job = j; t_state.offset = 0; pthread_mutex_unlock(&m_transfer); res = transfer(pread, pwrite); free(pread); free(pwrite); return res; } /* if symlink, copy instantly */ else if (is_lnk(pread)) { DEBUG("push/pull on symlink"); copy_symlink(pread, pwrite); copy_attrs(pread, pwrite); free(pread); free(pwrite); return TRANSFER_FINISH; } else if (is_dir(pread)) { DEBUG("push/pull on DIR"); clone_dir(pread, pwrite); copy_attrs(pread, pwrite); free(pread); free(pwrite); return TRANSFER_FINISH; } else { ERROR("cannot read file %s", pread); free(pread); free(pwrite); return TRANSFER_FAIL; } DEBUG("wtf"); return TRANSFER_FAIL; }