void CMediaMonitor::Scan(DIRECTORY::IDirectory& directory, CStdString& aPath, MOVIELIST& movies) { // dispatch any pending commands first before scanning this directory! DispatchNextCommand(); CFileItemList items; if (!directory.GetDirectory(aPath, items)) { return ; } for (int i = 0; i < (int)items.Size(); ++i) { CFileItem* pItem = items[i]; if (pItem->m_bIsFolder) { Scan(directory, pItem->m_strPath, movies); } else { char* szFilename = (char*) pItem->GetLabel().c_str(); char* szExtension = strrchr(szFilename, '.'); char* szExpected = szFilename + (strlen(szFilename) - 4); // ensure file has a 3 letter extension that isn't .nfo if ((szExtension != NULL) && (szExpected == szExtension) && (strcmp(szExtension, ".nfo") != 0) ) { Movie aMovie; aMovie.strFilepath = pItem->m_strPath; aMovie.dwDate = (( (pItem->m_dateTime.GetYear()) << 16 ) | ( (pItem->m_dateTime.GetMonth() & 0x00FF) << 8 ) | (pItem->m_dateTime.GetDay() & 0x00FF) ); aMovie.wTime = (( (pItem->m_dateTime.GetHour() & 0x00FF) << 8 ) | (pItem->m_dateTime.GetMinute() & 0x00FF) ); movies.push_back(aMovie); //OutputDebugString(pItem->GetLabel().c_str()); //OutputDebugString("\n"); } } } }
void CMediaMonitor::Process() { InitializeObserver(); CMediaMonitor::Command command; command.rCommand = CMediaMonitor::CommandType::Refresh; QueueCommand(command); while (!m_bStop) { switch ( WaitForSingleObject(m_hCommand, INFINITE) ) { case WAIT_OBJECT_0: m_bBusy = true; DispatchNextCommand(); m_bBusy = false; break; } } }
void CUdpClient::Process() { Sleep(2000); CLog::Log(UDPCLIENT_DEBUG_LEVEL, "UDPCLIENT: Listening."); SOCKADDR_IN remoteAddress; char messageBuffer[1024]; DWORD dataAvailable; while ( !m_bStop ) { fd_set readset, exceptset; FD_ZERO(&readset); FD_SET(client_socket, &readset); FD_ZERO(&exceptset); FD_SET(client_socket, &exceptset); int nfds = (int)(client_socket); timeval tv = { 0, 100000 }; if (select(nfds, &readset, NULL, &exceptset, &tv) < 0) { CLog::Log(LOGERROR, "UDPCLIENT: failed to select on socket"); break; } // is there any data to read dataAvailable = 0; ioctlsocket(client_socket, FIONREAD, &dataAvailable); // while there is data to read while (dataAvailable > 0) { // read data int messageLength = sizeof(messageBuffer) - 1 ; #ifndef _LINUX int remoteAddressSize; #else socklen_t remoteAddressSize; #endif remoteAddressSize = sizeof(remoteAddress); int ret = recvfrom(client_socket, messageBuffer, messageLength, 0, (struct sockaddr *) & remoteAddress, &remoteAddressSize); if (ret != SOCKET_ERROR) { // Packet received messageLength = ret; messageBuffer[messageLength] = '\0'; CStdString message = messageBuffer; CLog::Log(UDPCLIENT_DEBUG_LEVEL, "UDPCLIENT RX: %u\t\t<- '%s'", XbmcThreads::SystemClockMillis(), message.c_str() ); // NOTE: You should consider locking access to the screen device // or at least wait until after vertical refresh before firing off events // to protect access to graphics resources. g_graphicsContext.Lock(); OnMessage(remoteAddress, message, (LPBYTE)messageBuffer, messageLength); g_graphicsContext.Unlock(); } else { CLog::Log(UDPCLIENT_DEBUG_LEVEL, "UDPCLIENT: Socket error %u", WSAGetLastError()); } // is there any more data to read? dataAvailable = 0; ioctlsocket(client_socket, FIONREAD, &dataAvailable); } // dispatch a single command if any pending while(DispatchNextCommand()) {} } closesocket(client_socket); CLog::Log(UDPCLIENT_DEBUG_LEVEL, "UDPCLIENT: Stopped listening."); }