void msg_flw(int connfd, std::vector<std::string> &tokens){ std::cout << "msg_flw execute\n"; std::unique_lock<std::mutex> lck(file2); std::unique_lock<std::mutex> lck2(file3); std::ifstream ifs(get_path(file_id[3])); std::vector<std::string> flwing; std::string line, username = tokens[1], retval = ""; if(ifs.is_open()){ while(getline(ifs, line)){ std::istringstream iss2(line); std::vector<std::string> temp{std::istream_iterator<std::string>{iss2}, std::istream_iterator<std::string>{}}; if(temp[0] == username){ for(int i = 1; i < temp.size(); i++){ flwing.push_back(temp[i]); } } } ifs.close(); } ifs.open(get_path(file_id[2])); if(ifs.is_open()){ while(getline(ifs, line)){ std::istringstream iss2(line); std::vector<std::string> temp{std::istream_iterator<std::string>{iss2}, std::istream_iterator<std::string>{}}; for(int i = 0; i < flwing.size(); i++){ if(flwing[i] == temp[0]){ retval += (line + "\n"); } } } write(connfd, retval.c_str(), retval.size()); ifs.close(); } }
void bkp_follow(std::vector<std::string> &tokens){ std::cout << "backup follow execute\n"; std::unique_lock<std::mutex> lck(file3); std::unique_lock<std::mutex> lck2(file4); std::ifstream ifs(get_path(file_id[3])); std::string line, username = tokens[1], newf = tokens[2]; std::vector<std::string> flwing; bool found = false, valid = true; std::ofstream output; std::string temp_file = get_path(file_id[4]); if(ifs.is_open()){ output.open(temp_file); while(getline(ifs, line) && valid){ std::istringstream iss2(line); std::vector<std::string> temp{std::istream_iterator<std::string>{iss2}, std::istream_iterator<std::string>{}}; if(temp[0] == username){ found = true; for(int i = 1; i < temp.size(); i++){ flwing.push_back(temp[i]); if(newf == temp[i]){ std::cout << "cond 1\n"; valid = false; break; } } }else{ output << line << "\n"; } } ifs.close(); output.close(); } if(!found){ std::cout << "cond 2\n"; std::ofstream output2(get_path(file_id[3]), std::ios::app); std::string retval = username + " " + newf; output2 << "\n" << retval; output2.close(); } if(valid && found){ std::cout << "cond 3\n"; output.open(get_path(file_id[3])); ifs.open(temp_file); while(getline(ifs, line)){ output << line << "\n"; } std::string retval = username + " "; for(int i = 0; i < flwing.size(); i++){ retval += flwing[i]; retval += " "; } retval += newf; output << retval; output.close(); ifs.close(); } }
STDMETHODIMP CudaDecodeFilter::Pause() { CAutoLock lck(&m_cStateLock); HRESULT hr = NOERROR; if (m_State == State_Paused) { // (This space left deliberately blank) } // If we have no input pin or it isn't yet connected then when we are // asked to pause we deliver an end of stream to the downstream filter. // This makes sure that it doesn't sit there forever waiting for // samples which we cannot ever deliver without an input connection. else if (m_CudaDecodeInputPin == NULL || m_CudaDecodeInputPin->IsConnected() == FALSE) { if(m_paStreams[0]->IsConnected() && m_EOSDelivered == FALSE) { m_paStreams[0]->DeliverEndOfStream(); m_EOSDelivered = TRUE; } m_State = State_Paused; } // We may have an input connection but no output connection // However, if we have an input pin we do have an output pin else if (m_paStreams[0]->IsConnected() == FALSE) { m_State = State_Paused; } else { if (m_State == State_Stopped) { // allow a class derived from CTransformFilter // to know about starting and stopping streaming CAutoLock lck2(&m_csReceive); hr = StartStreaming(); } if (SUCCEEDED(hr)) { // Make sure the receive not blocking // Make sure the out-sending thread not working m_MediaController->FlushAllPending(); hr = CBaseFilter::Pause(); } } return hr; }
STDMETHODIMP CTransformFilter::Pause() { CAutoLock lck(&m_csFilter); HRESULT hr = NOERROR; if (m_State == State_Paused) { // (This space left deliberately blank) } // If we have no input pin or it isn't yet connected then when we are // asked to pause we deliver an end of stream to the downstream filter. // This makes sure that it doesn't sit there forever waiting for // samples which we cannot ever deliver without an input connection. else if (m_pInput == NULL || m_pInput->IsConnected() == FALSE) { if (m_pOutput && m_bEOSDelivered == FALSE) { m_pOutput->DeliverEndOfStream(); m_bEOSDelivered = TRUE; } m_State = State_Paused; } // We may have an input connection but no output connection // However, if we have an input pin we do have an output pin else if (m_pOutput->IsConnected() == FALSE) { m_State = State_Paused; } else { if (m_State == State_Stopped) { // allow a class derived from CTransformFilter // to know about starting and stopping streaming CAutoLock lck2(&m_csReceive); hr = StartStreaming(); } if (SUCCEEDED(hr)) { hr = CBaseFilter::Pause(); } } m_bSampleSkipped = FALSE; m_bQualityChanged = FALSE; return hr; }
HRESULT MyThresholdDxFilter::OnEffectSetting(ID3DX11Effect* pEffect, void* self) { if (pEffect == NULL || self == NULL ) return E_FAIL; HRESULT hr = S_OK; MyThresholdDxFilter* pSelf = (MyThresholdDxFilter*)(GSDXFilterBase*)self; if (pSelf->m_pD3DDisplay == NULL || pSelf->m_pInTextureList.size() <= 0) return E_FAIL; GSAutoLock lck2(pSelf->m_pInTextureList[0]->GetGSCritSec()); IGSCamera* pCamera = pSelf->m_pD3DDisplay->GetCamera(); if (pCamera == NULL) return E_FAIL; CAutoLock lck1(&pSelf->m_csRenderPara); ID3D11ShaderResourceView* pInTex = NULL; hr = pSelf->m_pInTextureList[0]->GetShaderResourceView(pInTex); if (pInTex == NULL) return E_FAIL; int _sampleType = 1; //linear sampler float threshold = pSelf->m_fThreshold; D3DXMATRIX matView = pCamera->GetViewMatrix(); D3DXMATRIX matProj = pCamera->GetProjMatrix(); D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); D3DXMATRIX matWorldViewProj = matWorld * matView * matProj; GSEffectSettingEntry fxEntries[] = { {"WorldViewProj", MATRIX, (void*)&matWorldViewProj, 0, sizeof(matWorldViewProj)}, {"g_sampleType", SCALAR, (void*)&_sampleType, 0, sizeof(_sampleType)}, {"g_Texture", RESOURCE, (void*)pInTex, 0, 0}, {"g_threshold", SCALAR, (void*)&threshold, 0, sizeof(threshold)} }; hr = pSelf->_SetEffectPara(pEffect, fxEntries, ARRAYSIZE(fxEntries)); return hr; }
STDMETHODIMP CTransformFilter::Stop() { CAutoLock lck1(&m_csFilter); if (m_State == State_Stopped) { return NOERROR; } // Succeed the Stop if we are not completely connected ASSERT(m_pInput == NULL || m_pOutput != NULL); if (m_pInput == NULL || m_pInput->IsConnected() == FALSE || m_pOutput->IsConnected() == FALSE) { m_State = State_Stopped; m_bEOSDelivered = FALSE; return NOERROR; } ASSERT(m_pInput); ASSERT(m_pOutput); // decommit the input pin before locking or we can deadlock m_pInput->Inactive(); // synchronize with Receive calls CAutoLock lck2(&m_csReceive); m_pOutput->Inactive(); // allow a class derived from CTransformFilter // to know about starting and stopping streaming HRESULT hr = StopStreaming(); if (SUCCEEDED(hr)) { // complete the state transition m_State = State_Stopped; m_bEOSDelivered = FALSE; } return hr; }
STDMETHODIMP CudaDecodeFilter::Stop() { CAutoLock lck1(&m_cStateLock); if (m_State == State_Stopped) { return NOERROR; } // Succeed the Stop if we are not completely connected ASSERT(m_CudaDecodeInputPin == NULL || m_paStreams[0] != NULL); if (m_CudaDecodeInputPin == NULL || m_CudaDecodeInputPin->IsConnected() == FALSE || m_paStreams[0]->IsConnected() == FALSE) { m_State = State_Stopped; m_EOSDelivered = FALSE; return NOERROR; } // Important!!! Refuse to receive any more samples m_MediaController->FlushAllPending(); // decommit the input pin before locking or we can deadlock m_CudaDecodeInputPin->Inactive(); // synchronize with Receive calls CAutoLock lck2(&m_csReceive); OutputPin()->BeginFlush(); OutputPin()->Inactive(); OutputPin()->EndFlush(); // allow a class derived from CTransformFilter // to know about starting and stopping streaming HRESULT hr = StopStreaming(); if (SUCCEEDED(hr)) { // complete the state transition m_State = State_Stopped; m_EOSDelivered = FALSE; } return hr; }
void unfollow(int connfd, std::vector<std::string> &tokens){ std::cout << "unfollow execute\n"; std::unique_lock<std::mutex> lck(file3); std::unique_lock<std::mutex> lck2(file4); std::ifstream ifs(get_path(file_id[3])); std::string line, username = tokens[1], unf = tokens[2]; std::vector<std::string> flwing; bool found = false, valid = true; std::ofstream output; std::string temp_file = get_path(file_id[4]); if(ifs.is_open()){ output.open(temp_file); while(getline(ifs, line) && valid){ std::istringstream iss2(line); std::vector<std::string> temp{std::istream_iterator<std::string>{iss2}, std::istream_iterator<std::string>{}}; if(temp[0] == username){ found = true; for(int i = 1; i < temp.size(); i++){ if(temp[i] != unf){ flwing.push_back(temp[i]); } } if(temp.size() != flwing.size() + 2){ valid = false; write(connfd, "false", 5); break; } }else{ output << line << "\n"; } } ifs.close(); output.close(); } if(!found){ write(connfd, "false", 5); } if(valid && found){ output.open(get_path(file_id[3])); ifs.open(temp_file); while(getline(ifs, line)){ output << line << "\n"; } std::string retval = username + " "; for(int i = 0; i < flwing.size(); i++){ retval += flwing[i]; if(i != flwing.size()-1) retval += " "; } output << retval; output.close(); ifs.close(); std::string s = "unfollow " + tokens[1] + " " + tokens[2]; const char *msg = s.c_str(); int len = strlen(msg); if(b1_active){ send(backfd1, msg, len, 0); connect(1); } if(b2_active){ send(backfd2, msg, len, 0); connect(2); } if(b3_active){ send(backfd3, msg, len, 0); connect(3); } write(connfd, "true", 4); } }