void OnBodyReceived(DWORD err, DWORD bytes) { if(err != NO_ERROR) { if(server->onClientError) { server->onClientError(connection, err, server->userData); } } else if(bytes != message->BodySize) { // We're still missing data, reschedule read } else { state = MSGSTATE_DONE; buffer[message->BodySize-1] = 0; // Enforce 0 termination std::vector<MessageField> fieldStore(message->FieldCount); std::vector<std::string> stringStore; stringStore.reserve(message->FieldCount * 2); char const * ptr = buffer; UINT32 bytesLeft = bytes; for(size_t i = 0; i < fieldStore.size(); ++i) { if(!ReadEntry(ptr, bytesLeft, fieldStore[i].Key, stringStore)) { break; } if(!ReadEntry(ptr, bytesLeft, fieldStore[i].Value, stringStore)) { break; } } message->Fields = &fieldStore[0]; server->onClientMessage(connection, message, server->userData); server->ScheduleRead(connection); } delete[] buffer; delete message; }
bool vfsHDD::RemoveEntry(const std::string& name) { u64 entry_block, parent_entry; if (!SearchEntry(name, entry_block, &parent_entry)) { return false; } vfsHDD_Entry entry; ReadEntry(entry_block, entry); if (entry.type == vfsHDD_Entry_Dir) { RemoveBlocksDir(entry.data_block); } else if (entry.type == vfsHDD_Entry_File) { RemoveBlocksFile(entry.data_block); } if (parent_entry) { u64 next = entry.next_block; ReadEntry(parent_entry, entry); entry.next_block = next; WriteEntry(parent_entry, entry); } WriteBlock(entry_block, g_null_block); return true; }
void VEFObject::LoadVEF(DataStream *stream) { Init(); if (!stream) { return; } ieDword i; ieResRef Signature; ieDword offset1, offset2; ieDword count1, count2; stream->ReadResRef( Signature); if (strncmp( Signature, "VEF V1.0", 8 ) != 0) { Log(ERROR, "VEFObject", "Not a valid VEF File: %s", ResName); delete stream; return; } SingleObject = false; stream->ReadDword( &offset1); stream->ReadDword( &count1); stream->ReadDword( &offset2); stream->ReadDword( &count2); stream->Seek(offset1, GEM_STREAM_START); for (i=0;i<count1;i++) { ReadEntry(stream); } stream->Seek(offset2, GEM_STREAM_START); for (i=0;i<count2;i++) { ReadEntry(stream); } }
s32 vfsHDD::OpenDir(const std::string& name) { LOG_WARNING(HLE, "OpenDir(%s)", name.c_str()); u64 entry_block; if (!SearchEntry(name, entry_block)) { return -1; } CHECK_ASSERTION(m_hdd_file.Seek(entry_block * m_hdd_info.block_size) != -1); vfsHDD_Entry entry; m_hdd_file.Read(&entry, sizeof(vfsHDD_Entry)); if (entry.type == vfsHDD_Entry_File) { return 1; } m_cur_dir_block = entry.data_block; ReadEntry(m_cur_dir_block, m_cur_dir); return 0; }
SyncLogEntry SyncLogger::ReadFirstEntry(const char* pszHash) { ParseFile(pszHash); // Assures the correct parsing of the file. assert(m_pCFG != NULL); // cfg_t* pEntryCFG = cfg_getnsec(m_pCFG, MOD_NUMBER_VARNAME, 0); return ReadEntry(cfg_getnsec(m_pCFG, MOD_NUMBER_VARNAME, 0)); /* // Assures that the section has been found, which means there is at least one section. assert(pEntryCFG != NULL); // TODO: Copy values SyncLogEntry sle; sle.m_strFilePath = cfg_getstr(pEntryCFG, FILE_PATH_VARNAME); sle.m_strModTime = cfg_getstr(pEntryCFG, MOD_TIME_VARNAME); string strModType = cfg_getstr(pEntryCFG, MOD_TYPE_VARNAME); if (strModType.length() != 1) { // The log entry does not meet the standard. return NULL; } sle.m_chModType = strModType.c_str()[0]; return sle; */ }
void vfsHDDFile::Open(u64 info_block) { m_info_block = info_block; ReadEntry(m_info_block, m_info); m_position = 0; m_cur_block = m_info.data_block; }
void MP4TableProperty::Read(MP4File* pFile, u_int32_t index) { ASSERT(index == 0); if (m_implicit) { return; } u_int32_t numProperties = m_pProperties.Size(); if (numProperties == 0) { WARNING(numProperties == 0); return; } u_int32_t numEntries = GetCount(); /* for each property set size */ for (u_int32_t j = 0; j < numProperties; j++) { m_pProperties[j]->SetCount(numEntries); } for (u_int32_t i = 0; i < numEntries; i++) { ReadEntry(pFile, i); } }
bool vfsHDD::SearchEntry(const std::string& name, u64& entry_block, u64* parent_block) { u64 last_block = 0; u64 block = m_cur_dir_block; vfsHDD_Entry entry; std::string buf; while (block) { ReadEntry(block, entry, buf); if (fmt::CmpNoCase(name, buf) == 0) { entry_block = block; if (parent_block) *parent_block = last_block; return true; } last_block = block; block = entry.is_used ? entry.next_block : 0ULL; } return false; }
void IOAPIC::ClearPin(int apic, int pin) { struct IO_APIC_route_entry entry; entry = ReadEntry(apic, pin); if(entry.delivery_mode == dest_SMI) return; MaskEntry(apic, pin); }
PString SIDStil::GetEntry(PString relPathToEntry, int32 tuneNo, STILField field) { if (baseDir.IsEmpty()) return (""); // Fail if a section-global comment was asked for if (relPathToEntry.GetAt(relPathToEntry.GetLength() - 1) == '/') return (""); if (stilVersion < 2.59f) { tuneNo = 0; field = all; } // Find out whether we have this entry in the buffer if ((entryBuf.Left(relPathToEntry.GetLength()) != relPathToEntry) || ((entryBuf.Find('\n') != relPathToEntry.GetLength()) && (stilVersion > 2.59f))) { // The relative pathnames don't match or they're not the same length: // We don't have it in the buffer, so pull it in try { PDirectory tempDir; tempDir.SetDirectory(baseDir); tempDir.Append("DOCUMENTS"); stilFile->Open(tempDir.GetDirectory() + "STIL.txt", PFile::pModeRead | PFile::pModeShareRead); if (PositionToEntry(relPathToEntry, stilFile, stilDirs) == false) { // Copy the entry's name to the buffer entryBuf = relPathToEntry + "\n"; } else { entryBuf.MakeEmpty(); ReadEntry(stilFile, entryBuf); } stilFile->Close(); } catch(PFileException e) { // Failed reading from the STIL.txt file stilFile->Close(); return (""); } } // Put the requested field into the result string if (GetField(resultEntry, entryBuf, tuneNo, field) != true) return (""); return (resultEntry); }
char *csArchive::Read (const char *name, size_t *size) { ArchiveEntry *f = (ArchiveEntry *) FindName (name); if (!f) return NULL; if (size) *size = f->info.ucsize; return ReadEntry (file, f); }
bool vfsHDD::GetNextEntry(u64& block, vfsHDD_Entry& entry, std::string& name) { if (!block) { return false; } ReadEntry(block, entry, name); block = entry.is_used ? entry.next_block : 0; return true; }
int AvgByCount(double ts, double input_val, void *state_set, int tau, double *out_ts, double *out_val) { int ierr; double curr_ts; double curr_val; double count; double acc; int size; int read; Rewind(state_set); size = SizeOf(state_set); acc = input_val; *out_ts = ts; count = 1.0; read = 0; while((ReadEntry(state_set,&curr_ts,&curr_val) != 0) && (count < tau)) { read += 1; /* * -1 because input_val counts */ if((size - read) < (tau-1)) { acc += curr_val; /* printf("%f ",curr_val); */ count += 1; } } /* printf("%f ",input_val); printf(" | "); */ *out_val = acc / count; Rewind(state_set); return(1); }
PString SIDStil::GetBug(PString relPathToEntry, int32 tuneNo) { if (baseDir.IsEmpty()) return (""); // Older versions of STIL is detected if (stilVersion < 2.59f) tuneNo = 0; // Find out whether we have this bug entry in the buffer. // If the baseDir was changed, we'll have to read it in again, // even if it might be in the buffer already if ((bugBuf.Left(relPathToEntry.GetLength()) != relPathToEntry) || ((bugBuf.Find('\n') != relPathToEntry.GetLength()) && (stilVersion > 2.59f))) { // The relative pathnames don't match or they're not the same length: // We don't have it in the buffer, so pull it in try { PDirectory tempDir; tempDir.SetDirectory(baseDir); tempDir.Append("DOCUMENTS"); bugFile->Open(tempDir.GetDirectory() + "BUGlist.txt", PFile::pModeRead | PFile::pModeShareRead); if (PositionToEntry(relPathToEntry, bugFile, bugDirs) == false) { // Copy the entry's name to the buffer bugBuf = relPathToEntry + "\n"; } else { bugBuf.MakeEmpty(); ReadEntry(bugFile, bugBuf); } bugFile->Close(); } catch(PFileException e) { // Failed reading from the STIL.txt file bugFile->Close(); return (""); } } // Put the requested field into the result string if (GetField(resultBug, bugBuf, tuneNo) != true) return (""); return (resultBug); }
int sBook::FindPos(U64 key) { int left, right, mid; polyglot_move entry[1]; // binary search (finds the leftmost entry) left = 0; right = bookSize-1; while (left < right) { mid = (left + right) / 2; ReadEntry(entry, mid); if (key <= entry->key) right = mid; else left = mid+1; } ReadEntry(entry, left); return (entry->key == key) ? left : bookSize; }
bool vfsHDD::Rename(const std::string& from, const std::string& to) { u64 entry_block; if (!SearchEntry(from, entry_block)) { return false; } vfsHDD_Entry entry; ReadEntry(entry_block, entry); WriteEntry(entry_block, entry, to); return true; }
bool GOrgueArchiveIndex::ReadContent(wxString& id, std::vector<GOArchiveEntry>& entries) { if (!ReadString(id)) return false; unsigned cnt; if (!Read(&cnt, sizeof(cnt))) return false; entries.resize(cnt); for(unsigned i = 0; i < entries.size(); i++) if (!ReadEntry(entries[i])) return false; return true; }
void IOAPIC::EnableIOAPIC () { union IO_APIC_reg_01 reg_01; for(int i = 0; i < PIN_MAP_SIZE; i++) { irq_2_pin[i].pin = -1; irq_2_pin[i].next = 0; } for(int i = 0; i < MAX_PIRQS; i++) pirq_entries[i] = -1; for(int apic = 0; apic < system->smp->nr_ioapics; apic++) { reg_01.raw = ioapic_read(apic, 1); nr_ioapic_registers[apic] = reg_01.bits.entries+1; } for(int apic = 0; apic < system->smp->nr_ioapics; apic++) { for (int pin = 0; pin < nr_ioapic_registers[apic]; pin++) { struct IO_APIC_route_entry entry; entry = ReadEntry(apic, pin); if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) { ioapic_i8259.apic = apic; ioapic_i8259.pin = pin; goto found_i8259; } } } found_i8259: int i8259_pin = system->smp->FindISAIRQPin(0, mp_ExtINT); int i8259_apic = system->smp->FindISAIRQAPIC(0, mp_ExtINT); /* Trust the MP table if nothing is setup in the hardware */ if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) { printk("IOAPIC: ExtINT not setup in hardware but reported by MP table\n"); ioapic_i8259.pin = i8259_pin; ioapic_i8259.apic = i8259_apic; } if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) && (i8259_pin >= 0) && (ioapic_i8259.pin >= 0)) { printk("IOAPIC: ExtINT in hardware and MP table differ\n"); } ClearIOAPIC(); }
list<SyncLogEntry> SyncLogger::GetEntries(const char* pszHash, const string strFilePath) { if(!ParseFile(pszHash)) throw OFSException("Synclogger parse error", 0,true); // Assures the correct parsing of the file. assert(m_pCFG != NULL); list<SyncLogEntry> listOfEntries; const int nCount = cfg_size(m_pCFG, MOD_NUMBER_VARNAME); for (int i = 0; i < nCount; i++) { SyncLogEntry sle = ReadEntry(cfg_getnsec(m_pCFG, MOD_NUMBER_VARNAME, i)); if (strFilePath == "" || sle == strFilePath) listOfEntries.push_back(sle); } return listOfEntries; }
SeqEntry *NextSeqEntry(SeqSpec *wildName) { SeqSpec *thisSpec; thisSpec = NewSeqSpec(); if ( wildName->file[0] == '@' ) { if ( NextIndSpec(wildName, thisSpec) == 0 ) return(NULL); } else { if ( wildName->isUser ) { if ( NextUserSpec(wildName, thisSpec) == 0 ) return(NULL); } else { if ( NextDBSpec(wildName, thisSpec) == 0 ) return(NULL); } } return( ReadEntry(thisSpec) ); }
\t-A <produce a sum instead of an average>\n\ \t-c count (cannot be used with -t)\n\ \t-t time (cannot be used with -c)\n\ \t-o <make the windows overlap>\n"; int AvgByTime(double ts, double input_val, void *state_set, double time_delta, double *out_ts, double *out_val) { int ierr; double curr_ts; double curr_val; double count; double acc; Rewind(state_set); acc = input_val; *out_ts = ts; count = 1.0; while(ReadEntry(state_set,&curr_ts,&curr_val) != 0) { /* * if we are within a delta of the ts, count it */ if(curr_ts >= (ts - time_delta)) { acc += curr_val; count += 1; } } *out_val = acc / count; Rewind(state_set); return(1); }
void vfsHDD::RemoveBlocksDir(u64 start_block) { std::string name; u64 block = start_block; vfsHDD_Entry entry; while (block) { ReadEntry(block, entry, name); WriteBlock(block, g_null_block); if (entry.type == vfsHDD_Entry_Dir && name != "." && name != "..") { LOG_WARNING(HLE, "Removing sub folder '%s'", name.c_str()); RemoveBlocksDir(entry.data_block); } else if (entry.type == vfsHDD_Entry_File) { RemoveBlocksFile(entry.data_block); } block = entry.next_block; } }
int SumByTime(double ts, double input_val, void *state_set, double time_delta, double *out_ts, double *out_val) { int ierr; double curr_ts; double curr_val; double count; double acc; Rewind(state_set); acc = input_val; *out_ts = ts; count = 1.0; while(ReadEntry(state_set,&curr_ts,&curr_val) != 0) { /* * if we are within a delta of the ts, count it */ if(curr_ts >= (ts - time_delta)) { acc += curr_val; count += 1; } } *out_val = acc; Rewind(state_set); return(1); }
int sBook::GetPolyglotMove(sPosition *p, int printOutput) { int bestMove = 0; int bestScore = 0; int maxWeight = 0; int sumOfWeights = 0; int pos; polyglot_move entry[1]; int move; int score; int values[100]; U64 key = GetPolyglotKey(p); char moveString[6]; nOfChoices = 0; if (bookFile != NULL && bookSize != 0) { srand(Timer.GetMS() ); for (pos = FindPos(key); pos < bookSize; pos++) { ReadEntry(entry,pos); if (entry->key != key) break; move = entry->move; score = entry->weight; // ugly hack to convert polyglot move to a real one int fsq = Tsq(move); int tsq = Fsq(move); // correction for castling moves if (fsq == E1 && tsq == H1 && p->kingSquare[WHITE] == E1) tsq = G1; if (fsq == E8 && tsq == H8 && p->kingSquare[BLACK] == E8) tsq = G8; if (fsq == E1 && tsq == A1 && p->kingSquare[WHITE] == E1) tsq = C1; if (fsq == E8 && tsq == A8 && p->kingSquare[BLACK] == E8) tsq = C8; // now we want to get a move with full data, not only from and to squares int realMove = (tsq << 6) | fsq; MoveToStr(realMove, moveString); realMove = StrToMove(p, moveString); if (maxWeight < score) maxWeight = score; sumOfWeights += score; moves[nOfChoices] = realMove; values[nOfChoices] = score; nOfChoices++; } // pick a move, filtering out those with significantly lower weight for (int i = 0; i<nOfChoices; i++) { // report about possible choices and rejected moves if (values[i] > 1 || maxWeight == 1) { if (printOutput) { printf("info string "); PrintMove(moves[i]); printf(" %d %%", (values[i] * 100) / sumOfWeights ); if (IsInfrequent(values[i], maxWeight)) printf(" infrequent "); } } // shall we pick this move? if (!IsInfrequent(values[i], maxWeight)) { bestScore += values[i]; if (my_random(bestScore) < values[i]) bestMove = moves[i]; } printf("\n"); } } //if (printOutput) PrintMissingMoves(p); return bestMove; }
PString SIDStil::GetGlobalComment(PString relPathToEntry) { PString dir; int32 lastSlash, pathLen; int32 temp; if (baseDir.IsEmpty()) return (""); // Save the dirpath lastSlash = relPathToEntry.ReverseFind('/'); if (lastSlash == -1) return (""); pathLen = lastSlash + 1; dir = relPathToEntry.Left(pathLen); // Find out whether we have this global comment in the buffer. // If the baseDir was changed, we'll have to read it in again, // even if it might be in the buffer already if ((globalBuf.Left(dir.GetLength()) != dir) || ((globalBuf.Find('\n') != pathLen) && (stilVersion > 2.59f))) { // The relative pathnames don't match or they're not the same length: // We don't have it in the buffer, so pull it in try { PDirectory tempDir; tempDir.SetDirectory(baseDir); tempDir.Append("DOCUMENTS"); stilFile->Open(tempDir.GetDirectory() + "STIL.txt", PFile::pModeRead | PFile::pModeShareRead); if (PositionToEntry(dir, stilFile, stilDirs) == false) { // Copy the dirname to the buffer globalBuf = dir + "\n"; } else { globalBuf.MakeEmpty(); ReadEntry(stilFile, globalBuf); } stilFile->Close(); } catch(PFileException e) { // Failed reading from the STIL.txt file stilFile->Close(); return (""); } } // Position the index to the global comment field temp = globalBuf.Find('\n'); temp++; // Check whether this is a NULL entry or not if (temp == globalBuf.GetLength()) return (""); return (globalBuf.Mid(temp)); }
void INI_LoadSettings(SETTINGS *settings) { wchar_t filename[] = L".\\Durazno.ini"; settings[0].port = 0; settings[1].port = 1; settings[2].port = 2; settings[3].port = 3; if(ReadEntry(L"General", -1, L"INIversion", filename) != INIversion) return; customDLL = ReadString(L"General", -1, L"LoadDLL", filename); for(s32 port = 0; port < 4; port++) { SETTINGS &set = settings[port]; s32 result; result = ReadEntry(L"Controller", port, L"Port", filename); if (result != -1) set.port = result % 4; set.isDisabled = ReadEntry(L"Controller", port, L"Disable", filename) == 1 ? true : false; set.isDummy = ReadEntry(L"Controller", port, L"Dummy", filename) == 1 ? true : false; set.linearDZ = ReadEntry(L"Controller", port, L"LinearDZ", filename) == 1 ? true : false; set.linearADZ = ReadEntry(L"Controller", port, L"LinearADZ", filename) == 1 ? true : false; set.stickL.invertedX = ReadEntry(L"Controller", port, L"AxisInvertedLX", filename) == 1 ? true : false; set.stickL.invertedY = ReadEntry(L"Controller", port, L"AxisInvertedLY", filename) == 1 ? true : false; set.stickR.invertedX = ReadEntry(L"Controller", port, L"AxisInvertedRX", filename) == 1 ? true : false; set.stickR.invertedY = ReadEntry(L"Controller", port, L"AxisInvertedRY", filename) == 1 ? true : false; result = ReadEntry(L"Controller", port, L"TriggerMin", filename); if (result != -1) set.triggerMin = result & 0xFF; result = ReadEntry(L"Controller", port, L"TriggerMax", filename); if (result != -1) set.triggerMax = result & 0xFF; result = ReadEntry(L"Controller", port, L"Rumble", filename); if (result != -1) set.rumble = result / FACTOR; result = ReadEntry(L"Controller", port, L"L_Linearity", filename); if (result != -1) set.stickL.linearity = (result - 300.0) / 100.0; result = ReadEntry(L"Controller", port, L"L_Deadzone", filename); if (result != -1) set.stickL.deadzone = result / FACTOR; result = ReadEntry(L"Controller", port, L"L_AntiDeadzone", filename); if (result != -1) set.stickL.antiDeadzone = result / FACTOR; result = ReadEntry(L"Controller", port, L"R_Linearity", filename); if (result != -1) set.stickR.linearity = (result - 300.0) / 100.0; result = ReadEntry(L"Controller", port, L"R_Deadzone", filename); if (result != -1) set.stickR.deadzone = result / FACTOR; result = ReadEntry(L"Controller", port, L"R_AntiDeadzone", filename); if (result != -1) set.stickR.antiDeadzone = result / FACTOR; ReadRemap(port, filename, settings); } }
int main(int argc,char *argv[]) { double val; double ts; void *data_set; int size; int c; int curr; int ierr; char fname[255]; if(argc < 2) { fprintf(stderr,"usage: testinput -f filename\n"); fflush(stderr); exit(1); } fname[0] = 0; memset(fname,0,sizeof(fname)); while((c = getopt(argc,argv,PRED_ARGS)) != EOF) { switch(c) { case 'f': strncpy(fname,optarg,sizeof(fname)); break; default: fprintf(stderr,"unrecognized argument %c\n", c); fflush(stderr); break; } } if(fname[0] == 0) { fprintf(stderr,"usage: testinput -f fname\n"); fflush(stderr); exit(1); } ierr = InitDataSet(&data_set,2); if(ierr == 0) { fprintf(stderr,"testinput error: InitDataSet failed\n"); exit(1); } SetBlockSize(data_set,14); ierr = LoadDataSet(fname,data_set); if(ierr == 0) { fprintf(stderr, "testinput error: LoadDataSet failed for %s\n", fname); exit(1); } while(ReadEntry(data_set,&ts,&val)) { fprintf(stdout,"%d %f\n",(int)ts,val); fflush(stdout); } FreeDataSet(data_set); exit(0); }
void INI_LoadSettings() { wchar_t filename[] = L".\\Durazno.ini"; settings[0].port = 0; settings[1].port = 1; settings[2].port = 2; settings[3].port = 3; if(ReadEntry(L"General", -1, L"INIversion", filename) != INIversion) return; customDLL = ReadString(L"General", -1, L"LoadDLL", filename); for(s32 port = 0; port < 4; port++) { s32 result; settings[port].isDisabled = ReadEntry(L"Controller", port, L"Disable", filename) == 1? true : false; settings[port].isDummy = ReadEntry(L"Controller", port, L"Dummy", filename) == 1? true : false; settings[port].axisInverted[GP_AXIS_LX] = ReadEntry(L"Controller", port, L"AxisInvertedLX", filename) == 1? true : false; settings[port].axisInverted[GP_AXIS_LY] = ReadEntry(L"Controller", port, L"AxisInvertedLY", filename) == 1? true : false; settings[port].axisInverted[GP_AXIS_RX] = ReadEntry(L"Controller", port, L"AxisInvertedRX", filename) == 1? true : false; settings[port].axisInverted[GP_AXIS_RY] = ReadEntry(L"Controller", port, L"AxisInvertedRY", filename) == 1? true : false; result = ReadEntry(L"Controller", port, L"TriggerMin", filename); if(result != -1) settings[port].triggerMin = result & 0xFF; result = ReadEntry(L"Controller", port, L"TriggerMax", filename); if(result != -1) settings[port].triggerMax = result & 0xFF; result = ReadEntry(L"Controller", port, L"Linearity", filename); if(result != -1) settings[port].linearity = result/10.0 - 3.0; result = ReadEntry(L"Controller", port, L"Deadzone", filename); if(result != -1) settings[port].deadzone = result / 100.0f; result = ReadEntry(L"Controller", port, L"AntiDeadzone", filename); if(result != -1) settings[port].antiDeadzone = result / 100.0f; result = ReadEntry(L"Controller", port, L"Rumble", filename); if(result != -1) settings[port].rumble = result / 100.0f; result = ReadEntry(L"Controller", port, L"Port", filename); if(result != -1) settings[port].port = result % 4; result = ReadEntry(L"Controller", port, L"TurboToggle", filename); if (result != -1) settings[port].turboToggle = result; ReadRemap(port, filename); ReadTurbo(port, filename); } }
/** * \param ArgTypes * * Whitespace is ignored * >i: Input Integer (32-bits) * >I: Input Long Integer (64-bits) * >s: Input String * >d: Input Buffer (Preceded by valid size) * <I: Output long integer * <d: Output Buffer (Preceded by valid size) * ?d: Bi-directional buffer (Preceded by valid size), buffer contents * are returned */ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) { va_list args; int paramCount, dataLength; int retCount = 2, retLength = sizeof(uint64_t) + sizeof(uint32_t); void **retPtrs; // Pointers to return buffers const char *str; tRequestHeader *req; void *dataPtr; uint64_t retValue; int i; // DEBUG! // printf("&tRequestHeader->Params = %i\n", offsetof(tRequestHeader, Params)); // printf("&tRequestValue->Flags = %i\n", offsetof(tRequestValue, Flags)); // printf("&tRequestValue->Length = %i\n", offsetof(tRequestValue, Length)); // Get data size va_start(args, ArgTypes); str = ArgTypes; paramCount = 0; dataLength = 0; while(*str) { tRequestValue tmpVal; str = ReadEntry(&tmpVal, NULL, NULL, str, &args); if( !str ) { fprintf(stderr, "syscalls.c: ReadEntry failed (SyscallID = %i)\n", SyscallID); exit(127); } paramCount ++; if( !(tmpVal.Flags & ARG_FLAG_ZEROED) ) dataLength += tmpVal.Length; if( tmpVal.Flags & ARG_FLAG_RETURN ) { retLength += tmpVal.Length; retCount ++; } } va_end(args); dataLength += sizeof(tRequestHeader) + paramCount*sizeof(tRequestValue); retLength += sizeof(tRequestHeader) + retCount*sizeof(tRequestValue); // Allocate buffers retPtrs = malloc( sizeof(void*) * (retCount+1) ); if( dataLength > retLength) req = malloc( dataLength ); else req = malloc( retLength ); req->ClientID = 0; //< Filled later req->CallID = SyscallID; req->NParams = paramCount; req->MessageLength = dataLength; dataPtr = &req->Params[paramCount]; // Fill `output` and `input` va_start(args, ArgTypes); str = ArgTypes; // - re-zero so they can be used as indicies paramCount = 0; retCount = 0; while(*str) { str = ReadEntry(&req->Params[paramCount], dataPtr, &retPtrs[retCount], str, &args); if( !str ) break; if( !(req->Params[paramCount].Flags & ARG_FLAG_ZEROED) ) dataPtr += req->Params[paramCount].Length; if( req->Params[paramCount].Flags & ARG_FLAG_RETURN ) retCount ++; paramCount ++; } va_end(args); // --- Send syscall request if( SendRequest(req, dataLength, retLength) < 0 ) { fprintf(stderr, "syscalls.c: SendRequest failed (SyscallID = %i)\n", SyscallID); exit(127); } dataPtr = (void*)&req->Params[req->NParams]; assert(req->NParams >= 2); // return assert(req->Params[0].Type == ARG_TYPE_INT64); assert(req->Params[0].Length == sizeof(uint64_t)); retValue = *(uint64_t*)dataPtr; dataPtr += sizeof(uint64_t); // errno assert(req->Params[1].Type == ARG_TYPE_INT32); assert(req->Params[1].Length == sizeof(uint32_t)); acess__errno = *(uint32_t*)dataPtr; dataPtr += sizeof(uint32_t); // Write changes to buffers if( req->NParams - 2 != retCount ) { fprintf(stderr, "syscalls.c: Return count inbalance (%i - 1 != exp %i) [Call %i]\n", req->NParams, retCount, SyscallID); exit(127); } retCount = 0; for( i = 2; i < req->NParams; i ++ ) { #if 0 int j; printf("Return Data %i: (%i)", i, req->Params[i].Length); for( j = 0; j < req->Params[i].Length; j ++ ) printf(" %02x", ((uint8_t*)dataPtr)[j]); printf("\n"); #endif assert( req->Params[i].Type == ARG_TYPE_DATA ); memcpy( retPtrs[retCount++], dataPtr, req->Params[i].Length ); dataPtr += req->Params[i].Length; } free( req ); free( retPtrs ); DEBUG(": %i 0x%llx", SyscallID, retValue); return retValue; }
// --------------------------------------------------------------------------- // CAtPhbkStoreRead::EventSignal // other items were commented in a header // --------------------------------------------------------------------------- void CAtPhbkStoreRead::EventSignal(TAtEventSource aEventSource, TInt aStatus) { LOGTEXT3(_L8("CAtPhbkStoreRead::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource); if(aStatus != KErrNone) { Complete(); iPhoneGlobals.iEventSignalActive = EFalse; iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(aStatus,iPhoneBookType,iPhbkData); } else { if( aEventSource== EWriteCompletion ) { if( iState==ESetStoreName ) { iState = ESetStoreNameComplete; } else if( iState==EReadEntry ) { iState = EReadEntryComplete; } } else { if( iState==ESetStoreNameComplete ) { Complete(); iPhoneGlobals.iEventSignalActive = EFalse; if(iError == KErrNone) { ClearBuffer(); iState = EReadEntry; ReadEntry(); } else { iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(iError,iPhoneBookType,iPhbkData); } } else if( iState==EReadEntryComplete ) { Complete(); iPhoneGlobals.iEventSignalActive = EFalse; //encounter OK or ERROR if( iEndFlag ) { ClearBuffer(); iPhbkData.Zero(); iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(iError,iPhoneBookType,iPhbkData); } else { if( iError==KErrNone ) { TRAPD(err, GeneratePhbkDataL()); iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(err,iPhoneBookType,iPhbkData); ClearCurrentLine(); } else { iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(iError,iPhoneBookType,iPhbkData); } } } } } }