static RotatedTextItem *XRotRetrieveFromCache(Display* dpy, XFontStruct* font, float angle, char* text, int align) { Font fid; char *font_name = NULL; long unsigned int name_value; RotatedTextItem *item=NULL; RotatedTextItem *i1=first_text_item; /* get font name, if it exists */ if(XGetFontProperty(font, XA_FONT, &name_value)) { DEBUG_PRINT1("got font name OK\n"); font_name=XGetAtomName(dpy, name_value); fid=0; } #ifdef CACHE_FID /* otherwise rely (unreliably?) on font ID */ else { DEBUG_PRINT1("can't get fontname, caching FID\n"); font_name=NULL; fid=font->fid; } #else /* not allowed to cache font ID's */ else {
bool PieceManager::GetRequest(std::list<SliceInfo> &slice_list, t_uint32 want_num, const BitField &remote_own_pieces) { assert(want_num > 0); slice_list.clear(); DownloadingPiece* pdown = get_best_downloading(remote_own_pieces); if(pdown == 0) { DEBUG_PRINT0("get_best_downloading failed\n"); return false; } else { for(size_t i = 0; i < want_num; ++i) { SliceInfo si; if(!pdown->GetRequest(si, IsEndGame())) { DEBUG_PRINT1("pdown->GetRequest(si) failed slist.size() == %d\n", slice_list.size()); break; } else { DEBUG_PRINT1("slice_list.size() == %d\n", slice_list.size()); slice_list.push_back(si); } } return (slice_list.size() > 0); } }
bool CIpInfo::LoadInfoFile(const char* lpszFilePathName) { bool bReturn = false; ifstream hSrcFile(lpszFilePathName,ios_base::binary); if(hSrcFile.is_open()&& !hSrcFile.fail()) { hSrcFile.seekg(0,ios::end); unsigned long dwNumberOfBytesToRead = hSrcFile.tellg();//Get file size hSrcFile.seekg(0,ios::beg); m_pDataBuffer = new unsigned char[dwNumberOfBytesToRead + 1];//would not be failed in win32? memset(m_pDataBuffer,0,dwNumberOfBytesToRead+1); if(m_pDataBuffer != NULL) { hSrcFile.read((char*)m_pDataBuffer,dwNumberOfBytesToRead); unsigned long readBytes = hSrcFile.gcount(); if(readBytes > 0) { //calculate the ip information record count unsigned long *pIntData = (unsigned long *)m_pDataBuffer; unsigned long nBuffer_0 = *pIntData;//Start position of record infor in file unsigned long nBuffer_4 = *(pIntData + 1);//End position of record infor in file first_index_pos = *pIntData; last_index_pos= *(pIntData+1); nBuffer_4 -= nBuffer_0; m_dwRecordCount = nBuffer_4 / 7;//IP record count int nsuiv = nBuffer_4 % 7; if(nsuiv == 0)//must be integral info struct,7 bytes { m_bInit = true; bReturn = m_bInit; } } if(hSrcFile.fail()) { DEBUG_PRINT1("Error Opening File\n"); } if(hSrcFile.bad()) { DEBUG_PRINT1("Error reading File\n"); } while(readBytes < dwNumberOfBytesToRead && hSrcFile.eof()) { hSrcFile.read((char*)(m_pDataBuffer+readBytes),dwNumberOfBytesToRead-readBytes); unsigned long cur_read = hSrcFile.gcount(); readBytes += cur_read; } } hSrcFile.close();//close IP data file } if(!m_bInit) FreeBuffer();//Verify the null buffer if we got some error return bReturn; }
/*************************************************************************** * SteMiniportSetInformation() * * NDIS エントリポイント * OID の値を問い合わせるために NDIS によって呼ばれる。 * * 引数: * * MiniportAdapterContext : Adapter 構造体のポインタ * Oid : この問い合わせの OID * InformationBuffer : 情報のためのバッファー * InformationBufferLength : バッファのサイズ * BytesRead : いくつの情報が読まれたか * BytesNeeded : バッファが少ない場合に必要なサイズを指示 * * 返り値: * * 正常時 : NDIS_STATUS_SUCCESS * *******************************************************************************/ NDIS_STATUS SteMiniportSetInformation( IN NDIS_HANDLE MiniportAdapterContext, IN NDIS_OID Oid, IN PVOID InformationBuffer, IN ULONG InformationBufferLength, OUT PULONG BytesRead, OUT PULONG BytesNeeded) { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; STE_ADAPTER *Adapter; ULONG NewFilter; DEBUG_PRINT0(3, "SteMiniportSetInformation called\n"); Adapter = (STE_ADAPTER *)MiniportAdapterContext; DEBUG_PRINT1(3, "SteMiniportSetInformation: Oid = 0x%x\n", Oid); // 必須 OID のセット要求だけを実装 // TODO: // 今のところ、パケットフィルター以外は実際にはセットしていないので、セットできるようにする。 // switch(Oid) { // 一般的な特性 case OID_GEN_CURRENT_PACKET_FILTER: if(InformationBufferLength != sizeof(ULONG)){ *BytesNeeded = sizeof(ULONG); *BytesRead = 0; Status = NDIS_STATUS_INVALID_LENGTH; break; } NewFilter = *(ULONG *)InformationBuffer; Adapter->PacketFilter = NewFilter; *BytesRead = InformationBufferLength; DEBUG_PRINT1(3,"SteMiniportSetInformation: New filter = 0x%x (See ntddndis.h)\n", NewFilter); break; case OID_GEN_CURRENT_LOOKAHEAD: *BytesRead = InformationBufferLength; break; case OID_GEN_PROTOCOL_OPTIONS: *BytesRead = InformationBufferLength; break; // Ethernet の特性 case OID_802_3_MULTICAST_LIST: *BytesRead = InformationBufferLength; break; default: Status = NDIS_STATUS_INVALID_OID; break; } return(Status); }
static void meet( void) { MUTEX_LOCK(&mutex); while (!(waita && waitb)) { DEBUG_PRINT1("C Waiting"); MUTEX_WAIT(&waitc, &mutex); } DEBUG_PRINT1("C Continuing"); MUTEX_UNLOCK(&mutex); }
static void holda( void) { MUTEX_LOCK(&mutex); waita = 1; DEBUG_PRINT1("A Broadcast C"); MUTEX_BROADCAST(&waitc); while (waita) { DEBUG_PRINT1("A Waiting"); MUTEX_WAIT(&conda, &mutex); } DEBUG_PRINT1("A Continuing"); MUTEX_UNLOCK(&mutex); }
static void holdb( void) { MUTEX_LOCK(&mutex); waitb = 1; DEBUG_PRINT1("B Broadcast C"); MUTEX_BROADCAST(&waitc); while (waitb) { DEBUG_PRINT1("B Waiting"); MUTEX_WAIT(&condb, &mutex); } DEBUG_PRINT1("B Continuing"); MUTEX_UNLOCK(&mutex); }
/***************************************************************************** * DriverEntry() * * この関数のは System がこのドライバをロードするときに呼ばれ、ドライバを * NDIS と関連付け、エントリポイントを登録する。 * * 引数: * DriverObject : ドライバーオブジェクトのポインタ * RegistryPath : ドライバーのレジストリのパス 関連付け * * 返り値: * * NDIS_STATUS * ********************************************************************************/ NDIS_STATUS DriverEntry( IN PVOID DriverObject, IN PVOID RegistryPath) { NDIS_MINIPORT_CHARACTERISTICS MiniportCharacteristics; NDIS_STATUS Status; DEBUG_PRINT0(3, "DriverEntry called\n"); NdisZeroMemory(&MiniportCharacteristics, sizeof(NDIS_MINIPORT_CHARACTERISTICS)); /* * ミニポートドライバを NDIS に関連付けし、NdisWrapperHandle を得る。 */ NdisMInitializeWrapper( &NdisWrapperHandle, // OUT PNDIS_HANDLE DriverObject, // IN ドライバーオブジェクト RegistryPath, // IN レジストリパス NULL // IN 必ず NULL ); if(NdisWrapperHandle == NULL){ DEBUG_PRINT0(1, "NdisInitializeWrapper failed\n"); return(STATUS_INVALID_HANDLE); } MiniportCharacteristics.MajorNdisVersion = STE_NDIS_MAJOR_VERSION; // Major Version MiniportCharacteristics.MinorNdisVersion = STE_NDIS_MINOR_VERSION; // Minor Version MiniportCharacteristics.CheckForHangHandler = SteMiniportCheckForHang; MiniportCharacteristics.HaltHandler = SteMiniportHalt; MiniportCharacteristics.InitializeHandler = SteMiniportInitialize; MiniportCharacteristics.QueryInformationHandler = SteMiniportQueryInformation; MiniportCharacteristics.ResetHandler = SteMiniportReset ; MiniportCharacteristics.SetInformationHandler = SteMiniportSetInformation; MiniportCharacteristics.ReturnPacketHandler = SteMiniportReturnPacket; MiniportCharacteristics.SendPacketsHandler = SteMiniportSendPackets; Status = NdisMRegisterMiniport( NdisWrapperHandle, // IN NDIS_HANDLE &MiniportCharacteristics, // IN PNDIS_MINIPORT_CHARACTERISTICS sizeof(NDIS_MINIPORT_CHARACTERISTICS) // IN UINT ); if( Status != NDIS_STATUS_SUCCESS){ DEBUG_PRINT1(1, "NdisMRegisterMiniport failed(Status = 0x%x)\n", Status); NdisTerminateWrapper( NdisWrapperHandle, // IN NDIS_HANDLE NULL ); return(Status); } // グローバルロックを初期化 NdisAllocateSpinLock(&SteGlobalSpinLock); NdisMRegisterUnloadHandler(NdisWrapperHandle, SteMiniportUnload); return(NDIS_STATUS_SUCCESS); }
/** * Internalize (non-leaving) the contents of the Alarm Server backup * from the backup file. */ TInt CASSrvAlarmStore::Internalize(CASSrvAlarmQueue::TStoreOperation aInternalizeOperation) { TInt error = KErrNone; DEBUG_PRINT1(_L("> Alarm Store Internalize ()")); // tell Alarm Queue what type of Internalize to perform error = ServerWideData().Queue().StartAlarmStoreOperation(aInternalizeOperation); if (!error) { // don't watch for change notifications during Internalize iFlags.Set(EIsInternalizing); TRAP(error, InternalizeL()); // tell alarm queue that Internalize is complete ServerWideData().Queue().EndAlarmStoreOperation(error); // Finished Internalize, Look for notifications again, etc... iFlags.Clear(EIsInternalizing); } DEBUG_PRINT2(_L("< Alarm Store Internalize - error %i"), error); return error; }
/** * Externalize (non-leaving) the contents of the Alarm Server backup * to the backup file. */ TInt CASSrvAlarmStore::Externalize() { TInt error = KErrNone; #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT if (!iServerWideData.ServerIsReadOnly()) { #endif DEBUG_PRINT1(_L("> Alarm Store Externalize")); // tell Alarm Queue what type of Store operation we want to perform error = ServerWideData().Queue().StartAlarmStoreOperation(CASSrvAlarmQueue::EStoreExternalize); if (!error) { TRAP(error, ExternalizeL()); // tell alarm queue that Externalize is complete ServerWideData().Queue().EndAlarmStoreOperation(error); } DEBUG_PRINT2(_L("< Alarm Store Externalize - error %i"), error); #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT } #endif return error; }
/** Recover if RunL() leaves. @see CActive */ TInt CCntLowDiskManager::RunError(TInt /*aError*/) { DEBUG_PRINT1(__VERBOSE_DEBUG__,_L("[CNTMODEL] CCntLowDiskManager::RunError(): RunL() has left!\n")); return (KErrNone); }
uint8 Com_ReceiveSignal(Com_SignalIdType SignalId, void* SignalDataPtr) { const ComSignal_type * Signal; const ComIPdu_type *IPdu; uint8 r = E_OK; const void* pduDataPtr; VALIDATE_SIGNAL(SignalId, 0x0b, E_NOT_OK); DEBUG_PRINT1(DEBUG_LOW, "Com_ReceiveSignal: SignalId %d\r\n", SignalId); Signal = GET_Signal(SignalId); IPdu = GET_IPdu(Signal->ComIPduHandleId); pduDataPtr = 0; if (IPdu->ComIPduSignalProcessing == DEFERRED && IPdu->ComIPduDirection == RECEIVE) { pduDataPtr = IPdu->ComIPduDeferredDataPtr; } else { if (isPduBufferLocked(getPduId(IPdu))) { r = COM_BUSY; } pduDataPtr = IPdu->ComIPduDataPtr; } Com_ReadSignalDataFromPduBuffer( SignalId, FALSE, SignalDataPtr, pduDataPtr); return r; }
bool PieceManager::SliceCompleted(const SliceInfo &slice_info) { StartedPiecesMap::iterator it = m_started_pieces.find(slice_info.piece_idx); if(it == m_started_pieces.end()) return false; DownloadingPiece *pdown = it->second; if(!pdown->RequestCompleted(slice_info)) return false; if(pdown->IsCompleted()) { if(CheckPiece(slice_info.piece_idx)) { t_uint32 pidx = slice_info.piece_idx; assert(m_pieces_info[pidx].state == P_DOWNLOADING); m_pieces_info[pidx].state = P_DONE; t_uint32 pos = m_pos_in_interests[pidx]; assert(pos != NONE_POS); m_pos_in_interests[pidx] = NONE_POS; std::vector<t_uint32> &piece_list = m_interests[m_pieces_info[pidx].have]; assert(!piece_list.empty()); if(pos == piece_list.size() - 1) { piece_list.erase(piece_list.end() - 1); } else { piece_list[pos] = piece_list[piece_list.size() - 1]; m_pos_in_interests[piece_list[pos]] = pos; piece_list.erase(piece_list.end() - 1); } m_bitfield.Set(pidx); //确认此片写入磁盘中(因为此片也许会在cache中) m_storage.FlushPiece(pidx); if(!m_is_endgame && need_enter_endgame()) { m_is_endgame = true; DEBUG_PRINT0("ENTER END GAME MODE!!!!!!!!!!!!!!!\n"); } } else { DEBUG_PRINT1("Piece index == %d hash check failed\n", slice_info.piece_idx); ::MessageBox(0, TEXT("Piece index == hash check failed\n"), 0,0); t_uint32 pidx = slice_info.piece_idx; assert(m_pieces_info[pidx].state == P_DOWNLOADING); m_pieces_info[pidx].state = P_FREE; } m_started_pieces.erase(it); delete pdown; } return true; }
static void trace_flush (void) { char *line; obstack_1grow (&trace, '\0'); line = (char *) obstack_finish (&trace); DEBUG_PRINT1 ("%s\n", line); obstack_free (&trace, line); }
FileImpl::~FileImpl() { try{ Close(); }catch(const std::exception &expt) { DEBUG_PRINT1("Unknow Exception == %s\n", expt.what()); assert(0); } }
static void starta( void) { MUTEX_LOCK(&mutex); { waita = 0; DEBUG_PRINT1("C Broadcast A"); MUTEX_BROADCAST(&conda); } MUTEX_UNLOCK(&mutex); }
static void startb( void) { MUTEX_LOCK(&mutex); { waitb = 0; DEBUG_PRINT1("C Broadcast B"); MUTEX_BROADCAST(&condb); } MUTEX_UNLOCK(&mutex); }
void CASSrvAlarmStore::BackupCompletedL() { // End of Backup DEBUG_PRINT1(_L("-> Alarm Store => Backup Ended")); // Backup server was reading from the alarm file so // tell alarm queue that Backup is complete ServerWideData().Queue().EndAlarmStoreOperation(KErrNone); // In case Store has been waiting for backup to finish. Now // attempt to perform deferred operation. RetryStoreOperation(); }
/** * ドライバクラスメインプロセス * * ロボットの初期化から終了までの処理を行う。 */ void Driver::Process(void){ this->ClearEventFlag(); state_self_introduction(); this->ClearEventFlag(); state_bt_connect(); this->ClearEventFlag(); state_calibration(); this->ClearEventFlag(); this->status_ = STATE_WAIT_START; is_opened_ = true; VectorT<S16> cmd(50,0); while(is_opened_){ switch(status_){ case STATE_WAIT_START: state_wait_start(); break; case STATE_DRIVING: state_driving(); break; case STATE_COMPLETE: DEBUG_PRINT1("s", "STATE_COMPLETE"); is_opened_ = false; break; case STATE_ERROR: DEBUG_PRINT1("s", "STATE_ERROR"); is_opened_ = false; break; default: is_opened_ = false; break; } } }
void CASSrvAlarmStore::RestoreCompletedL(TInt aRestoreResult) { DEBUG_PRINT1(_L("-> Alarm Store => Restore Ended")); // If the Backup server successfully wrote to the alarm file, then we should // read its contents and restore all alarm data based upon it. if (aRestoreResult == KErrNone) { DEBUG_PRINT1(_L("-- End of Restore ... EEnd")); // Any error during Internalize must be pretty severe so catch it and leave. // NB Internalize calls ServerWideData().Queue().EndAlarmStoreOperation(); User::LeaveIfError(Internalize(CASSrvAlarmQueue::EStoreInternalizeRestore)); } else { DEBUG_PRINT1(_L("-- end of Restore ... EAbort")); ServerWideData().Queue().EndAlarmStoreOperation(KErrGeneral); // we don't know what state the AlarmServer.Ini file is in // so want an Externalize() to happen soon ScheduleExternalizeWithRetry(KDelayPeriodBeforeAttemptingAnExternalize); } }
void TreeIterator::Next() { if(m_curr.GetPathType() == PATH_ROOT || m_curr.GetPathType() == PATH_DIR) { std::wstring path; bool res = m_curr.GetPath(path); assert(res); try{ DirectoryIterator dir_iter(path); std::string name; for(dir_iter.First(); !dir_iter.IsDone(); dir_iter.Next()) { name.clear(); const Path &ref_path = dir_iter.Current(); res = ref_path.GetName(name); assert(res); if((name != ".") && (name != "..")) { m_queue.push(ref_path); } } }catch(const ExceptionSpace::FileException &expt) { DEBUG_PRINT1("UnKnow exception == %s\n", expt.what()); if(!m_ignore_error) { throw; } } } if(!m_queue.empty()) { m_curr = m_queue.front(); m_queue.pop(); }else { m_curr.Reset(""); } }
//************************************************************************************* void CASSrvAlarmStore::ConstructL() { CTimer::ConstructL(); DEBUG_PRINT1(_L("++ ++ Alarm Store ConstructL")); TFileName name; RFs& fsSession = ServerWideData().FsSession(); ASSrvStaticUtils::GetPrivateDirL(fsSession, name); //Check INI file directory exists TUint attribs; //Not used dummy parameter TInt error = fsSession.Att(name,attribs); if (error == KErrNotFound || error == KErrPathNotFound) { error = fsSession.MkDirAll(name); } User::LeaveIfError(error); ASSrvStaticUtils::GetServerPathL(fsSession, name); #ifndef __WINC__ iBackupNotification = CBackupRestoreNotification::NewL(name, *this); #endif // Internalize any previously persisted data error = Internalize(CASSrvAlarmQueue::EStoreInternalizeStartup); if (error != KErrNone) { error = fsSession.Delete(name); if (error != KErrNotFound) User::LeaveIfError(error); } // Ready to watch for "Alarm Added" and other Alarm Queue events ServerWideData().Queue().NotificationPoolChangeL(*this); // Ready to watch for Alarm Sound Intervals changing ServerWideData().AnyEventManager().MASAnyEventManagerObserverAddL(*this); }
//************************************************************************************* CASSrvAlarmStore::~CASSrvAlarmStore() { #ifndef __WINC__ delete iBackupNotification; #endif ServerWideData().Queue().NotificationPoolChangeCancel(*this); DEBUG_PRINT1(_L("-- -- Alarm Store destructor")); // is an externalize request still waiting? if (iFlags.IsSet(ERequestExternalize)) { Cancel(); // Flush current alarm queue // (if this fails now there is nothing we can do about it) Externalize(); } // no longer interested in these events ServerWideData().AnyEventManager().MASAnyEventManagerObserverRemove(*this); }
/************************************************************************* * SteMiniportinitialize() * * NDIS エントリポイント * ネットワーク I/O 操作のために NIC ドライバがネットワーク I/O 操作を * するために必要なリソースを確保する。 * * 引数: * * OpenErrorStatus OUT PNDIS_STATUS * SelectedMediumIndex OUT PUINT * MediumArray IN PNDIS_MEDIUM * MediumArraySize IN UINT * MiniportAdapterHandle IN NDIS_HANDLE * WrapperConfigurationContext IN NDIS_HANDLE * * 返り値: * * 正常時: NDIS_STATUS_SUCCESS * *************************************************************************/ NDIS_STATUS SteMiniportInitialize( OUT PNDIS_STATUS OpenErrorStatus, OUT PUINT SelectedMediumIndex, IN PNDIS_MEDIUM MediumArray, IN UINT MediumArraySize, IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_HANDLE WrapperConfigurationContext ) { UINT i; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; STE_ADAPTER *Adapter = NULL; BOOLEAN MediaFound = FALSE; DEBUG_PRINT0(3, "SteMiniportInitialize called\n"); *SelectedMediumIndex = 0; for ( i = 0 ; i < MediumArraySize ; i++){ if (MediumArray[i] == NdisMedium802_3){ *SelectedMediumIndex = i; MediaFound = TRUE; break; } } // 途中で break するためだけの Do-While 文 do { if(!MediaFound){ // 上記の for 文で見つけられなかったようだ DEBUG_PRINT0(1, "SteMiniportInitialize: No Media much\n"); Status = NDIS_STATUS_UNSUPPORTED_MEDIA; break; } // // Adapter を確保し、初期化する // if ((Status = SteCreateAdapter(&Adapter)) != NDIS_STATUS_SUCCESS){ DEBUG_PRINT0(1, "SteMiniportInitialize: Can't allocate memory for STE_ADAPTER\n"); Status = NDIS_STATUS_RESOURCES; break; } DEBUG_PRINT1(3, "SteMiniportInitialize: Adapter = 0x%p\n", Adapter); Adapter->MiniportAdapterHandle = MiniportAdapterHandle; // // Registory を読む処理。...省略。 // NdisOpenConfiguration(); // NdisReadConfiguration(); // // NIC のためのハードウェアリソースのリストを得る。...省略。 // NdisMQueryAdapterResources() // // // NDIS に NIC の情報を伝える。 // かならず NdisXxx 関数を呼び出すより前に、以下の NdisMSetAttributesEx // を呼び出さなければならない。 // NdisMSetAttributesEx( MiniportAdapterHandle, //IN NDIS_HANDLE (NDIS_HANDLE) Adapter, //IN NDIS_HANDLE 0, //IN UINT NDIS_ATTRIBUTE_DESERIALIZE, //IN ULONG Deserialized ミニポートドライバ NdisInterfaceInternal //IN NDIS_INTERFACE_TYPE ); // // NDIS 5.0 の場合はかならず SHUTDOWN_HANDLER を登録しなければならない。 // NdisMRegisterAdapterShutdownHandler( MiniportAdapterHandle, // IN NDIS_HANDLE (PVOID) Adapter, // IN PVOID (ADAPTER_SHUTDOWN_HANDLER) SteMiniportShutdown // IN ADAPTER_SHUTDOWN_HANDLER ); // // 仮想 NIC デーモンからの IOCT/ReadFile/WriteFile 用の // デバイスを作成し、Dispatch ルーチンを登録する。 // SteRegisterDevice(Adapter); // // SteRecvTimerFunc() を呼ぶためのタイマーオブジェクトを初期化 // NdisInitializeTimer( &Adapter->RecvTimer, //IN OUT PNDIS_TIMER SteRecvTimerFunc, //IN PNDIS_TIMER_FUNCTION (PVOID)Adapter //IN PVOID ); // // SteResetTimerFunc() を呼ぶためのタイマーオブジェクトを初期化 // NdisInitializeTimer( &Adapter->ResetTimer, //IN OUT PNDIS_TIMER SteResetTimerFunc, //IN PNDIS_TIMER_FUNCTION (PVOID)Adapter //IN PVOID ); } while (FALSE); return(Status); }
void CASSrvAlarmStore::BackupBeginningL() { DEBUG_PRINT1(_L("-> Alarm Store => Backup Beginning")); StartOfBackupOrRestoreL(CASSrvAlarmQueue::EStoreBackup); }
/************************************************************************ * SteMiniportQueryInformation() * * NDIS エントリポイント * OID の値を問い合わせるために NDIS によって呼ばれる。 * * 引数: * * MiniportAdapterContext : STE_ADAPTER 構造体のポインタ * Oid : この問い合わせの OID * InformationBuffer : 情報のためのバッファー * InformationBufferLength : バッファのサイズ * BytesWritten : いくつの情報が記述されたか * BytesNeeded : バッファが少ない場合に必要なサイズを指示 * * 返り値: * * 正常時 : NDIS_STATUS_SUCCESS * ************************************************************************/ NDIS_STATUS SteMiniportQueryInformation( IN NDIS_HANDLE MiniportAdapterContext, IN NDIS_OID Oid, IN PVOID InformationBuffer, IN ULONG InformationBufferLength, OUT PULONG BytesWritten, OUT PULONG BytesNeeded ) { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; STE_ADAPTER *Adapter; PVOID Information = NULL; // 提供する情報へのポインタ ULONG InformationLength = 0; // 提供する情報の長さ ULONG ulTemp; // 整数値の情報のための領域(マクロ内で利用) CHAR VendorName[] = STE_VENDOR_NAME; // ベンダー名 // あまりに冗長なので、必要なデバッグレベルを上げる DEBUG_PRINT0(4, "SteMiniportQueryInformation called\n"); Adapter = (STE_ADAPTER *)MiniportAdapterContext; DEBUG_PRINT1(4, "SteMiniportQueryInformation: Oid = 0x%x\n", Oid); switch(Oid) { // 一般的な特性 (22個) case OID_GEN_SUPPORTED_LIST: //サポートされる OID のリスト SET_INFORMATION_BY_POINTER(sizeof(STESupportedList), &STESupportedList); case OID_GEN_HARDWARE_STATUS: // ハードウェアステータス SET_INFORMATION_BY_VALUE(sizeof(NDIS_HARDWARE_STATUS), NdisHardwareStatusReady); case OID_GEN_MEDIA_SUPPORTED: // NIC がサポートできる(が必須ではない)メディアタイプ case OID_GEN_MEDIA_IN_USE: // NIC が現在使っている完全なメディアタイプのリスト SET_INFORMATION_BY_VALUE(sizeof(NDIS_MEDIUM), NdisMedium802_3); case OID_GEN_MAXIMUM_LOOKAHEAD: // NIC が lookahead データとして提供できる最大バイト数 case OID_GEN_MAXIMUM_FRAME_SIZE: // NIC がサポートする、ヘッダを抜いたネットワークパケットサイズ SET_INFORMATION_BY_VALUE(sizeof(ULONG), ETHERMTU); case OID_GEN_LINK_SPEED: //NIC がサポートする最大スピード SET_INFORMATION_BY_VALUE(sizeof(ULONG), ETHERLINKSPEED); case OID_GEN_TRANSMIT_BUFFER_SPACE: // NIC 上の送信用のメモリの総量 // TODO: これでいいのか? SET_INFORMATION_BY_VALUE(sizeof(ULONG), ETHERMTU); case OID_GEN_RECEIVE_BUFFER_SPACE: // NIC 上の受信用のメモリの総量 // TODO: これでいいのか? SET_INFORMATION_BY_VALUE(sizeof(ULONG), ETHERMTU); case OID_GEN_TRANSMIT_BLOCK_SIZE: // NIC がサポートする送信用のネットワークパケットサイズ SET_INFORMATION_BY_VALUE(sizeof(ULONG), ETHERMAX); case OID_GEN_RECEIVE_BLOCK_SIZE: // NIC がサポートする受信用のネットワークパケットサイズ SET_INFORMATION_BY_VALUE(sizeof(ULONG), ETHERMAX); case OID_GEN_VENDOR_ID: // IEEE に登録してあるベンダーコード SET_INFORMATION_BY_VALUE(sizeof(ULONG), 0xFFFFFF); case OID_GEN_VENDOR_DESCRIPTION: // NIC のベンダー名 SET_INFORMATION_BY_POINTER(sizeof(VendorName), VendorName); case OID_GEN_VENDOR_DRIVER_VERSION: // ドライバーのバージョン SET_INFORMATION_BY_VALUE(sizeof(ULONG), STE_DRIVER_VERSION); case OID_GEN_CURRENT_PACKET_FILTER: // プロトコルが NIC から受け取るパケットのタイプ SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->PacketFilter); case OID_GEN_CURRENT_LOOKAHEAD: // 現在の lookahead のバイト数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), ETHERMTU); case OID_GEN_DRIVER_VERSION: // NDIS のバージョン SET_INFORMATION_BY_VALUE(sizeof(USHORT), STE_NDIS_VERSION); case OID_GEN_MAXIMUM_TOTAL_SIZE: // NIC がサポートするネットワークパケットサイズ SET_INFORMATION_BY_VALUE(sizeof(ULONG), ETHERMAX); // case OID_GEN_PROTOCOL_OPTIONS: // オプションのプロトコルフラグ。Set のみ必須 case OID_GEN_MAC_OPTIONS: // 追加の NIC のプロパティを定義したビットマスク SET_INFORMATION_BY_VALUE(sizeof(ULONG), NDIS_MAC_OPTION_NO_LOOPBACK | NDIS_MAC_OPTION_TRANSFERS_NOT_PEND | NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA); case OID_GEN_MEDIA_CONNECT_STATUS: // NIC 上の connection 状態 // TODO: 状態を確認し、NdisMediaStateDisconnected を返すようにする SET_INFORMATION_BY_VALUE(sizeof(ULONG), NdisMediaStateConnected); case OID_GEN_MAXIMUM_SEND_PACKETS: // 一回のリクエストで受けられるパケットの最大数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), STE_MAX_SEND_PACKETS); // 一般的な統計情報 (5個) case OID_GEN_XMIT_OK: // 正常に送信できたフレーム数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->Opackets); case OID_GEN_RCV_OK: // 正常に受信できたフレーム数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->Ipackets); case OID_GEN_XMIT_ERROR: // 送信できなかった(もしくはエラーになった)フレーム数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->Oerrors); case OID_GEN_RCV_ERROR: // 受信できなかった(もしくはエラーになった)フレーム数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->Ierrors); case OID_GEN_RCV_NO_BUFFER: // バッファ不足のために受信できなかったフレーム数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->NoResources); // Ethernet 用の特性 (4個) case OID_802_3_PERMANENT_ADDRESS: // ハードウェアに書かれている MAC アドレス case OID_802_3_CURRENT_ADDRESS: // NIC の現在の MAC アドレス SET_INFORMATION_BY_POINTER(ETHERADDRL, Adapter->EthernetAddress); case OID_802_3_MULTICAST_LIST: // 現在のマルチキャストパケットのアドレスリスト // TODO: マルチキャストリストをセットする。 // 今のところ 0 を返す SET_INFORMATION_BY_VALUE(ETHERADDRL, 0); case OID_802_3_MAXIMUM_LIST_SIZE: // NIC ドライバが管理できる最大のマルチキャストアドレスの数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), STE_MAX_MCAST_LIST); // Ethernet 用統計情報 (3個) case OID_802_3_RCV_ERROR_ALIGNMENT: // アライメントエラーの受信フレーム数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->AlignErrors); case OID_802_3_XMIT_ONE_COLLISION: // コリジョンが 1 回発生した送信フレーム数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->OneCollisions); case OID_802_3_XMIT_MORE_COLLISIONS: // コリジョンが 1 回以上発生した送信フレーム数 SET_INFORMATION_BY_VALUE(sizeof(ULONG), Adapter->Collisions); default: Status = NDIS_STATUS_NOT_SUPPORTED; break; } if(Information != NULL) { NdisMoveMemory(InformationBuffer, Information, InformationLength); *BytesWritten = InformationLength; } else if(InformationLength > 0) { // バッファが小さい場合は、必要なサイズを通知する。 *BytesNeeded = InformationLength; Status = NDIS_STATUS_BUFFER_TOO_SHORT; } return(Status); }
void CASSrvAlarmStore::RestoreBeginningL() { // Restore is starting DEBUG_PRINT1(_L("-> Alarm Store => Restore Beginning")); StartOfBackupOrRestoreL(CASSrvAlarmQueue::EStoreRestore); }
/* * This function is called by the handleConnection() function in * rwtransfer.c once the connection has been established. This * function returns -1 on error, 0 if no files were transferred, or * 1 if one or more files were successfully received. */ int transferFiles( sk_msg_queue_t *q, skm_channel_t channel, transfer_t *sndr) { static pthread_mutex_t open_file_mutex = PTHREAD_MUTEX_INITIALIZER; int fd = -1; uint64_t size = 0; uint64_t pa_size = 0; uint8_t *map = NULL; char *name = NULL; char *dotname = NULL; char dotpath[PATH_MAX]; char destpath[sizeof(dotpath)-1]; struct stat st; ino_t *inode; int proto_err; int rv; sk_dll_iter_t iter; const char *duplicate_dir; enum transfer_state {File_info, File_info_ack, Send_file, Complete_ack, Error} state; int thread_exit; int transferred_file = 0; state = File_info; proto_err = 0; thread_exit = 0; destpath[0] = '\0'; dotpath[0] = '\0'; memset(&st, 0, sizeof(st)); while (!shuttingdown && !proto_err && !thread_exit && !sndr->disconnect && (state != Error)) { sk_msg_t *msg; /* Handle reads */ switch (state) { case File_info: case Send_file: rv = skMsgQueueGetMessage(q, &msg); if (rv == -1) { ASSERT_ABORT(shuttingdown); continue; } if (handleDisconnect(msg, sndr->ident)) { state = Error; } break; case Error: ASSERT_ABORT(0); break; default: msg = NULL; } /* Handle all states */ switch (state) { case File_info: /* Create the placeholder and dot files and mmap() the * space. */ { file_info_t *finfo; uint32_t len; mode_t mode; off_t offrv; if ((proto_err = checkMsg(msg, q, CONN_NEW_FILE))) { break; } DEBUG_PRINT1("Received CONN_NEW_FILE"); finfo = (file_info_t *)skMsgMessage(msg); size = (uint64_t)ntohl(finfo->high_filesize) << 32 | ntohl(finfo->low_filesize); pa_size = size; /* blocksize = ntohl(finfo->block_size); --- UNUSED */ mode = ntohl(finfo->mode) & 0777; len = skMsgLength(msg) - offsetof(file_info_t, filename); dotname = (char *)calloc(1, len + 1); CHECK_ALLOC(dotname); name = dotname + 1; dotname[0] = '.'; memcpy(name, finfo->filename, len); if (!memchr(name, '\0', len)) { sendString(q, channel, EXTERNAL, SEND_CONN_REJECT(sndr), LOG_WARNING, "Illegal filename (from %s)", sndr->ident); state = FILE_INFO_ERROR_STATE(sndr); break; } INFOMSG("Receiving from %s: '%s' (%" PRIu64 " bytes)", sndr->ident, name, size); /* Check filesystem for enough space for file */ if (CHECK_DISK_SPACE(pa_size)) { WARNINGMSG(("Not enough space on filesystem for %" PRIu64 " byte file '%s'"), pa_size, name); pa_size = 0; state = FILESYSTEM_FULL_ERROR_STATE(sndr); break; } /* Create the placeholder file */ rv = snprintf(destpath, sizeof(destpath), "%s/%s", destination_dir, name); if ((size_t)rv >= sizeof(destpath)) { sendString(q, channel, EXTERNAL, SEND_CONN_REJECT(sndr), LOG_WARNING, "Filename too long (from %s)", sndr->ident); state = FILE_INFO_ERROR_STATE(sndr); destpath[0] = '\0'; break; } assert((size_t)rv < sizeof(destpath)); pthread_mutex_lock(&open_file_mutex); reopen: fd = open(destpath, O_CREAT | O_EXCL | O_WRONLY, 0); if (fd == -1) { if (errno != EEXIST) { CRITMSG("Could not create '%s': %s", destpath, strerror(errno)); thread_exit = 1; pthread_mutex_unlock(&open_file_mutex); break; } if (stat(destpath, &st) == -1) { WARNINGMSG("Unable to stat '%s': %s", destpath, strerror(errno)); } else if (S_ISREG(st.st_mode) && ((st.st_mode & 0777) == 0) && ((st.st_size == 0))) { /* looks like a placeholder file. are we * receiving a file with the same name from a * different rwsender? */ int found = 0; skDLLAssignIter(&iter, open_file_list); while (skDLLIterForward(&iter, (void **)&inode) == 0) { if (st.st_ino == *inode) { WARNINGMSG(("Multiple rwsenders attempting" " to send file '%s'"), name); found = 1; break; } } if (!found) { WARNINGMSG(("Filename already exists (from a" " previous run?). Removing '%s'"), destpath); if (unlink(destpath) == 0) { goto reopen; } WARNINGMSG("Failed to unlink '%s': %s", destpath, strerror(errno)); /* treat file as a duplicate */ } } /* else file is a duplicate */ st.st_ino = 0; destpath[0] = dotpath[0] = '\0'; sendString(q, channel, EXTERNAL, SEND_CONN_DUPLICATE(sndr), LOG_WARNING, "Filename already exists (from %s)", sndr->ident); state = FILE_INFO_ERROR_STATE(sndr); pthread_mutex_unlock(&open_file_mutex); break; } /* else, successfully opened placeholder file */ if (fstat(fd, &st) == -1) { CRITMSG("Could not fstat newly created file '%s': %s", destpath, strerror(errno)); st.st_ino = 0; thread_exit = 1; pthread_mutex_unlock(&open_file_mutex); break; } if (skDLListPushTail(open_file_list, &st.st_ino)) { CRITMSG("Unable to grow open file list"); st.st_ino = 0; thread_exit = 1; pthread_mutex_unlock(&open_file_mutex); break; } pthread_mutex_unlock(&open_file_mutex); DEBUGMSG("Created '%s'", destpath); rv = close(fd); fd = -1; if (rv == -1) { CRITMSG("Could not close file '%s': %s", destpath, strerror(errno)); thread_exit = 1; break; } /* Create the dotfile */ rv = snprintf(dotpath, sizeof(dotpath), "%s/%s", destination_dir, dotname); reopen2: fd = open(dotpath, O_RDWR | O_CREAT | O_EXCL, mode); if (fd == -1) { int saveerrno = errno; if (errno == EEXIST) { WARNINGMSG("Filename already exists. Removing '%s'", dotpath); if (unlink(dotpath) == 0) { goto reopen2; } WARNINGMSG("Failed to unlink '%s': %s", dotpath, strerror(errno)); } CRITMSG("Could not create '%s': %s", dotpath, strerror(saveerrno)); thread_exit = 1; dotpath[0] = '\0'; break; } DEBUGMSG("Created '%s'", dotpath); /* Allocate space on disk */ offrv = lseek(fd, size - 1, SEEK_SET); if (offrv == -1) { CRITMSG("Could not allocate disk space for '%s': %s", dotpath, strerror(errno)); thread_exit = 1; break; } rv = write(fd, "", 1); if (rv == -1) { CRITMSG("Could not allocate disk space for '%s': %s", dotpath, strerror(errno)); thread_exit = 1; break; } /* Map space */ map = (uint8_t *)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if ((void *)map == MAP_FAILED) { CRITMSG("Could not map '%s': %s", dotpath, strerror(errno)); thread_exit = 1; break; } rv = close(fd); fd = -1; if (rv == -1) { CRITMSG("Could not close file '%s': %s", dotpath, strerror(errno)); thread_exit = 1; break; } GOT_DISK_SPACE(pa_size); pa_size = 0; state = File_info_ack; } break; case File_info_ack: DEBUG_PRINT1("Sending CONN_NEW_FILE_READY"); proto_err = skMsgQueueSendMessage(q, channel, CONN_NEW_FILE_READY, NULL, 0); state = Send_file; break; case Send_file: /* Get the content of the file and write into the dot file */ { block_info_t *block; uint64_t offset; uint32_t len; if (skMsgType(msg) != CONN_FILE_BLOCK) { if ((proto_err = checkMsg(msg, q, CONN_FILE_COMPLETE))) { break; } DEBUG_PRINT1("Received CONN_FILE_COMPLETE"); state = Complete_ack; break; } block = (block_info_t *)skMsgMessage(msg); len = skMsgLength(msg) - offsetof(block_info_t, block); offset = (uint64_t)ntohl(block->high_offset) << 32 | ntohl(block->low_offset); DEBUG_CONTENT_PRINT("Receiving offset=%" PRIu64 " len=%" PRIu32, offset, len); if (offset + len > size) { sendString(q, channel, EXTERNAL, CONN_DISCONNECT, LOG_WARNING, ("Illegal block (offset/size %" PRIu64 "/%" PRIu32 ")"), offset, len); state = Error; break; } memcpy(map + offset, block->block, len); } break; case Complete_ack: /* Un-mmap() the file, create any duplicate files, and * move the dotfile over the placeholder file */ rv = munmap(map, size); map = NULL; if (rv == -1) { CRITMSG("Could not unmap file '%s': %s", dotpath, strerror(errno)); thread_exit = 1; break; } /* Handle duplicate-destinations. Any errors here are * simply logged and processing continues. */ skDLLAssignIter(&iter, duplicate_dirs); while (skDLLIterForward(&iter, (void **)&duplicate_dir) == 0) { char path[sizeof(destpath)]; snprintf(path, sizeof(path), "%s/%s", duplicate_dir, name); if (unique_duplicates) { rv = skCopyFile(dotpath, path); if (rv != 0) { WARNINGMSG("Could not copy '%s' to '%s': %s", dotpath, path, strerror(rv)); } } else { DEBUGMSG("Linking '%s' as '%s'", dotpath, path); rv = link(dotpath, path); if (EXDEV == errno) { DEBUGMSG("Link failed EXDEV; copying '%s' to '%s'", dotpath, path); rv = skCopyFile(dotpath, path); if (rv != 0) { WARNINGMSG("Could not copy '%s' to '%s': %s", dotpath, path, strerror(rv)); } } else if (rv != 0) { WARNINGMSG("Could not link '%s' as '%s': %s", dotpath, path, strerror(errno)); } } } DEBUGMSG("Renaming '%s' to '%s'", dotpath, destpath); rv = rename(dotpath, destpath); if (rv != 0) { CRITMSG("Failed rename of '%s' to '%s': %s", dotpath, destpath, strerror(errno)); thread_exit = 1; break; } /* remove the file from the open_file_list */ pthread_mutex_lock(&open_file_mutex); skDLLAssignIter(&iter, open_file_list); while (skDLLIterForward(&iter, (void **)&inode) == 0) { if (st.st_ino == *inode) { skDLLIterDel(&iter); break; } } st.st_ino = 0; pthread_mutex_unlock(&open_file_mutex); DEBUG_PRINT1("Sending CONN_FILE_COMPLETE"); proto_err = skMsgQueueSendMessage(q, channel, CONN_FILE_COMPLETE, NULL, 0); if (proto_err == 0) { /* Run the post command on the file */ if (post_command) { runPostCommand(post_command, destpath, sndr->ident); } destpath[0] = '\0'; INFOMSG("Finished receiving from %s: '%s'", sndr->ident, name); free(dotname); dotname = NULL; } destpath[0] = dotpath[0] = '\0'; transferred_file = 1; state = File_info; break; case Error: break; } if (msg != NULL) { skMsgDestroy(msg); } } if (fd != -1) { close(fd); } if (map != NULL) { munmap(map, size); } if (dotname != NULL) { free(dotname); } if (dotpath[0] != '\0') { DEBUGMSG("Removing '%s'", dotpath); unlink(dotpath); } if (destpath[0] != '\0') { DEBUGMSG("Removing '%s'", destpath); unlink(destpath); } if (st.st_ino != 0) { skDLLAssignIter(&iter, open_file_list); while (skDLLIterForward(&iter, (void **)&inode) == 0) { if (st.st_ino == *inode) { skDLLIterDel(&iter); break; } } } if (pa_size) { GOT_DISK_SPACE(pa_size); } if (thread_exit) { return -1; } return transferred_file; }
static int XRotDrawHorizontalString(Display* dpy, XFontStruct* font, Drawable drawable, GC gc, int x, int y, char* text, int align, int bg) { GC my_gc; int nl=1, i; int height; int xp, yp; char *str1, *str2, *str3; char *str2_a="\0", *str2_b="\n\0"; int dir, asc, desc; XCharStruct overall; DEBUG_PRINT1("**\nHorizontal text.\n"); /* this gc has similar properties to the user's gc (including stipple) */ my_gc=XCreateGC(dpy, drawable, 0, 0); XCopyGC(dpy, gc, GCForeground|GCBackground|GCFunction|GCStipple|GCFillStyle| GCTileStipXOrigin|GCTileStipYOrigin|GCPlaneMask, my_gc); XSetFont(dpy, my_gc, font->fid); /* count number of sections in string */ if(align!=NONE) for(i=0; i<strlen(text)-1; i++) if(text[i]=='\n') nl++; /* ignore newline characters if not doing alignment */ if(align==NONE) str2=str2_a; else str2=str2_b; /* overall font height */ height=font->ascent+font->descent; /* y position */ if(align==TLEFT || align==TCENTRE || align==TRIGHT) yp=y+font->ascent; else if(align==MLEFT || align==MCENTRE || align==MRIGHT) yp=y-nl*height/2+font->ascent; else if(align==BLEFT || align==BCENTRE || align==BRIGHT) yp=y-nl*height+font->ascent; else yp=y; str1=my_strdup(text); if(str1==NULL) return 1; str3=my_strtok(str1, str2); /* loop through each section in the string */ do { XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc, &overall); /* where to draw section in x ? */ if(align==TLEFT || align==MLEFT || align==BLEFT || align==NONE) xp=x; else if(align==TCENTRE || align==MCENTRE || align==BCENTRE) xp=x-overall.rbearing/2; else xp=x-overall.rbearing; /* draw string onto bitmap */ if(!bg) XDrawString(dpy, drawable, my_gc, xp, yp, str3, strlen(str3)); else XDrawImageString(dpy, drawable, my_gc, xp, yp, str3, strlen(str3)); /* move to next line */ yp+=height; str3=my_strtok((char *)NULL, str2); } while(str3!=NULL); free(str1); XFreeGC(dpy, my_gc); return 0; }