void BeaconTransmitter::Configure(const std::string& name, unsigned int protocolID, unsigned int listenerPort, unsigned int serverPort, Serializable* userData) { GetHeader().GetData().SetName(name); GetHeader().GetData().mProtocolID = protocolID; mListenerPort = listenerPort; GetHeader().GetData().mServerPort = serverPort; mpUserData = userData; mIsConfigured = true; }
void STRING::assign(const char *cstr, int len) { STRING_HEADER* this_header = GetHeader(); this_header->used_ = 0; // dont bother copying data if need to realloc char* this_cstr = ensure_cstr(len + 1); // +1 for '\0' this_header = GetHeader(); // for realloc memcpy(this_cstr, cstr, len); this_cstr[len] = '\0'; this_header->used_ = len + 1; assert(InvariantOk()); }
char* Packet::GetPacket(){ if (completebuffer){ if (!m_bSplitted) memcpy(completebuffer,GetHeader(),6); return completebuffer; } else{ delete[] tempbuffer; tempbuffer = NULL; // 'new' may throw an exception tempbuffer = new char[size+10]; memcpy(tempbuffer,GetHeader(),6); memcpy(tempbuffer+6,pBuffer,size); return tempbuffer; } }
STRING& STRING::operator=(const STRING& str) { str.FixHeader(); const STRING_HEADER* str_header = str.GetHeader(); int str_used = str_header->used_; GetHeader()->used_ = 0; // clear since ensure doesnt need to copy data char* this_cstr = ensure_cstr(str_used); STRING_HEADER* this_header = GetHeader(); memcpy(this_cstr, str.GetCStr(), str_used); this_header->used_ = str_used; assert(InvariantOk()); return *this; }
bool FastCheck() const { if (Size < sizeof(RawHeader)) { return false; } const RawHeader& header = GetHeader(); BOOST_STATIC_ASSERT(sizeof(header.ID) == sizeof(FDI_ID)); if (0 != std::memcmp(header.ID, FDI_ID, sizeof(FDI_ID))) { return false; } const std::size_t dataOffset = fromLE(header.DataOffset); if (dataOffset < sizeof(header) || dataOffset > Size) { return false; } const uint_t cylinders = fromLE(header.Cylinders); if (!Math::InRange(cylinders, MIN_CYLINDERS_COUNT, MAX_CYLINDERS_COUNT)) { return false; } const uint_t sides = fromLE(header.Sides); if (!Math::InRange(sides, MIN_SIDES_COUNT, MAX_SIDES_COUNT)) { return false; } return true; }
Tile *Tile::CopyTile(BackendType backend_type) { auto schema = GetSchema(); bool tile_columns_inlined = schema->IsInlined(); auto allocated_tuple_count = GetAllocatedTupleCount(); // Create a shallow copy of the old tile TileGroupHeader *new_header = GetHeader(); Tile *new_tile = TileFactory::GetTile( backend_type, INVALID_OID, INVALID_OID, INVALID_OID, INVALID_OID, new_header, *schema, tile_group, allocated_tuple_count); PL_MEMCPY(static_cast<void *>(new_tile->data), static_cast<void *>(data), tile_size); // Do a deep copy if some column is uninlined, so that // the values in that column point to the new pool if (!tile_columns_inlined) { auto uninlined_col_cnt = schema->GetUninlinedColumnCount(); // Go over each uninlined column, making a deep copy for (oid_t col_itr = 0; col_itr < uninlined_col_cnt; col_itr++) { auto uninlined_col_offset = schema->GetUninlinedColumn(col_itr); // Copy the column over to the new tile group for (oid_t tuple_itr = 0; tuple_itr < allocated_tuple_count; tuple_itr++) { type::Value val = (new_tile->GetValue(tuple_itr, uninlined_col_offset)); new_tile->SetValue(val, tuple_itr, uninlined_col_offset); } } } return new_tile; }
SubMediaPiecePtr Storage::GetSubPiece(UINT pieceIndex, UINT8 subPieceIndex) const { //SubMediaPiecePtr subPiece = m_unfinishedDataPieces.GetSubPiece(pieceIndex, subPieceIndex); //if ( subPiece ) // return subPiece; SubMediaPiecePtr subPiece; PieceInfo pieceInfo = this->GetPieceInfo(pieceIndex); if (pieceInfo.IsValid()) { // 从piece中提取sub piece subPiece = pieceInfo.GetSubPiece(subPieceIndex); //LIVE_ASSERT( subPiece ); } else { // 检查headers //subPiece = m_unfinishedHeaderPieces.GetSubPiece(pieceIndex, subPieceIndex); //if ( subPiece ) // return subPiece; MediaHeaderPiecePtr headerPiece = GetHeader(pieceIndex); if ( headerPiece ) { subPiece = SubMediaPiecePtr(headerPiece->GetSubPiece(subPieceIndex)); //LIVE_ASSERT( subPiece ); } } return subPiece; }
void CListUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) { if( _tcscmp(pstrName, _T("header")) == 0 ) GetHeader()->SetVisible(_tcscmp(pstrValue, _T("hidden")) != 0); else if( _tcscmp(pstrName, _T("footer")) == 0 ) GetFooter()->SetVisible(_tcscmp(pstrValue, _T("hidden")) != 0); else if( _tcscmp(pstrName, _T("expanding")) == 0 ) SetExpanding(_tcscmp(pstrValue, _T("true")) == 0); else CVerticalLayoutUI::SetAttribute(pstrName, pstrValue); }
size_t BindTransmitter::Size() const { const size_t size = GetHeader().Size() + systemId_.Size() + password_.Size() + systemType_.Size() \ + interfaceVersion_.Size() + addrTon_.Size() + addrNpi_.Size() + addressRange_.Size(); return size; }
bool YL_CHTTPRequest::GetHeaderItem( const string& strItemName,string& strContent ) { long lHeadLen = 0; unsigned char* pszHead = GetHeader( lHeadLen ); if( pszHead != NULL && lHeadLen > 0) { char* pTmpBuf = new char[lHeadLen+1]; memcpy(pTmpBuf,pszHead,lHeadLen); pTmpBuf[lHeadLen] = '\0'; char* pPos = strstr( pTmpBuf,strItemName.c_str()); if( pPos == NULL ) { delete pTmpBuf; return false; } pPos = strstr( pPos+1,":"); if( pPos == NULL ) { delete pTmpBuf; return false; } while (*++pPos) { if (*pPos != ' ') break; } char* pPos2 = strstr( pPos,"\r\n"); *pPos2 = '\0'; strContent = pPos; delete[] pTmpBuf; return true; } return false; }
int add_or_update_alarm(uint8_t hour, uint8_t min, uint8_t mode, uint8_t repeat_factor, char *name) { pthread_mutex_t *bucket_mtx = GetLock(hour, min); pthread_mutex_lock(bucket_mtx); AlarmClockInfo *header = GetHeader(hour, min); AlarmClockInfo *temp = header; // Check whether an existing entry should be updated while (temp) { if (temp->hour == hour && temp->min == min) { temp->mode = mode; temp->repeat_factor = repeat_factor; strcpy(temp->name, name); pthread_mutex_unlock(bucket_mtx); return 0; } temp = temp->next; } // A new entry is inserted AlarmClockInfo *naci = CreateNewInfo(hour,min,mode,repeat_factor,name); naci->next = header; *AC_TABLE_ENTRY(hour,min) = naci; pthread_mutex_unlock(bucket_mtx); return 1; }
// Return 1 if found and removed, otherwise return 0 int cancel_alarm(uint8_t hour, uint8_t min, int play) { pthread_mutex_t *bucket_mtx = GetLock(hour, min); pthread_mutex_lock(bucket_mtx); AlarmClockInfo *cand = GetHeader(hour, min); AlarmClockInfo *prev = NULL; while (cand) { if (cand->hour == hour && cand->min == min) { // Optionally, play the alarm here before essentially removing it // ... if (play) ; // sound an alarm if (!prev) *AC_TABLE_ENTRY(hour, min) = cand->next; else prev->next = cand->next; free(cand); pthread_mutex_unlock(bucket_mtx); return 1; } prev = cand; cand = cand->next; } pthread_mutex_unlock(bucket_mtx); return 0; }
bool FastCheck() const { if (Size <= sizeof(RawHeader)) { return false; } const RawHeader& header = GetHeader(); const uint_t endOfBlock = fromLE(header.LastSrcRestBytes) + 1; const uint_t lastBytesAddr = endOfBlock - LAST_BYTES_COUNT; const uint_t bitStreamAddr = lastBytesAddr - fromLE(header.SizeOfPacked); const uint_t srcPacked = fromLE(header.SrcPacked); if (bitStreamAddr == srcPacked) { //move forward } else if (lastBytesAddr == srcPacked + 1) { //move backward } else { return false; } const std::size_t usedSize = GetUsedSize(); return Math::InRange(usedSize, sizeof(header), Size); }
//Draw the border and background, leave clip set to the windows client area bool SummerfaceWindow::PrepareDraw () { if(UseBorder) { ESVideo::SetClip(Area(0, 0, ESVideo::GetScreenWidth(), ESVideo::GetScreenHeight())); //TODO: Make border color ESVideo::FillRectangle(Area(Region.X, Region.Y, Region.Width, BorderWidth), 0xFFFFFFFF); ESVideo::FillRectangle(Area(Region.X + BorderWidth, Region.Bottom(), Region.Width, BorderWidth), 0x00000080); ESVideo::FillRectangle(Area(Region.X, Region.Bottom() - BorderWidth, Region.Width, BorderWidth), 0xFFFFFFFF); ESVideo::FillRectangle(Area(Region.X, Region.Y + BorderWidth, BorderWidth, Region.Height - BorderWidth * 2), 0xFFFFFFFF); ESVideo::FillRectangle(Area(Region.Right(), Region.Y + BorderWidth, BorderWidth, Region.Height - BorderWidth), 0x00000080); ESVideo::FillRectangle(Area(Region.Right() - BorderWidth, Region.Y + BorderWidth, BorderWidth, Region.Height - BorderWidth * 2), 0xFFFFFFFF); ESVideo::FillRectangle(Client, Colors::BackGround); ESVideo::SetClip(Client); std::string header = GetHeader(); if(!header.empty()) { FontManager::GetBigFont()->PutString(header.c_str(), 1, 1, Colors::Normal, true); ESVideo::FillRectangle(Area(0, FontManager::GetBigFont()->GetHeight() + 1, Client.Width, 1), 0xFFFFFFFF); ESVideo::SetClip(Area(Client.X, Client.Y + FontManager::GetBigFont()->GetHeight() + 3, Client.Width, Client.Height - (FontManager::GetBigFont()->GetHeight() + 3))); } } else { ESVideo::SetClip(Region); } return Draw(); }
void BindTransmitter::initBody(const unsigned char *data, size_t len) { size_t offset = GetHeader().Size(); systemId_ = CString(data + offset, SystemIdLen, "system_id"); offset += systemId_.Size(); password_ = CString(data + offset, PasswordLen, "password"); offset += password_.Size(); systemType_ = CString(data + offset, SystemTypeLen, "system_type"); offset += systemType_.Size(); interfaceVersion_ = OneByteInteger(data + offset, "interface_version"); offset += interfaceVersion_.Size(); addrTon_ = OneByteInteger(data + offset, "addr_ton"); offset += addrTon_.Size(); addrNpi_ = OneByteInteger(data + offset, "addr_npi"); offset += addrNpi_.Size(); addressRange_ = CString(data + offset, AddressRangeLen, "address_range"); offset += addressRange_.Size(); if (offset != len) { // throw std::invalid_argument("FOO"); } }
void STRING::insert_range(inT32 index, const char* str, int len) { // if index is outside current range, then also grow size of string // to accmodate the requested range. STRING_HEADER* this_header = GetHeader(); int used = this_header->used_; if (index > used) used = index; char* this_cstr = ensure_cstr(used + len + 1); if (index < used) { // move existing string from index to '\0' inclusive. memmove(this_cstr + index + len, this_cstr + index, this_header->used_ - index); } else if (len > 0) { // We are going to overwrite previous null terminator, so write the new one. this_cstr[this_header->used_ + len - 1] = '\0'; // If the old header did not have the terminator, // then we need to account for it now that we've added it. // Otherwise it was already accounted for; we just moved it. if (this_header->used_ == 0) ++this_header->used_; } // Write new string to index. // The string is already terminated from the conditions above. memcpy(this_cstr + index, str, len); this_header->used_ += len; assert(InvariantOk()); }
SysStatus MPMsgMgr::MsgSync::send(DispatcherID dspid) { MsgHeader *const hdr = GetHeader(this); SysStatus rc; MPMsgMgr *targetMgr; rc = DREF(hdr->manager->getRegistry())->lookupMgr(dspid, targetMgr); tassert(_SUCCESS(rc), err_printf("MPMsgAsync: lookupMgr failed.\n")); hdr->sender = Scheduler::GetCurThread(); targetMgr->addPendingSend(hdr); /* * This is the trivial implementation, where we immediately block when * sending a cross processor message. We have a more sophisticated * algorithm which attempts to spin for a while and then blocks if * information in the reply queue is not for us. FIXME, implement this */ while (hdr->sender != Scheduler::NullThreadID) { Scheduler::Block(); } /* * With the message queue implementation, message returned is the same * as message sent. */ return 0; }
// Return false if the tuple's table (tile group) is dropped. // In such case, this recycled tuple can not be added to the recycled_list. // Since no one will use it any more, keeping track of it is useless. // Note that, if we drop a single tile group without dropping the whole table, // such assumption is problematic. bool GCManager::ResetTuple(const TupleMetadata &tuple_metadata) { auto &manager = catalog::Manager::GetInstance(); auto tile_group = manager.GetTileGroup(tuple_metadata.tile_group_id); // During the resetting, a table may deconstruct because of the DROP TABLE request if (tile_group == nullptr) { LOG_TRACE("Garbage tuple(%u, %u) in table %u no longer exists", tuple_metadata.tile_group_id, tuple_metadata.tuple_slot_id, tuple_metadata.table_id); return false; } // From now on, the tile group shared pointer is held by us // It's safe to set headers from now on. auto tile_group_header = tile_group->GetHeader(); // Reset the header tile_group_header->SetTransactionId(tuple_metadata.tuple_slot_id, INVALID_TXN_ID); tile_group_header->SetBeginCommitId(tuple_metadata.tuple_slot_id, MAX_CID); tile_group_header->SetEndCommitId(tuple_metadata.tuple_slot_id, MAX_CID); tile_group_header->SetPrevItemPointer(tuple_metadata.tuple_slot_id, INVALID_ITEMPOINTER); tile_group_header->SetNextItemPointer(tuple_metadata.tuple_slot_id, INVALID_ITEMPOINTER); PL_MEMSET( tile_group_header->GetReservedFieldRef(tuple_metadata.tuple_slot_id), 0, storage::TileGroupHeader::GetReservedSize()); LOG_TRACE("Garbage tuple(%u, %u) in table %u is reset", tuple_metadata.tile_group_id, tuple_metadata.tuple_slot_id, tuple_metadata.table_id); return true; }
size_t DWARFMappedHash::MemoryTable::FindCompleteObjCClassByName (const char *name, DIEArray &die_offsets, bool must_be_implementation) { DIEInfoArray die_info_array; if (FindByName(name, die_info_array)) { if (must_be_implementation && GetHeader().header_data.ContainsAtom (eAtomTypeTypeFlags)) { // If we have two atoms, then we have the DIE offset and // the type flags so we can find the objective C class // efficiently. DWARFMappedHash::ExtractTypesFromDIEArray (die_info_array, UINT32_MAX, eTypeFlagClassIsImplementation, die_offsets); } else { // We don't only want the one true definition, so try and see // what we can find, and only return class or struct DIEs. // If we do have the full implementation, then return it alone, // else return all possible matches. const bool return_implementation_only_if_available = true; DWARFMappedHash::ExtractClassOrStructDIEArray (die_info_array, return_implementation_only_if_available, die_offsets); } } return die_offsets.size(); }
void BaseWordForm::PrepareHeader() { Header *header = GetHeader(); if (header) { if (!__pICHeader) __pICHeader = Utils::GetBitmapN("ic_header.png"); header->SetTitleIcon(__pICHeader); header->RemoveAllButtons(); header->RemoveAllItems(); if (__pContextMenu) { ButtonItem btnMenu; btnMenu.Construct(BUTTON_ITEM_STYLE_ICON, ID_MENU); btnMenu.SetIcon(BUTTON_ITEM_STATUS_NORMAL, Utils::GetBitmapN(L"ic_menu.png")); header->SetButton(BUTTON_POSITION_RIGHT, btnMenu); } // ButtonItem btnAddWord; // btnAddWord.Construct(BUTTON_ITEM_STYLE_ICON, ID_ADD_WORD); // //btnAddWord.SetText(GetString("IDS_ADD_WORD_BUTTON")); // btnAddWord.SetIcon(BUTTON_ITEM_STATUS_NORMAL, Utils::GetBitmap(L"ic_add_word.png")); // HeaderItem headerItem1; // header->SetTitleText("voc4u"); // header->SetButton(BUTTON_POSITION_RIGHT, btnAddWord); // header->PlayWaitingAnimation(HEADER_ANIMATION_POSITION_BUTTON_LEFT); header->SetTitleText("Voc4u"); header->AddActionEventListener(*this); } }
void edbPackage::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane) { if (!expandedKids) { expandedKids=true; browser->RemoveDummyChild(this); // Log wxLogInfo(wxT("Adding child object to package %s"), GetIdentifier().c_str()); browser->AppendCollection(this, packageFunctionFactory); browser->AppendCollection(this, packageProcedureFactory); browser->AppendCollection(this, packageVariableFactory); } if (properties) { CreateListColumns(properties); properties->AppendItem(_("Name"), GetName()); properties->AppendItem(_("OID"), GetOid()); properties->AppendItem(_("Owner"), GetOwner()); properties->AppendItem(_("Header"), firstLineOnly(GetHeader())); properties->AppendItem(_("Body"), firstLineOnly(GetBody())); properties->AppendItem(_("ACL"), GetAcl()); properties->AppendItem(_("System package?"), GetSystemObject()); if (GetConnection()->EdbMinimumVersion(8, 2)) properties->AppendItem(_("Comment"), firstLineOnly(GetComment())); } }
BOOL CItemList::OnLButtonDown(UINT flags, LPPOINT point, LPRECT prect ) { DWORD i = GetItem( point, prect ); // Select items SelectItem( i, TRUE, TRUE, ( GetKeyState( VK_CONTROL ) & 0x8000 ), ( GetKeyState( VK_SHIFT ) & 0x8000 ) != 0 ); // Set scroll information if ( i < m_dwPtr && m_pIndex[ i ] != NULL && ( m_pIndex[ i ]->flags & LIF_GROUP ) != 0 ) { // Validate max scroll line DWORD slm = GetScrollLineMax( prect ); DWORD cl = GetCurLine(); if ( cl > slm ) SetCurLine( slm ); } // end if // Punt if item clicked if ( i != MAXDWORD )return TRUE; // Are we clicking a header resize area? m_phii = GetHeader().GetHeaderResizeColumn( prect, point, m_lHScroll ); if ( m_phii != NULL ) { m_phiiwidth = m_phii->width; } // end if // Save click location m_lbuttondown.x = point->x; m_lbuttondown.y = point->y; return FALSE; }
int CWav::Load(const char* fn) { GetHeader(fn, &m_PCM.length, &m_PCM.sample_per_sec, &m_PCM.play_time, &m_PCM.raw_offset); FILE* fp = fopen(fn, "rb"); if (!fp) { return -1; } fseek(fp, m_PCM.raw_offset, SEEK_SET); m_PCM.raw = (short*)malloc(m_PCM.length * 2 * sizeof(short)); int idx = 0; for(int i = 0; i < m_PCM.length; i++) { short data; fread(&data, 2, 1, fp); m_PCM.raw[idx++] = data; fread(&data, 2, 1, fp); m_PCM.raw[idx++] = data; } fclose(fp); m_AL.device = alcOpenDevice(NULL); m_AL.context = alcCreateContext(m_AL.device, NULL); alcMakeContextCurrent(m_AL.context); alGenBuffers(1, &m_AL.buffer); alBufferData(m_AL.buffer, AL_FORMAT_STEREO16, m_PCM.raw, m_PCM.length * 2 * sizeof(ALshort), 44100); alGenSources(1, &m_AL.source); alSourcei(m_AL.source, AL_BUFFER, m_AL.buffer); // alSourcei(m_AL.source, AL_LOOPING, AL_TRUE ); Play(); return 0; }
// static already_AddRefed<Shmem::SharedMemory> Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead, const IPC::Message& aDescriptor, id_t* aId, bool aProtect) { size_t size; size_t pageSize = SharedMemory::SystemPageSize(); // |2*pageSize| is for the front and back sentinels RefPtr<SharedMemory> segment = ReadSegment(aDescriptor, aId, &size, 2*pageSize); if (!segment) { return nullptr; } Header* header = GetHeader(segment); if (size != header->mSize) { // Deallocation should zero out the header, so check for that. if (header->mSize || header->mUnsafe || header->mMagic[0] || memcmp(header->mMagic, &header->mMagic[1], sizeof(header->mMagic)-1)) { NS_ERROR("Wrong size for this Shmem!"); } else { NS_WARNING("Shmem was deallocated"); } return nullptr; } // The caller of this function may not know whether the segment is // unsafe or not if (!header->mUnsafe && aProtect) Protect(segment); return segment.forget(); }
TreeViewItemPtr TreeViewItem::HitTreeItem(suic::Point pt) { if (GetHeader()) { suic::Rect rect = suic::VisualHelper::GetRenderRect(GetHeaderHost().get()); if (rect.PointIn(pt)) { return this; } } TreeViewItemPtr ret; int count = GetItems()->GetCount(); for (int i = 0; i < count; ++i) { TreeViewItemPtr item(GetItems()->GetItem(i)); if (item.get() && (ret=item->HitTreeItem(pt))) { break; } } return ret; }
// This is a private method; ensure FixHeader is called (or used_ is well defined) // beforehand char* STRING::ensure_cstr(inT32 min_capacity) { STRING_HEADER* orig_header = GetHeader(); if (min_capacity <= orig_header->capacity_) return ((char *)this->data_) + sizeof(STRING_HEADER); // if we are going to grow bigger, than double our existing // size, but if that still is not big enough then keep the // requested capacity if (min_capacity < 2 * orig_header->capacity_) min_capacity = 2 * orig_header->capacity_; int alloc = sizeof(STRING_HEADER) + min_capacity; STRING_HEADER* new_header = (STRING_HEADER*)(alloc_string(alloc)); memcpy(&new_header[1], GetCStr(), orig_header->used_); new_header->capacity_ = min_capacity; new_header->used_ = orig_header->used_; // free old memory, then rebind to new memory DiscardData(); data_ = new_header; assert(InvariantOk()); return ((char *)data_) + sizeof(STRING_HEADER); }
std::string StiRelationshipConsummatedReporter::GetHeader() const { auto tmpObjectForHeader = CreateInfoObject(); std::string header = tmpObjectForHeader->GetHeader(); delete tmpObjectForHeader; return header ; }
BOOL CWindowsMetaFile::Init(LPCSTR pszFileName) { Reset(); m_pszFileName = pszFileName; return GetHeader(); }
DWORD CItemList::FindString(LPCTSTR pCol, LPCTSTR pStr) { // Get column index DWORD i = GetHeader().FindCol( pCol ); if ( i == MAXDWORD ) return i; return FindString( i, pStr ); }
void MemoryManager::MarkBlockAsAllocated(char * const ptr) { size_t header = (((GetHeader(ptr) ^ (1 << (4 * sizeof(size_t)-1))))); SetHeader(ptr, header); size_t footer = (((GetFooter(ptr) ^ (1 << (4 * sizeof(size_t)-1))))); SetFooter(ptr, footer); }