int CCompressDeflate::End() { if (!m_bActive) { return 0; } int iZResult; m_sZStream.next_in = NULL; m_sZStream.avail_in = 0; bool bDone = false; do { // End the deflate stream if (m_bCompress) { iZResult = deflate(&m_sZStream, Z_FINISH); } else { iZResult = m_bStreamEnd ? Z_STREAM_END : inflate(&m_sZStream, Z_FINISH); } // If data output, save the memory to the output queue if (((iZResult == Z_OK) || (iZResult == Z_STREAM_END)) && (m_sZStream.avail_out < m_iBlockSize)) { StoreData(m_pBlock, m_iBlockSize - m_sZStream.avail_out); m_sZStream.next_out = m_pBlock; m_sZStream.avail_out = m_iBlockSize; } bDone = (iZResult == Z_STREAM_END) || (iZResult != Z_OK); } while (!bDone); // End the stream iZResult = m_bCompress ? deflateEnd(&m_sZStream) : inflateEnd(&m_sZStream); // Free the block data if (m_pBlock) { delete [] m_pBlock; } // Mark as inactive m_bActive = false; return m_iQueueSize; } // End
int QueueOperNoLock::PushDataIntoQueueBack(char *sValue,int iValueLen,char cLocked) { int iPkgLenWord; int iResSpaceLen = 0; int iCopyBeginPos = 0; char sHeader[sizeof(int) + 1] = {0}; if ( !m_pQueueCtl ) { snprintf(m_sErrMsg,sizeof(m_sErrMsg),"Store data fail:Not init locally"); return -3; } if ( m_pQueueCtl->cValidFlag <= 0 ) { snprintf(m_sErrMsg,sizeof(m_sErrMsg),"Store data fail:Shm deleted"); this->~QueueOperNoLock(); return -4; } if ( sValue == NULL || iValueLen <= 0 || iValueLen >= MAX_STOREBLK_LEN ) { snprintf(m_sErrMsg,sizeof(m_sErrMsg),"Store data fail:Data null or too long"); return -2; } iPkgLenWord = sizeof(int) + iValueLen; if ( cLocked == 1 ) SemLock(); if ( m_pQueueCtl->iQueueTailPos >= m_pQueueCtl->iQueueHeadPos ) iResSpaceLen = m_pQueueCtl->iSpaceSize - m_pQueueCtl->iQueueTailPos + m_pQueueCtl->iQueueHeadPos - 1; else iResSpaceLen = m_pQueueCtl->iQueueHeadPos - m_pQueueCtl->iQueueTailPos - 1; if ( iPkgLenWord > iResSpaceLen ) { if ( cLocked == 1 ) SemUnLock(); snprintf(m_sErrMsg,sizeof(m_sErrMsg),"Store data fail:Space full"); return -1; } memcpy(sHeader,&iPkgLenWord,sizeof(int)); iCopyBeginPos = StoreData(sHeader,sizeof(int),m_pQueueCtl->iQueueTailPos); m_pQueueCtl->iQueueTailPos = StoreData(sValue,iValueLen,iCopyBeginPos); if ( cLocked == 1 ) SemUnLock(); return 0; }
bool LoadFiles::LoadFile(string path) { fstream file; file.open(path, ios::in); if(!file) { return false; } StoreData(file, component); StoreData(file, connection); StoreData(file, entity); file.close(); return true; }
void wxsFontEditorDlg::UpdatePreview() { wxsFontData TempData; StoreData(TempData); wxFont Font = TempData.BuildFont(); if ( FaceList->GetSelection() != wxNOT_FOUND ) { Font.SetFaceName(FaceList->GetStringSelection()); } TestArea->SetFont(Font); }
bool LoadFiles::LoadPositionFile(string path) { fstream file; file.open(path, ios::in); if(!file) { return false; } StoreData(file, componentPosition); return true; }
/* Store stationary particles. */ mxArray* Snapshot::StoreSnapshot0(Snapshot& snapshot) { ParticleFactory& factory = ParticleFactory::getInstance(); vector<MovingParticle*> vp = snapshot.polygon->getParticles(); const int dims[] = { vp.size(), 3 }; vector<float> F(dims[0] * dims[1]); for (int j = 0; j < dims[0]; ++j) { SetData2(F, j, 0, dims[0], dims[1], vp[j]->getInitParticle()->getX()); SetData2(F, j, 1, dims[0], dims[1], vp[j]->getInitParticle()->getY()); SetData2(F, j, 2, dims[0], dims[1], (float)vp[j]->getInitParticle()->getId()); } return StoreData(F, mxSINGLE_CLASS, 2, dims); }
mxArray* ParticleSimulator::SaveDoneEvents() { const int dims[] = { doneEvents.size(), 5 }; vector<float> F(dims[0] * dims[1]); for (int i = 0; i < doneEvents.size(); ++i) { EventStruct ev = doneEvents[i]; SetData2(F, i, 0, dims[0], dims[1], (float)ev.p->id); SetData2(F, i, 1, dims[0], dims[1], (float)ev.q->id); SetData2(F, i, 2, dims[0], dims[1], (float)ev.r->id); SetData2(F, i, 0, dims[0], dims[1], (float)ev.t); SetData2(F, i, 0, dims[0], dims[1], (float)ev.type); } return StoreData(F, mxSINGLE_CLASS, 2, dims); }
mxArray* ParticleSimulator::SaveConvexity() { ParticleFactory* factory = ParticleFactory::getInstance(); const int dims[] = { factory->particles.size(), 3 }; vector<float> F(dims[0] * dims[1]); for (int i = 0; i < dims[0]; ++i) { MovingParticle* p = factory->particles[i]; CParticleF pr = p->project(p->created + 0.1); SetData2(F, i, 0, dims[0], dims[1], pr.m_X); SetData2(F, i, 1, dims[0], dims[1], pr.m_Y); SetData2(F, i, 2, dims[0], dims[1], p->reflexive<=0 ? 0.0f: 1.0f); } return StoreData(F, mxSINGLE_CLASS, 2, dims); }
mxArray* Snapshot::StoreSnapshot(Snapshot& snapshot) { ParticleFactory& factory = ParticleFactory::getInstance(); vector<CParticleF> shape = snapshot.polygon->project(snapshot.getProjectionTime()); const int dims[] = { shape.size(), 4 }; vector<float> F(dims[0] * dims[1]); for (int j = 0; j < dims[0]; ++j) { SetData2(F, j, 0, dims[0], dims[1], shape[j].m_X); SetData2(F, j, 1, dims[0], dims[1], shape[j].m_Y); SetData2(F, j, 2, dims[0], dims[1], snapshot.projection_time); SetData2(F, j, 3, dims[0], dims[1], snapshot.created_time); } return StoreData(F, mxSINGLE_CLASS, 2, dims); }
void pedometer(void* data) { INT16U oldsteps = 0; INT16U steps; INT8U count = 0; INT8U rest = FALSE; INT16U energyVal = 0; INT8U i; /* store data*/ StoreData((INT8S *)data); count++; /* when there is no count for a long time, it consider to be rest.*/ /* can ignore wrap around as rest is set.*/ if (count > REST_CNT) { rest = TRUE; } CntStep(); steps = GetStep(); if (oldsteps != steps) { /* display steps:.*/ /*print_str("steps: %d\n", steps);.*/ if (rest) rest = FALSE; else { /* Add energy according to table*/ for (i=0; i<TABLE_LEN; i++) { if (count > STEP_INT[i]) { energyVal += (count*ENERGY_INT[i])/4; break; } } } count = 0; /* show energy*/ /*print_str("energy: %d\n", energyVal/1000);*/ } oldsteps = steps; }
mxArray* ParticleSimulator::SaveParticles() { ParticleFactory* factory = ParticleFactory::getInstance(); const int dims[] = { factory->particles.size(), ParticleDumpSize }; vector<float> F(dims[0] * dims[1]); for (int i = 0; i < dims[0]; ++i) { MovingParticle* p = factory->particles[i]; vector<float> v = p->dump2vector(); for (int j = 0; j < dims[1]; ++j) { SetData2(F, i, j, dims[0], dims[1], v[j]); } } return StoreData(F, mxSINGLE_CLASS, 2, dims); }
int CCompressDeflate::Input(unsigned char *pData, int iSize) { // Check we can do anything? if (!m_bActive) { return 0; } // Check we have input data if (iSize > 0) { // Set up z stream m_sZStream.next_in = pData; m_sZStream.avail_in = iSize; // Input the data int iZResult; bool bDone = true; do { // Compress if (m_bCompress) { iZResult = deflate(&m_sZStream, Z_NO_FLUSH); } // Decompress else { if (!m_bStreamEnd) { iZResult = inflate(&m_sZStream, Z_NO_FLUSH); } m_bStreamEnd = (iZResult == Z_STREAM_END); } // Go again if we still have data to input, or an error has occured bDone = (m_sZStream.avail_in == 0); // If data output, save the memory to the output queue if (m_sZStream.avail_out < m_iBlockSize) { // There may be more data to output, so go again if necessary bDone &= (m_sZStream.avail_out > 0); StoreData(m_pBlock, m_iBlockSize - m_sZStream.avail_out); m_sZStream.next_out = m_pBlock; m_sZStream.avail_out = m_iBlockSize; } // If no data to output, stop else { bDone &= true; } } while (!bDone); } return m_iQueueSize; } // Compress
DWORD WINAPI ThreadFunc(VOID) { int i; if(!StoreData(GetCurrentThreadId())) ErrorExit("StoreData error"); for(i=0; i<5; i++) { DWORD dwOut; if(!GetData(&dwOut)) ErrorExit("GetData error"); if( dwOut != GetCurrentThreadId()) printf("thread %d: data is incorrect (%d)\n", GetCurrentThreadId(), dwOut); else printf("thread %d: data is correct\n", GetCurrentThreadId()); Sleep(0); } return 0; }
void Client::_ReadNetworkData() { char buffer[NETWORK_BUFFER_LENGTH]; memset(buffer, 0, sizeof(buffer)); SocketAddress addr; memset(&addr, 0, sizeof(SocketAddress)); int bytes_recv = 0; while(bytes_recv != -1 ) { bytes_recv = DarkNet::Recieve(m_socket,buffer, sizeof(buffer),addr); if(bytes_recv <= 0) continue; #if defined (_XBOX) //Make sure it has XnetInfo as header PacketHeader header = DarkNet::ExtractHeader(buffer,bytes_recv); if(header.m_darknet_xId == -1) continue; if(!m_isConnected) if(XNetRegisterKey(&header.m_xnkid,&header.m_xnkey) != 0) OUTPUT("FAILED To Register the key!"); //Else get the socketaddress DarkNet::XNAddrToInAddr(header.m_xnaddr, header.m_xnkid, addr); #endif if(IsServer(addr)) { StoreData(buffer); } else if(strcmp(buffer, CONNECTION_FORMED) == 0) { OnConnectionFormed(addr); } else _DataCallbackFunc(buffer,&addr); } }
int main (int argc, char **argv) { pwr_tStatus sts; pwr_tObjid ObjId; pwr_sClass_DsTrendConf *TConfP; pwr_tBoolean InitOK; pwr_tTime CurrentTime, LastScan, NextScan; pwr_tDeltaTime ScanDeltaTime, WaitTime; qcom_sQid qini; qcom_sQattr qAttr; int tmo; char mp[2000]; qcom_sQid qid = qcom_cNQid; qcom_sGet get; int swap = 0; trend_tCtx ctx; errh_Init("pwr_trend", errh_eAnix_trend); errh_SetStatus( PWR__SRVSTARTUP); sts = gdh_Init("ds_trend"); If_Error_Log_Exit(sts, "gdh_Init"); if (!qcom_Init(&sts, 0, "pwr_trend")) { errh_Fatal("qcom_Init, %m", sts); exit(sts); } qAttr.type = qcom_eQtype_private; qAttr.quota = 100; if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) { errh_Fatal("qcom_CreateQ, %m", sts); exit(sts); } qini = qcom_cQini; if (!qcom_Bind(&sts, &qid, &qini)) { errh_Fatal("qcom_Bind(Qini), %m", sts); exit(-1); } ctx = (trend_tCtx) calloc( 1, sizeof(trend_sCtx)); /* Wait until local nethandler has started */ while(EVEN(gdh_NethandlerRunning())) sleep(1); /* Fetch ScanTime */ sts = gdh_GetClassList(pwr_cClass_DsTrendConf, &ObjId); if (EVEN(sts)) { errh_Info("Couldn't get the DsTrendConf object. Used ScanTime = 1 s"); ctx->scantime = 1; ctx->scantime_tc = 1.0; } else { gdh_ObjidToPointer(ObjId, (pwr_tAddress *)&TConfP); ctx->scantime = TConfP->ScanTime; if ( ctx->scantime > 3600) ctx->scantime = 3600; else if ( ctx->scantime < 1) ctx->scantime = 1; ctx->scantime_tc = TConfP->ScanTime; if ( ctx->scantime_tc > 3600) ctx->scantime_tc = 3600; } ctx->dstrend_multiple = (int) (ctx->scantime / ctx->scantime_tc + 0.5); aproc_RegisterObject( ObjId); InitOK = FALSE; sts = InitTrendList( ctx); if ( EVEN(sts)) { /* This should be removed when we can wait for init messages. */ errh_SetStatus(0); errh_Info("No DsTrend objects configured"); exit(0); } /* If even sts, just wait for init message */ time_GetTimeMonotonic(&LastScan); time_FloatToD( &ScanDeltaTime, ctx->scantime_tc); aproc_TimeStamp( ctx->scantime, 5.0); errh_SetStatus( PWR__SRUN); for (;;) { time_GetTimeMonotonic(&CurrentTime); time_Aadd(&NextScan, &LastScan, &ScanDeltaTime); if (time_Acomp(&CurrentTime, &NextScan) < 0) { time_Adiff(&WaitTime, &NextScan, &CurrentTime); tmo = 1000 * time_DToFloat( 0, &WaitTime); get.maxSize = sizeof(mp); get.data = mp; qcom_Get( &sts, &qid, &get, tmo); if (sts == QCOM__TMO || sts == QCOM__QEMPTY) { if ( !swap) StoreData( ctx); } else { ini_mEvent new_event; qcom_sEvent *ep = (qcom_sEvent*) get.data; new_event.m = ep->mask; if (new_event.b.oldPlcStop && !swap) { swap = 1; errh_SetStatus( PWR__SRVRESTART); CloseTrendList( ctx); } else if (new_event.b.swapDone && swap) { swap = 0; sts = InitTrendList( ctx); errh_SetStatus( PWR__SRUN); errh_Info("Warm restart completed"); } else if (new_event.b.terminate) { exit(0); } } } else if ( !swap) StoreData( ctx); LastScan = NextScan; aproc_TimeStamp( ctx->scantime, 5.0); } return 1; }
//---------------------------------------------------------------------------- // Execute a script file int CSTATEngine::RunScript(ScriptProgressMonitor *const monitor) { int ret = ITS_OK; iCurrentCommand = 0; eStopProcessing = STAT_RUN; iDeviceCode = 0; // anything smaller can cause problems and doesn't make sense anyway! if (iMaxTimeLimit < 1000) iMaxTimeLimit = 1000; // pointers to our command structures CSTATScriptCommand *pSendCommand; CSTATScriptCommand *pRecvCommand; char lastCommand = NULL; receivedData.Empty( ); // get a command from the script while (pDecoder->GetNextCommand(&pSendCommand) && ret == ITS_OK) { iCurrentCommand++; if (StopProcessing()) { pComms->Send(STAT_RESYNCID); ret = E_USERCANCEL; break; } if (lastCommand == STAT_REBOOT) { ret = ITS_OK; break; } switch(pSendCommand->cCommandID) { case 'P': Message(pSendCommand->Command()); Sleep(atol(pSendCommand->Command())); break; case '/': Message(pSendCommand->Command()); break; case '#': { Message(pSendCommand->Command()); cScreenshotDirectory = pSendCommand->Command(); if(cScreenshotDirectory.Right(1) != _T("\\")) cScreenshotDirectory += _T("\\"); CreateAllDirectories(cScreenshotDirectory); } break; default: { // send the command and retrieve a response int iResyncErrors = 0; while ((ret = SendCommand(pSendCommand, &pRecvCommand)) == E_RESYNCCOMMAND) { Sleep(STAT_RETRYDELAY); iResyncErrors++; if (iResyncErrors > STAT_MAXERRORS) { Message("Too many resync errors - stopping"); ret = E_COMMANDFAILED; break; } } if (ret == ITS_OK) { // perform special operations for these commands switch(pSendCommand->cCommandID) { case 'D': StoreData(pRecvCommand->Command(), pRecvCommand->Length(), pDeviceInfo); AppendCommandToSTATLog("*** DEVICE INFORMATION ***", pRecvCommand->Command(), pRecvCommand->Length()); break; case 'S': { // convert and save the data returned in the response CString image = pSendCommand->Command(); ret = ConvertAndSaveScreeenshot(image, pRecvCommand->Command(), pRecvCommand->Length()); // imave verification if (ret == ITS_OK) { if (pImageVerify->IsActive() && pConverter->bWriteToFile) { ret = pImageVerify->VerifyImage(image); if (ret == VERIFICATION_PASS) ret = ITS_OK; } } break; } case 'T': { if(dataSocket==NULL) { // filename has been sent, now send the file itself CSTATScriptCommand oSendCommand; oSendCommand.cCommandID = pRecvCommand->cCommandID; // read and send the file contents if ((ret = ReadTransferFile(pSendCommand->Command(), &oSendCommand)) == ITS_OK) { int iResyncErrors = 0; while ((ret = SendCommand(&oSendCommand, &pRecvCommand)) == E_RESYNCCOMMAND) { Sleep(STAT_RETRYDELAY); iResyncErrors++; if (iResyncErrors > STAT_MAXERRORS) { Message("Too many resync errors - stopping"); ret = E_COMMANDFAILED; break; } } } } else { //release the socket ret = ReleaseSocket(); } break; } case 'R': case 'X': { if(dataSocket==NULL) { // save the file contents ret = SaveTransferFile(pSendCommand->Command(), pRecvCommand->Command(), pRecvCommand->Length()); } else { //release the socket ret = ReleaseSocket(); } break; } case 'G': { // upload the device log file and write to STAT log file AppendCommandToSTATLog("*** DEVICE LOG ***", pRecvCommand->Command(), pRecvCommand->Length()); break; } case STAT_REFRESH: case STAT_END: { ret = END_SCRIPT; break; } case 'N': { // Retrieve the TEF shared data StoreData(pRecvCommand->Command(), pRecvCommand->Length(), iTEFSharedData); AppendCommandToSTATLog("*** RETRIEVE TEF SHARED DATA ***", pRecvCommand->Command(), pRecvCommand->Length()); } break; default: { Sleep(iDelay); break; } } } if (ret == ITS_OK) { // Data received from certain of the commands is stored // for retreival later. switch(pSendCommand->cCommandID) { case 'W': case 'V': //execute returns pid case 'J': //poll returns 0 1 case '3': receivedData += oRecvCommand.Command(); break; default: break; } } } break; } lastCommand = pSendCommand->cCommandID; if(monitor) { monitor->OnCompleteCommand( iCurrentCommand ); } } pDecoder->Release(); return ret; }
int main(int argc, char **argv) { char **av = argv; struct sockaddr_in host; afs_int32 code; struct hostent *hp; char hnamebuf[200]; struct timeval tv; int noAuth = 1; /* Default is authenticated connections */ argc--, av++; if (argc < 1) { printf("usage: pxclient <serverHost>\n"); exit(1); } memset(&host, 0, sizeof(struct sockaddr_in)); host.sin_family = AF_INET; host.sin_addr.s_addr = inet_addr(av[0]); #ifdef STRUCT_SOCKADDR_HAS_SA_LEN host.sin_len = sizeof(struct sockaddr_in); #endif if (host.sin_addr.s_addr != -1) { strcpy(hnamebuf, av[0]); } else { hp = gethostbyname(av[0]); if (hp) { host.sin_family = hp->h_addrtype; memcpy((caddr_t) & host.sin_addr, hp->h_addr, hp->h_length); } else { printf("unknown server host %s\n", av[0]); exit(1); } } if ((code = pxclient_Initialize(noAuth, host.sin_addr.s_addr)) != 0) { printf("Couldn't initialize fs library (code=%d).\n", code); exit(1); } code = ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec, &tv.tv_usec); if (!code) printf("AFS_GetTime on %s sec=%ld, usec=%ld\n", av[0], tv.tv_sec, (long int)tv.tv_usec); else printf("return code is %d\n", code); #ifdef notdef while (1) { char line[500]; int nargs; printf("fs> "); if (fgets(line, 499, stdin) != NULL) { char *oper; char **argp = args; GetArgs(line, argp, &nargs); oper = &argp[0][0]; ++argp, --nargs; if (!strcmp(oper, "probe")) { code = ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec, &tv.tv_usec); printf("return code is %d\n", code); if (!code) printf("sec=%d\n", tv.tv_sec); } else if (!strcmp(oper, "fsstats")) { struct afsStatistics stats; code = ubik_AFS_GetStatistics(cstruct, 0, &stats); printf("return code is %d\n", code); } else if (!strcmp(oper, "fd")) { code = FetchData(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "fs")) { code = FetchStatus(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "fa")) { code = FetchACL(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "sd")) { code = StoreData(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "ss")) { code = StoreStatus(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "sa")) { code = StoreACL(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "cf")) { code = CreateFile(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "rf")) { code = RemoveFile(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "rn")) { code = Rename(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "sl")) { code = Symlink(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "hl")) { code = HardLink(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "md")) { code = MakeDir(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "rd")) { code = RemoveDir(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "rdd")) { code = Readdir(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "mm")) { code = MakeMountPoint(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "rt")) { code = ReleaseTokens(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "bs")) { code = BulkStatus(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "lk")) { code = Lookup(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "gt")) { code = GetToken(argp); printf("return code is %d\n", code); } else if (!strcmp(oper, "ka")) { code = KeepAlive(argp); printf("return code is %d\n", code); } else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit")) exit(0); else { printf("Unknown oper! Available operations: \n\n"); printf("fd <vnode> <unique> <pos> <len>\n"); printf("fs <vnode> <unique>\n"); printf("fa <vnode> <unique>\n"); printf ("sd <vnode> <unique> <pos> <len> <flen> [<mode>|-1] [<owner>|-1] [<length>|-1] <string>\n"); printf ("ss <vnode> <unique> [<mode>|-1] [<owner>|-1] [<length>|-1]\n"); printf("sa <vnode> <unique> <string>\n"); printf("rf <vnode> <unique> <name>\n"); printf ("cf <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n"); printf ("rn <ovnode> <ounique> <oname> <nvnode> <nunique> <nname>\n"); printf ("sl <vnode> <unique> <name> <contents> [<mode>|-1] [<owner>|-1] [<length>|-1]\n"); printf("hl <dvnode> <dunique> <name> <evnode> <eunique>\n"); printf ("md <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n"); printf("rd <vnode> <unique> <name>\n"); printf("rdd <vnode> <unique> <pos> <len>\n"); printf("lk <vnode> <unique> <name>\n"); printf("gt <vnode> <unique> <tokenID>\n"); printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n"); } } } #endif return 0; }
void wxsFontEditorDlg::OnButton2Click(wxCommandEvent& event) { StoreData(Data); EndModal(wxID_OK); }
HDDEDATA W_CALLBACK KapDDECallBack(WORD wTran, WORD wFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, DWORD dwData1, DWORD dwData2) { switch (wTran) { case XTYP_ADVSTART: case XTYP_ADVSTOP: { BOOL bRes = FALSE; if (wFmt == CF_TEXT) { char *cl; if (!DdeQueryString(dwDDEInst, hsz2, return_buffer, RET_BUFFER_LEN, CP_WINANSI)) return (HDDEDATA) FALSE; cl = strchr(return_buffer, ':'); if (cl) { DDEINFO ddeInfo; ATOMID idName; WORD wType; cl[0] = '\0'; idName = KppAddAtom(return_buffer); ddeInfo.idSlot = KppAddAtom(cl + 1); ddeInfo.idObj = KppGetObjectId(idName, &wType); ddeInfo.idApp = ddeInfo.idItem = NULLID; ddeInfo.idTopic = HszToAtom(hsz1); ddeInfo.hConv = hConv; if (ddeInfo.idObj) { UnwindProtect(cleanup1); requests++; switch (wTran) { case XTYP_ADVSTART: if (CreateLink(&ddeInfo)) bRes = TRUE; break; case XTYP_ADVSTOP: if (CloseServerLink(&ddeInfo, idName)) bRes = TRUE; break; } cleanup1: requests--; EndProtect(); } } } return (HDDEDATA) bRes; } case XTYP_EXECUTE: { DWORD dwLen; LPBYTE lpByte = DdeAccessData(hData, &dwLen); if (lpByte) { BOOL bFree = FALSE; LPBYTE lpCopy; if (dwLen < RET_BUFFER_LEN) { strcpy(return_buffer, lpByte); lpCopy = return_buffer; } else { lpCopy = strdup(lpByte); bFree = TRUE; } DdeUnaccessData(hData); if (lpCopy) { UnwindProtect(cleanup2); requests++; if (!KppEvalExpString(lpCopy)) KppPostKappaErrorMessageCB(); cleanup2: requests--; if (bFree) free(lpCopy); EndProtect(); return (HDDEDATA) DDE_FACK; } } return (HDDEDATA) DDE_FNOTPROCESSED; } case XTYP_CONNECT: if (DdeQueryString(dwDDEInst, hsz1, return_buffer, RET_BUFFER_LEN, CP_WINANSI)) { char *dot = strrchr(return_buffer, '.'); if (dot) dot[0] = '\0'; if (!stricmp(DDETopicName, return_buffer) || #ifdef MULTI !stricmp(DDEKappaName, return_buffer) || S_ILOC == 0 && #endif !stricmp("KAPPA", return_buffer)) return TRUE; } return (HDDEDATA) FALSE; case XTYP_DISCONNECT: UnwindProtect(cleanup3); requests++; DeleteDDETasks(hConv); cleanup3: requests--; EndProtect(); return (HDDEDATA) NULL; case XTYP_WILDCONNECT: { HSZPAIR hszPair[3]; hszPair[0].hszSvc = DdeCreateStringHandle(dwDDEInst, DDEAppName, CP_WINANSI); hszPair[0].hszTopic = DdeCreateStringHandle(dwDDEInst, DDETopicName, CP_WINANSI); hszPair[1].hszSvc = DdeCreateStringHandle(dwDDEInst, DDEAppName, CP_WINANSI); hszPair[1].hszTopic = DdeCreateStringHandle(dwDDEInst, DDEKappaName, CP_WINANSI); hszPair[2].hszSvc = hszPair[2].hszTopic = NULL; return DdeCreateDataHandle(dwDDEInst, (LPVOID) hszPair, sizeof(HSZPAIR) * 3, 0, hszPair[0].hszSvc, CF_TEXT, 0); } case XTYP_POKE: { UINT flag = DDE_FNOTPROCESSED; if (wFmt == CF_TEXT && DdeQueryString(dwDDEInst, hsz2, return_buffer, RET_BUFFER_LEN, CP_WINANSI)) { ATOMID idSlot; OBJECTID idObj; UnwindProtect(cleanup4); requests++; idObj = ObjSlotFromItem(return_buffer, &idSlot); if (idObj && StoreData(lpIDs->idNull, hData, idObj, idSlot)) flag = DDE_FACK; cleanup4: requests--; EndProtect(); } return (HDDEDATA) flag; } case XTYP_REQUEST: case XTYP_ADVREQ: hData = (HDDEDATA) DDE_FNOTPROCESSED; if (wFmt == CF_TEXT && DdeQueryString(dwDDEInst, hsz2, return_buffer, RET_BUFFER_LEN, CP_WINANSI)) { ATOMID idSlot; OBJECTID idObj; UnwindProtect(cleanup5); requests++; idObj = ObjSlotFromItem(return_buffer, &idSlot); if (idObj) { BOOL bMulti = FALSE; ITEMID idValue = Kpp_Get_SlotAnyValue(OBJECT_TYPE(idObj), idObj, idSlot, (LPWORD) &bMulti); GLOBALHANDLE hMem = NULL; LPBYTE lpBytes = NULL; DWORD dwLen = ValueToString(idValue, bMulti, &hMem, &lpBytes); if (dwLen) { hData = DdeCreateDataHandle(dwDDEInst, lpBytes, dwLen, 0, hsz2, CF_TEXT, 0); if (hMem) { GLOBALUNLOCK(hMem); GLOBALFREE(hMem); } if (!hData) hData = (HDDEDATA) DDE_FNOTPROCESSED; } } cleanup5: requests--; EndProtect(); } return hData; case XTYP_REGISTER: { ATOMID idApp = HszToAtom(hsz2); UnwindProtect(cleanup6); requests++; if (idApp) { WORD wType; OBJECTID idService = KppGetObjectId(idApp, &wType); if (!idService) { idService = KppMakeCO(OBJECT, idApp, idDDEService); wType = OBJECT; } if (idService) { if (DdeQueryString(dwDDEInst, hsz1, return_buffer, RET_BUFFER_LEN, CP_WINANSI)) Kpp_Set_SlotValue(wType, idService, Slot(idService), KppAddAtom(return_buffer), EXPATOM); else Kpp_Set_SlotValue(wType, idService, Slot(idService), lpIDs->idNull, EXPATOM); } } cleanup6: requests--; EndProtect(); return (HDDEDATA) NULL; } case XTYP_ADVDATA: UnwindProtect(cleanup7); requests++; if (wFmt == CF_TEXT) { CONVINFO ci; ATOMID idApp, idItem, idName; OBJECTID idLink; memset(&ci, 0, sizeof(CONVINFO)); ci.cb = sizeof(CONVINFO); DdeQueryConvInfo(hConv, QID_SYNC, &ci); idApp = HszToAtom(ci.hszSvcPartner); idItem = HszToAtom(hsz2); idName = LinkName(idApp, idItem); idLink = FindLink(idName); if (idLink) { WORD wDestType; ATOMID idDest = Kpp_Get_SlotValue(OBJECT, idLink, Slot(idDDEObject)); ATOMID idSlot = Kpp_Get_SlotValue(OBJECT, idLink, Slot(idDDESlot)); OBJECTID idDestObj = KppGetObjectId(idDest, &wDestType); StoreData(lpIDs->idNull, hData, idDestObj, idSlot); } } cleanup7: requests--; EndProtect(); return (HDDEDATA) DDE_FACK; case XTYP_XACT_COMPLETE: { char name[20]; OBJECTID idTask; ATOMID idName; WORD wType; UnwindProtect(cleanup8); requests++; task_name(name, hConv, dwData1); idName = KppAddAtom(name); idTask = KppGetObjectId(idName, &wType); if (idTask) { CONVINFO ci; memset(&ci, 0, sizeof(CONVINFO)); ci.cb = sizeof(CONVINFO); DdeQueryConvInfo(hConv, dwData1, &ci); switch (ci.wType) { case XTYP_REQUEST: if (wFmt == CF_TEXT) { WORD wDestType; ATOMID idDest = Kpp_Get_SlotValue(wType, idTask, Slot(idDDEObject)); ATOMID idSlot = Kpp_Get_SlotValue(wType, idTask, Slot(idDDESlot)); OBJECTID idDestObj = KppGetObjectId(idDest, &wDestType); StoreData(lpIDs->idNull, hData, idDestObj, idSlot); DdeDisconnect(hConv); } break; case XTYP_POKE: case XTYP_EXECUTE: DdeDisconnect(hConv); break; case (XTYP_ADVSTART | XTYPF_ACKREQ): { ATOMID idDest = Kpp_Get_SlotValue(wType, idTask, Slot(idDDEObject)); WORD wDestType; DDEINFO ddeInfo; ddeInfo.hConv = hConv; ddeInfo.idApp = Kpp_Get_SlotValue(wType, idTask, Slot(idService)); ddeInfo.idTopic = Kpp_Get_SlotValue(wType, idTask, Slot(idTopic)); ddeInfo.idItem = Kpp_Get_SlotValue(wType, idTask, Slot(idItem)); ddeInfo.idObj = KppGetObjectId(idDest, &wDestType); ddeInfo.idSlot = Kpp_Get_SlotValue(wType, idTask, Slot(idDDESlot)); CreateLink(&ddeInfo); break; } } DeleteDDETask(lpIDs->idNull, wType, idTask, (LPVOID) &hConv); } cleanup8: requests--; EndProtect(); return (HDDEDATA) NULL; } default: return (HDDEDATA) NULL; } }
void ProjectConfigurationPanel::OnApply() { StoreData(); *m_Configuration = m_ConfCopy; }
// The Activate function is where you work your magic. You should do four things in the Activate function: // 1) Retrieve your inputs by calling RetrieveData(input#) // 2) Do whatever you will do on it... // 3) Store the data to make it available to your outputs // 4) Return true to indicate successful activation, or false if there was an error. bool Pillars::Activate(BuildContext &context) { HFPointer hf_main = HF(RetrieveInput(0, context) ); // Use the RetrieveData(),StoreData() pair to get and set your heightfields HFPointer hf_voronoi = HF(RetrieveInput(1, context) ); // Use the RetrieveData(),StoreData() pair to get and set your heightfields HFPointer hf_pillarstrength = HF(RetrieveInput(2, context) ); // Use the RetrieveData(),StoreData() pair to get and set your heightfields HFPointer hf_walkassist = GetNewHF(context); // This is important! An input CAN RETURN NULL if it is not connected, or the input is turned off. So always check and bail out if its not there if (!hf_voronoi) return false; if (!hf_main) return false; if (!hf_walkassist) return false; //if (!hf_pillarstrength) //return false; // ** example: if we actually DID anything with our dummy param, this is how you would get it float dummy = INV_DUMMY; // ** example: If you wanted to access the data by coordinate instead of by index, here's how you would do it: int width = hf_voronoi->w(); int height = hf_voronoi->h(); //float dummy_height = (*hf_voronoi)[Coord(0,0)]; // use the coordinate version of the hf_voronoi array operator //size_t area = hf_voronoi->area(); // use size_t for heightfield iterating as it is possible for the index to exceed 32bits.. // heights are always in the range 0..1., it also doesn't care about world space location, so we can just do a simple iteration over the entire data field: float curr=-1; bool panic=false; for (size_t i=0; i<width; i++) { for (size_t j=0; j<height; j++) { size_t pos=j*height+i; if((*hf_voronoi)[pos]<0) { continue; } else { curr=(*hf_voronoi)[pos]; int avgx=i; int avgy=j; size_t pcnt=1; walk(curr, i,j,height,width,&avgx,&avgy,&pcnt,hf_voronoi,hf_main,hf_walkassist,-1,0,0); int phx=int(avgx/pcnt); int phy=int(avgy/pcnt); if (phx<0 || phx>=width || phy<0 || phy>= height) { panic=true; break; }; float pillarheight=(*hf_main)[ phx+ height*phy]; float pillarstrength= 1.0; if (hf_pillarstrength) { //we sample the pillar strength at the same point as we source the pillar heights from. pillarstrength=(*hf_pillarstrength)[ phx+ height*phy]; } walk(curr, i,j,height,width,&avgx,&avgy,&pcnt,hf_voronoi,hf_main,hf_walkassist, pillarheight,pillarstrength, 0); } } if (panic) break; } hf_main->ClampRange(); StoreData(hf_main,0, context); // pass the heightfield to our output stage. // Success! return true; }
int store_cred_handler(Service * /*service*/, int /*i*/, Stream *stream) { void * data = NULL; int rtnVal = FALSE; int rc; char * temp_file_name = NULL; bool found_cred; CredentialWrapper * temp_cred = NULL; int data_size = -1; classad::ClassAd * _classad = NULL; classad::ClassAd classad; std::string classad_cstr; char * classad_str = NULL; classad::ClassAdParser parser; ReliSock * socket = (ReliSock*)stream; const char * user = NULL; CredentialWrapper * cred_wrapper = NULL; if (!socket->triedAuthentication()) { CondorError errstack; if( ! SecMan::authenticate_sock(socket, WRITE, &errstack) ) { dprintf (D_ALWAYS, "Unable to authenticate, qutting\n"); goto EXIT; } } user = socket->getFullyQualifiedUser(); dprintf (D_FULLDEBUG, "Request by: %s, %s\n", socket->getOwner(), user); socket->decode(); if (!socket->code (classad_str)) { dprintf (D_ALWAYS, "Error receiving credential metadata\n"); goto EXIT; } classad_cstr = classad_str; free (classad_str); _classad = parser.ParseClassAd(classad_cstr); if (!_classad) { dprintf (D_ALWAYS, "Error: invalid credential metadata %s\n", classad_cstr.c_str()); goto EXIT; } classad = *_classad; delete _classad; int type; if (!classad.EvaluateAttrInt ("Type", type)) { dprintf (D_ALWAYS, "Missing Type attribute in classad!\n"); goto EXIT; } if (type == X509_CREDENTIAL_TYPE) { cred_wrapper = new X509CredentialWrapper (classad); dprintf (D_ALWAYS, "Name=%s Size=%d\n", cred_wrapper->cred->GetName(), cred_wrapper->cred->GetDataSize()); } else { dprintf (D_ALWAYS, "Unsupported credential type %d\n", type); goto EXIT; } cred_wrapper->cred->SetOrigOwner (socket->getOwner()); // original remote uname cred_wrapper->cred->SetOwner (user); // mapped uname // Receive credential data data_size = cred_wrapper->cred->GetDataSize(); if (data_size > MAX_CRED_DATA_SIZE) { dprintf (D_ALWAYS, "ERROR: Credential data size %d > maximum allowed (%d)\n", data_size, MAX_CRED_DATA_SIZE); goto EXIT; } data = malloc (data_size); if (data == NULL) { EXCEPT("Out of memory. Aborting."); } if (!socket->code_bytes(data,data_size)) { dprintf (D_ALWAYS, "Error receiving credential data\n"); goto EXIT; } cred_wrapper->cred->SetData (data, data_size); // Check whether credential under this name already exists found_cred=false; credentials.Rewind(); while (credentials.Next(temp_cred)) { if ((strcmp(cred_wrapper->cred->GetName(), temp_cred->cred->GetName()) == 0) && (strcmp(cred_wrapper->cred->GetOwner(), temp_cred->cred->GetOwner()) == 0)) { found_cred=true; break; // found it } } if (found_cred) { dprintf (D_ALWAYS, "Credential %s for owner %s already exists!\n", cred_wrapper->cred->GetName(), cred_wrapper->cred->GetOwner()); socket->encode(); int rcred=CREDD_ERROR_CREDENTIAL_ALREADY_EXISTS; socket->code(rcred); goto EXIT; } // Write data to a file temp_file_name = dircat (cred_store_dir, "credXXXXXX"); condor_mkstemp (temp_file_name); cred_wrapper->SetStorageName (temp_file_name); init_user_id_from_FQN (user); if (!StoreData(temp_file_name,data,data_size)) { socket->encode(); int rcred = CREDD_UNABLE_TO_STORE; socket->code(rcred); goto EXIT; } ((X509CredentialWrapper*)cred_wrapper)->cred->SetRealExpirationTime ( x509_proxy_expiration_time(temp_file_name)); // Write metadata to a file credentials.Append (cred_wrapper); SaveCredentialList(); // Write response to the client socket->encode(); rc = CREDD_SUCCESS; socket->code(rc); dprintf( D_ALWAYS, "Credential name %s owner %s successfully stored\n", cred_wrapper->cred->GetName(), cred_wrapper->cred->GetOwner() ); if (type == X509_CREDENTIAL_TYPE) { ((X509Credential*)cred_wrapper->cred)->display( D_FULLDEBUG ); } rtnVal = TRUE; EXIT: if ( data != NULL ) { free (data); } if ( temp_file_name != NULL ) { delete [] temp_file_name; } if ( cred_wrapper != NULL) { delete cred_wrapper; } return rtnVal; }