IDL_VPTR IDLStruct::vget(const char *name) { IDL_VPTR tmp; UCHAR *p; char message[80]; static int tag_index; // Does this tag exist? This is the bottleneck, by far // Better for the user to find the index ahead of time // Slightly faster than doing the ful getRefFromIDLStrucf thing indexIter = tagIndexHash.find(name); if (indexIter == tagIndexHash.end()) tagMessage(name); tag_index = indexIter->second; // point at the data p = ( idlStruct->value.s.arr->data + tag_offsets[tag_index] ); // for arrays. Problem is we still have to case the result if (tag_desc[tag_index]->flags & IDL_V_ARR) { // should copy the desc pointer efficiency tmp = IDL_ImportArray(tag_desc[tag_index]->value.arr->n_dim, tag_desc[tag_index]->value.arr->dim, tag_desc[tag_index]->type, p, NULL,NULL); } else // scalars: what if we want to modify the value? Should we just import //as array anyway? But how if the .arr is not set? { // This could be an issue tmp = IDL_Gettmp(); tmp->type = tagDescHash[name]->type; switch (tagDescHash[name]->type) { case IDL_TYP_BYTE: tmp->value.c = *(UCHAR *)p; break; case IDL_TYP_INT: tmp->value.i = *(short *)p; break; case IDL_TYP_UINT: tmp->value.ui = *(IDL_UINT *)p; break; case IDL_TYP_LONG: tmp->value.l = *(IDL_LONG *)p; break; case IDL_TYP_ULONG: tmp->value.ul = *(IDL_ULONG *)p; break; case IDL_TYP_LONG64: tmp->value.l64 = *(IDL_LONG64 *)p; break; case IDL_TYP_ULONG64: tmp->value.ul64 = *(IDL_ULONG64 *)p; break; case IDL_TYP_FLOAT: tmp->value.f = *(float *)p; break; //case IDL_TYP_FLOAT: IDL_StoreScalar(&tmp, IDL_TYP_FLOAT case IDL_TYP_DOUBLE: tmp->value.d = *(double *)p; break; case IDL_TYP_UNDEF: IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_LONGJMP, "TYPE is undefined"); default: IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_LONGJMP, "Cannot work with type"); } } return(tmp); }
IDL_VPTR IDL_CDECL idl_bam_cxc_get_data(int argc, IDL_VPTR argv[]) { QSharedMemory shared_memory("photo"); //QTextStream(stdout) << shared_memory.nativeKey() << endl; if (!shared_memory.attach(QSharedMemory::ReadOnly)) { IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Could not attach to shared memory block photo"); } shared_memory.lock(); int size = shared_memory.size(); if (size != sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS) { shared_memory.unlock(); shared_memory.detach(); IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Unexpected size for shared memory block photo"); } const unsigned int *data = (const unsigned int *) shared_memory.data(); unsigned int *data_copy = (unsigned int *) malloc(sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS); memcpy(data_copy, data, sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS); shared_memory.unlock(); shared_memory.detach(); int n_dim = 3; IDL_MEMINT dim[3] = {NCHANNELS, NPIXELY, NPIXELX}; IDL_VPTR rv = IDL_ImportArray(n_dim, dim, IDL_TYP_ULONG, (UCHAR *) data_copy, (IDL_ARRAY_FREE_CB) free, 0); return rv; }
IDL_VPTR IDL_CDECL idl_bam_cxc_get_event(int argc, IDL_VPTR argv[]) { unsigned long int *data = get_shared_memory("event"); int n_dim = 2; IDL_MEMINT dim[2] = {NPIXELY, NPIXELX}; IDL_VPTR rv = IDL_ImportArray(n_dim, dim, IDL_TYP_ULONG64, (UCHAR *) data, (IDL_ARRAY_FREE_CB) free, 0); return rv; }
/** * Get the names of all the data elements which are children of the primary raster element. * * @param[in] WINDOW @opt * The name of the window. Defaults to the active window. * @return An array of data element names or the string "failure" if an error occurred. * @usage names = get_data_element_names() * @endusage */ IDL_VPTR get_data_element_names(int argc, IDL_VPTR pArgv[], char* pArgk) { typedef struct { IDL_KW_RESULT_FIRST_FIELD; int windowExists; IDL_STRING windowName; } KW_RESULT; //IDL_KW_FAST_SCAN is the type of scan we are using, following it is the //name of the keyword, followed by the type, the mask(which should be 1), //flags, a boolean whether the value was populated and finally the value itself static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN, {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)), reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))}, {NULL} }; IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1); std::string windowName; std::string name; bool bSuccess = false; IDL_VPTR idlPtr; unsigned int total = 0; IDL_STRING* pStrarr = NULL; if (kw->windowExists) { windowName = IDL_STRING_STR(&kw->windowName); } SpatialDataWindow* pWindow = NULL; if (windowName.empty()) { pWindow = dynamic_cast<SpatialDataWindow*>(Service<DesktopServices>()->getCurrentWorkspaceWindow()); } else { pWindow = dynamic_cast<SpatialDataWindow*>( Service<DesktopServices>()->getWindow(windowName, SPATIAL_DATA_WINDOW)); } if (pWindow != NULL) { SpatialDataView* pView = pWindow->getSpatialDataView(); if (pView != NULL) { LayerList* pList = pView->getLayerList(); if (pList != NULL) { RasterElement* pElement = pList->getPrimaryRasterElement(); if (pElement != NULL) { std::vector<std::string> names = Service<ModelServices>()->getElementNames(pElement, ""); total = names.size(); if (total > 0) { pStrarr = reinterpret_cast<IDL_STRING*>(malloc(total * sizeof(IDL_STRING))); for (unsigned int i=0; i < total; ++i) { IDL_StrStore(&(pStrarr[i]), const_cast<char*>(names[i].c_str())); } bSuccess = true; } } } } } else if (windowName == "all") { std::vector<std::string> names = Service<ModelServices>()->getElementNames("RasterElement"); total = names.size(); if (total > 0) { pStrarr = reinterpret_cast<IDL_STRING*>(malloc(total* sizeof(IDL_STRING))); for (unsigned int i=0; i < total; ++i) { IDL_StrStore(&(pStrarr[i]), const_cast<char*>(names[i].c_str())); } bSuccess = true; } } if (!bSuccess) { IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "No elements matched."); return IDL_StrToSTRING("failure"); } IDL_MEMINT dims[] = {total}; idlPtr = IDL_ImportArray(1, dims, IDL_TYP_STRING, reinterpret_cast<UCHAR*>(pStrarr), reinterpret_cast<IDL_ARRAY_FREE_CB>(free), NULL); return idlPtr; }
// MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res); static IDL_VPTR IDL_mg_mysql_fetch_field(int argc, IDL_VPTR *argv) { static IDL_MEMINT nfields = 1; MYSQL_FIELD *field = mysql_fetch_field((MYSQL_RES *)argv[0]->value.ptrint); typedef struct field { IDL_STRING name; IDL_STRING org_name; IDL_STRING table; IDL_STRING org_table; IDL_STRING db; IDL_STRING catalog; IDL_STRING def; IDL_ULONG64 length; IDL_ULONG64 max_length; IDL_ULONG name_length; IDL_ULONG org_name_length; IDL_ULONG table_length; IDL_ULONG org_table_length; IDL_ULONG db_length; IDL_ULONG catalog_length; IDL_ULONG def_length; IDL_ULONG flags; IDL_ULONG decimals; IDL_ULONG charsetnr; IDL_ULONG type; #if MYSQL_VERSION_ID >= 50100 IDL_PTRINT extension; #endif } MG_Field; MG_Field *mg_field_data = (MG_Field *) calloc(nfields, sizeof(MG_Field)); void *idl_field_data; IDL_StrStore(&mg_field_data->name, field->name); IDL_StrStore(&mg_field_data->org_name, field->org_name); IDL_StrStore(&mg_field_data->table, field->table); IDL_StrStore(&mg_field_data->org_table, field->org_table); IDL_StrStore(&mg_field_data->db, field->db); IDL_StrStore(&mg_field_data->catalog, field->catalog); IDL_StrStore(&mg_field_data->def, field->def); mg_field_data->length = field->length; mg_field_data->max_length = field->max_length; mg_field_data->name_length = field->name_length; mg_field_data->org_name_length = field->org_name_length; mg_field_data->table_length = field->table_length; mg_field_data->org_table_length = field->org_table_length; mg_field_data->db_length = field->db_length; mg_field_data->catalog_length = field->catalog_length; mg_field_data->def_length = field->def_length; mg_field_data->flags = field->flags; mg_field_data->decimals = field->decimals; mg_field_data->charsetnr = field->charsetnr; mg_field_data->type = field->type; #if MYSQL_VERSION_ID >= 50100 mg_field_data->extension = (IDL_PTRINT)field->extension; #endif idl_field_data = IDL_MakeStruct(0, mg_mysql_field); IDL_VPTR result = IDL_ImportArray(1, &nfields, IDL_TYP_STRUCT, (UCHAR *) mg_field_data, 0, idl_field_data); return result; }
IDL_VPTR readwu(int argc, IDL_VPTR argv[], char *argk) { IDL_VPTR filename=NULL; static IDL_VARIABLE rv; rv.type=IDL_TYP_INT; rv.flags=IDL_V_CONST|IDL_V_NULL; rv.value.i=-1; char *outfile=NULL, buf[256]; struct stat statbuf; int nbytes,nread,nsamples; std::string tmpbuf(""); int i=0,j; if (argc != 1) { fprintf(stderr,"argc=%d\n",argc); fprintf(stderr,"array=readwu(wufile_name)\n"); return &rv; } IDL_STRING *infile=NULL; if (argv[0]->type != IDL_TYP_STRING) { IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"Parameter 1 must be type STRING"); } else { infile=(IDL_STRING *)(&argv[0]->value.s); } FILE *in=fopen(infile->s,"r"); if (!in) { IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"File not found"); return &rv; } stat(infile->s,&statbuf); nbytes=statbuf.st_size; fseek(in,0,SEEK_SET); tmpbuf.reserve(nbytes); // read entire file into a buffer. while ((nread=(int)fread(buf,1,sizeof(buf),in))) { tmpbuf+=std::string(&(buf[0]),nread); } // parse the header header.parse_xml(tmpbuf); // decode the data std::vector<unsigned char> datav( xml_decode_field<unsigned char>(tmpbuf,"data") ); tmpbuf.clear(); nsamples=header.group_info->data_desc.nsamples; nbytes=nsamples*header.group_info->recorder_cfg->bits_per_sample/8; if (datav.size() < nbytes) { fprintf(stderr,"Data size does not match number of samples\n"); return &rv; } // convert the data to floating point sah_complex *fpdata=(sah_complex *)IDL_MemAlloc(nsamples*sizeof(sah_complex),0,IDL_MSG_RET); if (!fpdata) { fprintf(stderr,"Unable to allocate memory!\r\n"); return &rv; } bits_to_floats(&(datav[0]),fpdata,nsamples); datav.clear(); IDL_MEMINT dims[]={nsamples}; return IDL_ImportArray(1,dims,IDL_TYP_COMPLEX,(UCHAR *)fpdata,NULL,NULL); }