Example #1
0
void CalibTree::Init(TChain *tree, const char *dupFileName) {
  // The Init() function is called when the selector needs to initialize
  // a new tree or chain. Typically here the branch addresses and branch
  // pointers of the tree will be set.
  // It is normally not necessary to make changes to the generated
  // code, but the routine can be extended by the user if needed.
  // Init() will be called many times when running on PROOF
  // (once per file to be processed).

  // Set object pointer
  t_DetIds       = 0;
  t_HitEnergies  = 0;
  t_trgbits      = 0;
  t_DetIds1      = 0;
  t_DetIds3      = 0;
  t_HitEnergies1 = 0;
  t_HitEnergies3 = 0;
  // Set branch addresses and branch pointers
  fChain = tree;
  if (!tree) return;
  fCurrent = -1;
  fChain->SetMakeClass(1);

  fChain->SetBranchAddress("t_Run", &t_Run, &b_t_Run);
  fChain->SetBranchAddress("t_Event", &t_Event, &b_t_Event);
  fChain->SetBranchAddress("t_DataType", &t_DataType, &b_t_DataType);
  fChain->SetBranchAddress("t_ieta", &t_ieta, &b_t_ieta);
  fChain->SetBranchAddress("t_iphi", &t_iphi, &b_t_iphi);
  fChain->SetBranchAddress("t_EventWeight", &t_EventWeight, &b_t_EventWeight);
  fChain->SetBranchAddress("t_nVtx", &t_nVtx, &b_t_nVtx);
  fChain->SetBranchAddress("t_nTrk", &t_nTrk, &b_t_nTrk);
  fChain->SetBranchAddress("t_goodPV", &t_goodPV, &b_t_goodPV);
  fChain->SetBranchAddress("t_l1pt", &t_l1pt, &b_t_l1pt);
  fChain->SetBranchAddress("t_l1eta", &t_l1eta, &b_t_l1eta);
  fChain->SetBranchAddress("t_l1phi", &t_l1phi, &b_t_l1phi);
  fChain->SetBranchAddress("t_l3pt", &t_l3pt, &b_t_l3pt);
  fChain->SetBranchAddress("t_l3eta", &t_l3eta, &b_t_l3eta);
  fChain->SetBranchAddress("t_l3phi", &t_l3phi, &b_t_l3phi);
  fChain->SetBranchAddress("t_p", &t_p, &b_t_p);
  fChain->SetBranchAddress("t_pt", &t_pt, &b_t_pt);
  fChain->SetBranchAddress("t_phi", &t_phi, &b_t_phi);
  fChain->SetBranchAddress("t_mindR1", &t_mindR1, &b_t_mindR1);
  fChain->SetBranchAddress("t_mindR2", &t_mindR2, &b_t_mindR2);
  fChain->SetBranchAddress("t_eMipDR", &t_eMipDR, &b_t_eMipDR);
  fChain->SetBranchAddress("t_eHcal", &t_eHcal, &b_t_eHcal);
  fChain->SetBranchAddress("t_eHcal10", &t_eHcal10, &b_t_eHcal10);
  fChain->SetBranchAddress("t_eHcal30", &t_eHcal30, &b_t_eHcal30);
  fChain->SetBranchAddress("t_hmaxNearP", &t_hmaxNearP, &b_t_hmaxNearP);
  fChain->SetBranchAddress("t_rhoh", &t_rhoh, &b_t_rhoh);
  fChain->SetBranchAddress("t_selectTk", &t_selectTk, &b_t_selectTk);
  fChain->SetBranchAddress("t_qltyFlag", &t_qltyFlag, &b_t_qltyFlag);
  fChain->SetBranchAddress("t_qltyMissFlag", &t_qltyMissFlag, &b_t_qltyMissFlag);
  fChain->SetBranchAddress("t_qltyPVFlag", &t_qltyPVFlag, &b_t_qltyPVFlag);
  fChain->SetBranchAddress("t_gentrackP", &t_gentrackP, &b_t_gentrackP);
  fChain->SetBranchAddress("t_DetIds", &t_DetIds, &b_t_DetIds);
  fChain->SetBranchAddress("t_HitEnergies", &t_HitEnergies, &b_t_HitEnergies);
  fChain->SetBranchAddress("t_trgbits", &t_trgbits, &b_t_trgbits);
  fChain->SetBranchAddress("t_DetIds1", &t_DetIds1, &b_t_DetIds1);
  fChain->SetBranchAddress("t_DetIds3", &t_DetIds3, &b_t_DetIds3);
  fChain->SetBranchAddress("t_HitEnergies1", &t_HitEnergies1, &b_t_HitEnergies1);
  fChain->SetBranchAddress("t_HitEnergies3", &t_HitEnergies3, &b_t_HitEnergies3);
  Notify();

  ifstream infil1(dupFileName);
  if (!infil1.is_open()) {
    std::cout << "Cannot open " << dupFileName << std::endl;
  } else {
    while (1) {
      Long64_t jentry;
      infil1 >> jentry;
      if (!infil1.good()) break;
      entries.push_back(jentry);
    }
    infil1.close();
    std::cout << "Reads a list of " << entries.size() << " events from " 
	      << dupFileName << std::endl;
  }
}
Example #2
0
DWORD CImplRepairVul::_ThreadFuncDownloadImpl()
{
	do 
	{
		m_thinfo.Reset();
		
		INT nTotalFixItem = m_arrDownloadItem.GetSize();
		if(nTotalFixItem==0)
			break;
		
		m_thinfo.totalNum = nTotalFixItem;
		
		//
		BOOL bImportLocal = m_dwRepairFlags&VULFLAG_REPAIR_IMPORT_LOCAL;
		BOOL bDownloadIfFailImport = m_dwRepairFlags&VULFLAG_REPAIR_DOWNLOAD_IF_FAIL_IMPORT;
		bImportLocal = bImportLocal && !m_strImportPath.IsEmpty();
		
		// 1. Download 

		CFileDownloader fdSingle;
		m_thinfo.m_pFileDownloaderSingle = &fdSingle;
		fdSingle.SetObserver( this );

		IDownload *fd = NULL;
		ATLVERIFY( SUCCEEDED(CreateDownloadObject(__uuidof(IDownload), (VOID**)&fd)) );
		m_thinfo.m_pFileDownloader = fd;
		fd->SetObserver( this );

		m_thinfo.m_fileDownloadLocal.SetObserver(this);
		for(int i=0; i<m_arrDownloadItem.GetSize() && !m_bCanceled; ++i)
		{
			T_RepairItem &item = m_arrDownloadItem[i];
            BOOL bNeedCheckCert = item.bCheckCert;
			DWORD dwDownfileStat = 0;
			
			Notify(EVulfix_DownloadBegin, item.nID, i, m_thinfo.totalNum);
			BOOL downSuccess = FALSE;
			if(item.type==VTYPE_SOFTLEAK && item.bDisableCOM)
			{
				downSuccess = TRUE;
			}
			else
			{
				downSuccess = FALSE;
				item.strFilename = m_strDownloadPath;
				CString strFilename;
				if(GetFileNameFromUrl(item.strURL, strFilename))
				{
					// 兼容正常文件名 
                    item.strFilename.Format(_T("%s\\%s"), m_strDownloadPath, strFilename);
					
					if(!IsFileExist(item.strFilename))
					{
                        item.strFilename.Format(_T("%s\\%s%s"), m_strDownloadPath, BK_FILE_PREFIX, strFilename);
						if(!IsFileExist(item.strFilename))
						{
							item.strFilename.Format(_T("%s\\%s"), m_strDownloadPath, strFilename);

							// download if file not exists 
							dwDownfileStat |= ERDOWN_LOCAL_NOT_EXISTS;
							BOOL toDownloadFromWeb = TRUE;
							if(bImportLocal)
							{
								m_thinfo.m_fileDownloadLocal.SetUserData((LPVOID)item.nID);

								CString strImportFilename;

								LPCTSTR lpszHttp = _T("http://");								
								if( _tcsnicmp(lpszHttp, m_strImportPath, _tcslen(lpszHttp))==0 )
								{
									// 支持本地http 导入 
									strImportFilename.Format(_T("%s/%s"), m_strImportPath, strFilename);
									fd->SetUserData((LPVOID)item.nID);
									fd->SetDownloadInfo(strImportFilename, item.strFilename);
									fd->Fetch();
								}
								else
								{
									// 本地路径导入 
									strImportFilename.Format(_T("%s\\%s"), m_strImportPath, strFilename);
									m_thinfo.m_fileDownloadLocal.SetDownloadInfo(strImportFilename, item.strFilename);
									if( !m_thinfo.m_fileDownloadLocal.Fetch() )
									{
										if(!m_bCanceled)
										{
											strImportFilename.Format(_T("%s\\%s%s"), m_strImportPath, BK_FILE_PREFIX, strFilename);
											m_thinfo.m_fileDownloadLocal.SetDownloadInfo(strImportFilename, item.strFilename);
											m_thinfo.m_fileDownloadLocal.Fetch();
										}
									}
								}

								if(PathFileExists(item.strFilename))
								{
									toDownloadFromWeb = FALSE;
									dwDownfileStat |= ERDOWN_IMPORT_LOCAL;
								}
								else
								{
									toDownloadFromWeb = bDownloadIfFailImport;
								}
							}
							
							if(toDownloadFromWeb && !m_bCanceled && !IsFileExist(item.strFilename) )
							{
								m_bDownloadHasReceivedData = FALSE;
                                for (int i = 0; i < 3 && !downSuccess && !m_bCanceled; i ++)
                                {
									// Download Fail, Wait for 3 seconds then to retry 
									if(i>0)
									{
										DWORD dwTimeWaitEnd = 3*1000 + GetTickCount();
										for(;!m_bCanceled && GetTickCount()<dwTimeWaitEnd;)
										{
											::Sleep(100);
										}
										if(m_bCanceled)
											break;
									}

                                    fd->SetUserData((LPVOID)item.nID);
                                    fd->SetDownloadInfo(item.strURL, item.strFilename);
                                    downSuccess = fd->Fetch();

									IDownStat *pdownstat = fd->GetDownloadStat();
									if(pdownstat && pdownstat->Downloaded()>0)
										m_bDownloadHasReceivedData = TRUE;

                                    if (downSuccess && bNeedCheckCert)
                                    {
                                        // 校验补丁包数字签名 
                                        HRESULT hVerifyRet = _VerifyWinTrustCert(item.strFilename);
                                        if(!IsValidPatchFile(item.strFilename) || FAILED(hVerifyRet))
                                        {
											dwDownfileStat |= ERDOWN_MULTIDOWN_ERRORSIGN;
                                            Notify(EVulfix_Download_Check_Error, item.nID, hVerifyRet, 0);
#ifdef _DEBUG
											MessageBox(NULL, _T("下载文件签名验证失败!!!"), NULL, MB_OK);
#else
                                            DeleteFile(item.strFilename);
											m_bDownloadHasReceivedData = TRUE;

											// 校验失败走单线程 
											downSuccess = fdSingle.Download(item.strURL, item.strFilename , NULL, (LPVOID)(INT_PTR)item.nID);
#endif                                      
											bNeedCheckCert = FALSE;
                                            break;
                                        }
                                        bNeedCheckCert = FALSE;
                                    }
                                }

								if(!m_bDownloadHasReceivedData)
									dwDownfileStat |= ERDOWN_CANNOT_REACH_OFFICIAL;

								// 如果未收到任何数据 
                                if (!downSuccess && !m_bCanceled && !m_bDownloadHasReceivedData && !item.strMirrorURL.IsEmpty())
                                {
									dwDownfileStat |= ERDOWN_MIRROR_USED;

									// 删除之前下载的所有文件?! , 因为如果一点数据都没有下载到的话, 就没必要删除临时文件了
                                    fd->SetUserData((LPVOID)item.nID);
                                    fd->SetDownloadInfo(item.strMirrorURL, item.strFilename);
                                    fd->Fetch(1);
                                }
							}
						}
					}
					
					downSuccess = IsFileExist(item.strFilename);
					if(downSuccess)
					{
                        if (bNeedCheckCert)
                        {
                            // 校验补丁包数字签名
                            HRESULT hVerifyRet = _VerifyWinTrustCert(item.strFilename);
                            if(FAILED(hVerifyRet))
                            {
                                Notify(EVulfix_Download_Check_Error, item.nID, hVerifyRet, 1);
                                DeleteFile(item.strFilename);
                                downSuccess = FALSE;
								dwDownfileStat |= ERDOWN_ERRORSIGN;
                            }
                        }
                        if(!IsValidPatchFile(item.strFilename))
						{
							DeleteFile(item.strFilename);
							downSuccess = FALSE;
						}
					}
				}
			}
			item.stateDownload = downSuccess;
			Notify(downSuccess ? EVulfix_DownloadEnd : EVulfix_DownloadError, item.nID, m_bCanceled, dwDownfileStat);
			
			if( downSuccess )
			{
				++m_thinfo.nDownSuccess;
				SetEvent(m_thinfo.m_hInstallEvent);
			}
		}
		{
			CObjGuard __guard__(m_thinfo.m_objLockFileDownloader, TRUE);
			m_thinfo.m_pFileDownloaderSingle = NULL;
            m_thinfo.m_pFileDownloader = NULL;
			m_thinfo.m_pFileDownloaderSingle = NULL;
			m_thinfo.m_fileDownloadLocal.SetObserver(NULL);
		}
		fd->SetObserver( NULL );
		fd->Release();
		fd = NULL;		
	} while (FALSE);
	
	m_thinfo.isDownloadDone = TRUE;
	SetEvent(m_thinfo.m_hInstallEvent);
	return 0;
}
Example #3
0
NS_IMETHODIMP
PlacesEvent::Run()
{
  Notify();
  return NS_OK;
}
Example #4
0
ECode NotificationManager::Notify(
    /* [in] */ Int32 id,
    /* [in] */ INotification* notification)
{
    return Notify(String(NULL), id, notification);
}
Example #5
0
/*
 * How server management (for one particular article) works:
	- there is a list of failed servers which is initially empty;
	- level is initially 0;

	<loop>
		- request a connection from server pool for current level;
		  Exception: this step is skipped for the very first download attempt, because a
		  level-0 connection is initially passed from queue manager;
		- try to download from server;
		- if connection to server cannot be established or download fails due to interrupted connection,
		  try again (as many times as needed without limit) the same server until connection is OK;
		- if download fails with error "Not-Found" (article or group not found) or with CRC error,
		  add the server to failed server list;
		- if download fails with general failure error (article incomplete, other unknown error
		  codes), try the same server again as many times as defined by option <Retries>; if all attempts
		  fail, add the server to failed server list;
		- if all servers from current level were tried, increase level;
		- if all servers from all levels were tried, break the loop with failure status.
	<end-loop>
*/
void ArticleDownloader::Run()
{
	debug("Entering ArticleDownloader-loop");

	SetStatus(adRunning);

	BuildOutputFilename();

	m_szResultFilename = m_pArticleInfo->GetResultFilename();

	if (g_pOptions->GetContinuePartial())
	{
		if (Util::FileExists(m_szResultFilename))
		{
			// file exists from previous program's start
			detail("Article %s already downloaded, skipping", m_szInfoName);
			FreeConnection(true);
			SetStatus(adFinished);
			Notify(NULL);
			return;
		}
	}

	EStatus Status = adFailed;

	int iRetries = g_pOptions->GetRetries() > 0 ? g_pOptions->GetRetries() : 1;
	int iRemainedRetries = iRetries;
	ServerPool::Servers failedServers;
	failedServers.reserve(g_pServerPool->GetServers()->size());
	NewsServer* pWantServer = NULL;
	NewsServer* pLastServer = NULL;
	int iLevel = 0;
	int iServerConfigGeneration = g_pServerPool->GetGeneration();

	while (!IsStopped())
	{
		Status = adFailed;

		SetStatus(adWaiting);
		while (!m_pConnection && !(IsStopped() || iServerConfigGeneration != g_pServerPool->GetGeneration()))
		{
			m_pConnection = g_pServerPool->GetConnection(iLevel, pWantServer, &failedServers);
			usleep(5 * 1000);
		}
		SetLastUpdateTimeNow();
		SetStatus(adRunning);

		if (IsStopped() || g_pOptions->GetPauseDownload() || g_pOptions->GetPauseDownload2() ||
			iServerConfigGeneration != g_pServerPool->GetGeneration())
		{
			Status = adRetry;
			break;
		}

		pLastServer = m_pConnection->GetNewsServer();

		m_pConnection->SetSuppressErrors(false);

		// test connection
		bool bConnected = m_pConnection && m_pConnection->Connect();
		if (bConnected && !IsStopped())
		{
			// Okay, we got a Connection. Now start downloading.
			detail("Downloading %s @ %s (%s)", m_szInfoName,
				m_pConnection->GetNewsServer()->GetName(), m_pConnection->GetHost());
			Status = Download();
		}

		if (bConnected)
		{
			if (Status == adConnectError)
			{
				m_pConnection->Disconnect();
				bConnected = false;
				Status = adFailed;
			}
			else
			{
				// freeing connection allows other threads to start.
				// we doing this only if the problem was with article or group.
				// if the problem occurs by connecting or authorization we do not
				// free the connection, to prevent starting of thousands of threads 
				// (cause each of them will also free it's connection after the 
				// same connect-error).
				FreeConnection(Status == adFinished || Status == adNotFound);
			}
		}

		if (Status == adFinished || Status == adFatalError)
		{
			break;
		}

		pWantServer = NULL;

		if (bConnected && Status == adFailed)
		{
			iRemainedRetries--;
		}

		if (!bConnected || (Status == adFailed && iRemainedRetries > 0))
		{
			pWantServer = pLastServer;
		}

		if (pWantServer && 
			!(IsStopped() || g_pOptions->GetPauseDownload() || g_pOptions->GetPauseDownload2() ||
			 iServerConfigGeneration != g_pServerPool->GetGeneration()))
		{
			detail("Waiting %i sec to retry", g_pOptions->GetRetryInterval());
			SetStatus(adWaiting);
			int msec = 0;
			while (!(IsStopped() || g_pOptions->GetPauseDownload() || g_pOptions->GetPauseDownload2() ||
				  iServerConfigGeneration != g_pServerPool->GetGeneration()) &&
				  msec < g_pOptions->GetRetryInterval() * 1000)
			{
				usleep(100 * 1000);
				msec += 100;
			}
			SetLastUpdateTimeNow();
			SetStatus(adRunning);
		}

		if (IsStopped() || g_pOptions->GetPauseDownload() || g_pOptions->GetPauseDownload2() ||
			iServerConfigGeneration != g_pServerPool->GetGeneration())
		{
			Status = adRetry;
			break;
		}

		if (!pWantServer)
		{
			failedServers.push_back(pLastServer);

			// if all servers from current level were tried, increase level
			// if all servers from all levels were tried, break the loop with failure status

			bool bAllServersOnLevelFailed = true;
			for (ServerPool::Servers::iterator it = g_pServerPool->GetServers()->begin(); it != g_pServerPool->GetServers()->end(); it++)
			{
				NewsServer* pCandidateServer = *it;
				if (pCandidateServer->GetNormLevel() == iLevel)
				{
					bool bServerFailed = !pCandidateServer->GetActive();
					if (!bServerFailed)
					{
						for (ServerPool::Servers::iterator it = failedServers.begin(); it != failedServers.end(); it++)
						{
							NewsServer* pIgnoreServer = *it;
							if (pIgnoreServer == pCandidateServer ||
								(pIgnoreServer->GetGroup() > 0 && pIgnoreServer->GetGroup() == pCandidateServer->GetGroup() &&
								 pIgnoreServer->GetNormLevel() == pCandidateServer->GetNormLevel()))
							{
								bServerFailed = true;
								break;
							}					
						}
					}
					if (!bServerFailed)
					{
						bAllServersOnLevelFailed = false;
						break;
					}
				}
			}

			if (bAllServersOnLevelFailed)
			{
				if (iLevel < g_pServerPool->GetMaxNormLevel())
				{
					detail("Article %s @ all level %i servers failed, increasing level", m_szInfoName, iLevel);
					iLevel++;
				}
				else
				{
					warn("Article %s @ all servers failed", m_szInfoName);
					Status = adFailed;
					break;
				}
			}
			
			iRemainedRetries = iRetries;
		}
	}

	FreeConnection(Status == adFinished);

	if (m_bDuplicate)
	{
		Status = adFinished;
	}

	if (Status != adFinished && Status != adRetry)
	{
		Status = adFailed;
	}

	if (IsStopped())
	{
		detail("Download %s cancelled", m_szInfoName);
		Status = adRetry;
	}

	if (Status == adFailed)
	{
		warn("Download %s failed", m_szInfoName);
	}

	SetStatus(Status);
	Notify(NULL);

	debug("Exiting ArticleDownloader-loop");
}
Example #6
0
void NotifyFailSetDevTblEntry(void) {
        Notify(PSTR("\r\nsetDevTblEn"), 0x80);
}
Example #7
0
/**
 * For driver use only.
 *
 * @param pcbw
 * @param buf_size
 * @param buf
 * @param flags
 * @return
 */
uint8_t BulkOnly::Transaction(CommandBlockWrapper *pcbw, uint16_t buf_size, void *buf
#if MS_WANT_PARSER
        , uint8_t flags
#endif
        ) {

#if MS_WANT_PARSER
        uint16_t bytes = (pcbw->dCBWDataTransferLength > buf_size) ? buf_size : pcbw->dCBWDataTransferLength;
        printf("Transfersize %i\r\n", bytes);
        delay(1000);

        bool callback = (flags & MASS_TRANS_FLG_CALLBACK) == MASS_TRANS_FLG_CALLBACK;
#else
        uint16_t bytes = buf_size;
#endif
        bool write = (pcbw->bmCBWFlags & MASS_CMD_DIR_IN) != MASS_CMD_DIR_IN;
        uint8_t ret = 0;
        uint8_t usberr;
        CommandStatusWrapper csw; // up here, we allocate ahead to save cpu cycles.
        SetCurLUN(pcbw->bmCBWLUN);
        ErrorMessage<uint32_t > (PSTR("CBW.dCBWTag"), pcbw->dCBWTag);

        while((usberr = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, sizeof (CommandBlockWrapper), (uint8_t*)pcbw)) == hrBUSY) delay(1);

        ret = HandleUsbError(usberr, epDataOutIndex);
        //ret = HandleUsbError(pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, sizeof (CommandBlockWrapper), (uint8_t*)pcbw), epDataOutIndex);
        if(ret) {
                ErrorMessage<uint8_t > (PSTR("============================ CBW"), ret);
        } else {
                if(bytes) {
                        if(!write) {
#if MS_WANT_PARSER
                                if(callback) {
                                        uint8_t rbuf[bytes];
                                        while((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, rbuf)) == hrBUSY) delay(1);
                                        if(usberr == hrSUCCESS) ((USBReadParser*)buf)->Parse(bytes, rbuf, 0);
                                } else {
#endif
                                        while((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, (uint8_t*)buf)) == hrBUSY) delay(1);
#if MS_WANT_PARSER

                                }
#endif
                                ret = HandleUsbError(usberr, epDataInIndex);
                        } else {
                                while((usberr = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, bytes, (uint8_t*)buf)) == hrBUSY) delay(1);
                                ret = HandleUsbError(usberr, epDataOutIndex);
                        }
                        if(ret) {
                                ErrorMessage<uint8_t > (PSTR("============================ DAT"), ret);
                        }
                }
        }

        {
                bytes = sizeof (CommandStatusWrapper);
                int tries = 2;
                while(tries--) {
                        while((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, (uint8_t*) & csw)) == hrBUSY) delay(1);
                        if(!usberr) break;
                        ClearEpHalt(epDataInIndex);
                        if(tries) ResetRecovery();
                }
                if(!ret) {
                        Notify(PSTR("CBW:\t\tOK\r\n"), 0x80);
                        Notify(PSTR("Data Stage:\tOK\r\n"), 0x80);
                } else {
                        // Throw away csw, IT IS NOT OF ANY USE.
                        ResetRecovery();
                        return ret;
                }
                ret = HandleUsbError(usberr, epDataInIndex);
                if(ret) {
                        ErrorMessage<uint8_t > (PSTR("============================ CSW"), ret);
                }
                if(usberr == hrSUCCESS) {
                        if(IsValidCSW(&csw, pcbw)) {
                                //ErrorMessage<uint32_t > (PSTR("CSW.dCBWTag"), csw.dCSWTag);
                                //ErrorMessage<uint8_t > (PSTR("bCSWStatus"), csw.bCSWStatus);
                                //ErrorMessage<uint32_t > (PSTR("dCSWDataResidue"), csw.dCSWDataResidue);
                                Notify(PSTR("CSW:\t\tOK\r\n\r\n"), 0x80);
                                return csw.bCSWStatus;
                        } else {
                                // NOTE! Sometimes this is caused by the reported residue being wrong.
                                // Get a different device. It isn't compliant, and should have never passed Q&A.
                                // I own one... 05e3:0701 Genesys Logic, Inc. USB 2.0 IDE Adapter.
                                // Other devices that exhibit this behavior exist in the wild too.
                                // Be sure to check quirks in the Linux source code before reporting a bug. --xxxajk
                                Notify(PSTR("Invalid CSW\r\n"), 0x80);
                                ResetRecovery();
                                //return MASS_ERR_SUCCESS;
                                return MASS_ERR_INVALID_CSW;
                        }
                }
        }
        return ret;
}
Example #8
0
void PrintExpCompensation()
{
    Notify(PSTR("ExpComp:"));
    PrintValueTitle<uint8_t, VT_EXPCOMP, VT_EXPCOMP_COUNT, VT_EXPCOMP_TEXT_LEN>((PTP*)&Ps, PS_DPC_ExpCompensation, ExpCompTitles);
    Notify(PSTR("\r\n"));
}
Example #9
0
void PrintCamOutput()
{
    Notify(PSTR("CamOutput:"));
    PrintValueTitle<uint8_t, VT_CAMOUTPUT, VT_CAMOUTPUT_COUNT, VT_CAMOUTPUT_TEXT_LEN>((PTP*)&Ps, PS_DPC_CameraOutput, CamOutputTitles);
    Notify(PSTR("\r\n"));
}
Example #10
0
void PrintWB()
{
    Notify(PSTR("WB:"));
    PrintValueTitle<uint8_t, VT_WB, VT_WB_COUNT, VT_WB_TEXT_LEN>((PTP*)&Ps, PS_DPC_WhiteBalance, WbTitles);
    Notify(PSTR("\r\n"));
}
Example #11
0
void PrintIso()
{
    Notify(PSTR("ISO:"));
    PrintValueTitle<uint16_t, VT_ISO, VT_ISO_COUNT, VT_ISO_TEXT_LEN>((PTP*)&Ps, PS_DPC_ISOSpeed, IsoTitles);
    Notify(PSTR("\r\n"));
}
Example #12
0
void PrintShutterSpeed()
{
    Notify(PSTR("T:"));
    PrintValueTitle<uint16_t, VT_SHSPEED, VT_SHSPEED_COUNT, VT_SHSPEED_TEXT_LEN>((PTP*)&Ps, PS_DPC_ShutterSpeed, ShutterSpeedTitles);
    Notify(PSTR("\r\n"));
}
Example #13
0
void PrintAperture()
{
    Notify(PSTR("F:"));
    PrintValueTitle<uint16_t, VT_APERTURE, VT_APT_COUNT, VT_APT_TEXT_LEN>((PTP*)&Ps, PS_DPC_Aperture, ApertureTitles);
    Notify(PSTR("\r\n"));
}
Example #14
0
void PrintMode()
{
    Notify(PSTR("Mode:"));
    PrintValueTitle<uint8_t, VT_MODE, VT_MODE_COUNT, VT_MODE_TEXT_LEN>((PTP*)&Ps, PS_DPC_ShootingMode, ModeTitles);
    Notify(PSTR("\r\n"));
}
Example #15
0
void NotifyFail(uint8_t rcode) {
        D_PrintHex<uint8_t > (rcode, 0x80);
        Notify(PSTR("\r\n"), 0x80);
}
Example #16
0
void FTComputingState::onFindSuccRedirect(
					Node* node,
					osip_transaction_t * tr ,
					osip_message *response) 
{
	char *message;
	size_t length = 0;
	int i = osip_message_to_str(response, &message, &length);
	node->LogStream("RECEIVE<<======================================\n") ;
	node->LogStream(message) ;
//	printf("RECEIVE<<======================================\n") ;
//	printf(message) ;

	/* to , from , contact are same as orig_request ;
	req_uri is the contact of the response */
	ChordId to(
			atoi(tr->orig_request->to->url->username),
			node->getConstants(),
			tr->orig_request->to->url->host,
			tr->orig_request->to->url->port
			) ;
	ChordId from(
			atoi(tr->orig_request->from->url->username),
			node->getConstants(),
			tr->orig_request->from->url->host,
			tr->orig_request->from->url->port
			) ;

		
	osip_contact_t *osip_contact ;
	osip_message_get_contact(response,0,&osip_contact) ;
	if(!osip_contact)	
	{return ;}//error
	ChordId contact(
		atoi(osip_contact->url->username),
		node->getConstants(),
		osip_contact->url->host,
		osip_contact->url->port
		) ;


	ChordId chordId = node->getChordId() ;
	//******************************

	//如果重定向到自己,那么自身就是对应to的finger
	if(contact.equals(chordId))
	{
		//scan fingertable
		for(int i = 1 ; i <= node->getFingerTable()->getTableLength() ; i++)
		{
			if(node->getFingerTable()->getFinger(i)->start.equals(to)) 
				break ;
		}

		int k ;
		if(i <= node->getFingerTable()->getTableLength())
			k = node->Set_Fingers(i, contact) + 1 ;

		//A.finger表更新完毕
		if (k == node->getFingerTable()->getTableLength() + 1)
		{
			//- Notify ...
			Notify(node) ;			
			//- change state ...
			ChangeState(node,new NormalState(node)) ;
		}

		//B.finger表未更新完
		if (k<= node->getFingerTable()->getTableLength())	//update of fingertalbe if not completed
		{
			int i = node->SndRegister(FINDSUCC,contact,node->getFingerTable()->getFinger(k)->start,chordId) ; 
			
			//- not change state...
			return ;
		}	
	}

	//继续重定向
	else
	{
		node->SndRegister(FINDSUCC,contact,to,chordId) ; 		
	}

}
Example #17
0
void NotifyFailGetDevDescr(void) {
        Notify(PSTR("\r\ngetDevDescr"), 0x80);
}
Example #18
0
//------------------------------------------------------------------
void FTComputingState::onFindSuccOK(	Node* node,
					osip_transaction_t * tr ,
					osip_message *response) 
{
	char *message;
	size_t length = 0;
	int i = osip_message_to_str(response, &message, &length);
	node->LogStream("RECEIVE<<======================================\n") ;
	node->LogStream(message) ;
//	printf("RECEIVE<<======================================\n") ;
//	printf(message) ;

	ChordId to(
			atoi(response->to->url->username),
			node->getConstants(),
			response->to->url->host,
			response->to->url->port
			) ;

	osip_contact_t * osip_contact ;
	osip_message_get_contact(response,0,&osip_contact) ;
	if(!osip_contact)	
	{return ;}//error
	ChordId contact(
		atoi(osip_contact->url->username),
		node->getConstants(),
		osip_contact->url->host,
		osip_contact->url->port
		) ;

	ChordId chordId = node->getChordId() ;
	//******************************

	//scan fingertable
	for(i = 1 ; i <= node->getFingerTable()->getTableLength() ; i++)
	{
		if(node->getFingerTable()->getFinger(i)->start.equals(to)) 
			break ;
	}
	
	int k ;
	if(i <= node->getFingerTable()->getTableLength())
		k = node->Set_Fingers(i, contact) + 1 ;

	//A.finger表更新完毕,有两种情况
	if (k == node->getFingerTable()->getTableLength() + 1)
	{
		//- Notify ...
		Notify(node) ;			
		//- change state ...
		ChangeState(node,new NormalState(node)) ;

		return ;
	}

	//B.finger表未更新完
	if (k<= node->getFingerTable()->getTableLength())	//update of fingertalbe if not completed
	{
		int i = node->SndRegister(FINDSUCC,contact,node->getFingerTable()->getFinger(k)->start,chordId) ;

		//- not change state...
		return ;
	}
}
Example #19
0
void NotifyFailSetConfDescr(void) {
        Notify(PSTR("\r\nsetConf"), 0x80);
}
Example #20
0
uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
    uint8_t	buf[sizeof(USB_DEVICE_DESCRIPTOR)];
	uint8_t	rcode;
	UsbDevice *p = NULL;
	EpInfo *oldep_ptr = NULL;
    uint16_t PID;
    uint16_t VID;
    
    // get memory address of USB device address pool
	AddressPool	&addrPool = pUsb->GetAddressPool();    
#ifdef EXTRADEBUG
	Notify(PSTR("\r\nXBOXUSB Init"));
#endif
    // check if address has already been assigned to an instance
    if (bAddress) {
#ifdef DEBUG
        Notify(PSTR("\r\nAddress in use"));
#endif
        return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
    }
    
    // Get pointer to pseudo device with address 0 assigned
    p = addrPool.GetUsbDevicePtr(0);
    
    if (!p) {        
#ifdef DEBUG
	    Notify(PSTR("\r\nAddress not found"));
#endif
        return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
    }
    
    if (!p->epinfo) {
#ifdef DEBUG
        Notify(PSTR("\r\nepinfo is null"));
#endif
        return USB_ERROR_EPINFO_IS_NULL;
    }
    
    // Save old pointer to EP_RECORD of address 0
    oldep_ptr = p->epinfo;
    
    // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
    p->epinfo = epInfo;
    
    p->lowspeed = lowspeed;
    
    // Get device descriptor
    rcode = pUsb->getDevDescr(0, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);// Get device descriptor - addr, ep, nbytes, data
    // Restore p->epinfo
    p->epinfo = oldep_ptr;
    
    if(rcode)
        goto FailGetDevDescr;
    
    VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
    PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
    
    if(VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) // We just check if it's a xbox controller using the Vendor ID
        goto FailUnknownDevice;
    if(PID == XBOX_WIRELESS_PID) {
#ifdef DEBUG
        Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"));
#endif
        goto FailUnknownDevice;
    }
    else if(PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) {
#ifdef DEBUG
        Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"));
#endif
        goto FailUnknownDevice;
    }        
    
    // Allocate new address according to device class
    bAddress = addrPool.AllocAddress(parent, false, port);
    
    if (!bAddress)
		return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
    
    // Extract Max Packet Size from device descriptor
    epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; 
    
    // Assign new address to the device
    rcode = pUsb->setAddr( 0, 0, bAddress );
    if (rcode) {
        p->lowspeed = false;
        addrPool.FreeAddress(bAddress);
        bAddress = 0;
#ifdef DEBUG
        Notify(PSTR("\r\nsetAddr: "));
#endif
        PrintHex<uint8_t>(rcode);
        return rcode;
    }
#ifdef EXTRADEBUG
    Notify(PSTR("\r\nAddr: "));
    PrintHex<uint8_t>(bAddress);
#endif
    p->lowspeed = false;
    
    //get pointer to assigned address record
    p = addrPool.GetUsbDevicePtr(bAddress);
    if (!p) 
        return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
    
    p->lowspeed = lowspeed;        
    
    // Assign epInfo to epinfo pointer - only EP0 is known
    rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
    if (rcode)
        goto FailSetDevTblEntry;
            
    /* The application will work in reduced host mode, so we can save program and data
       memory space. After verifying the VID we will use known values for the
       configuration values for device, interface, endpoints and HID for the XBOX360 Controllers */
        
    /* Initialize data structures for endpoints of device */
    epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01;    // XBOX 360 report endpoint
    epInfo[ XBOX_INPUT_PIPE ].epAttribs  = EP_INTERRUPT;
    epInfo[ XBOX_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
    epInfo[ XBOX_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
    epInfo[ XBOX_INPUT_PIPE ].bmSndToggle = bmSNDTOG0;
    epInfo[ XBOX_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
    epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02;    // XBOX 360 output endpoint
    epInfo[ XBOX_OUTPUT_PIPE ].epAttribs  = EP_INTERRUPT;
    epInfo[ XBOX_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
    epInfo[ XBOX_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
    epInfo[ XBOX_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0;
    epInfo[ XBOX_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
        
    rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
    if( rcode )
        goto FailSetDevTblEntry;
        
    delay(200);//Give time for address change
        
    rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
    if( rcode )
        goto FailSetConf;        

#ifdef DEBUG
    Notify(PSTR("\r\nXbox 360 Controller Connected"));
#endif                         
    setLedMode(ROTATING);
    Xbox360Connected = true;        

    bPollEnable = true;
    Notify(PSTR("\r\n"));
    return 0; // successful configuration
    
    /* diagnostic messages */  
FailGetDevDescr:
#ifdef DEBUG
    Notify(PSTR("\r\ngetDevDescr:"));
#endif
    goto Fail;    
FailSetDevTblEntry:
#ifdef DEBUG
    Notify(PSTR("\r\nsetDevTblEn:"));
#endif
    goto Fail;
FailSetConf:
#ifdef DEBUG
    Notify(PSTR("\r\nsetConf:"));
#endif
    goto Fail; 
FailUnknownDevice:
#ifdef DEBUG
    Notify(PSTR("\r\nUnknown Device Connected - VID: "));
    PrintHex<uint16_t>(VID);
    Notify(PSTR(" PID: "));
    PrintHex<uint16_t>(PID);
#endif
    rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
    goto Fail;
Fail:
#ifdef DEBUG
    Notify(PSTR("\r\nXbox 360 Init Failed, error code: "));
    Serial.print(rcode,HEX);
#endif    
    Release();
    return rcode;
}
Example #21
0
/**
 * For driver use only.
 *
 * @param status
 * @return
 */
uint8_t BulkOnly::HandleSCSIError(uint8_t status) {
        uint8_t ret = 0;

        switch(status) {
                case 0: return MASS_ERR_SUCCESS;

                case 2:
                        ErrorMessage<uint8_t > (PSTR("Phase Error"), status);
                        ErrorMessage<uint8_t > (PSTR("LUN"), bTheLUN);
                        ResetRecovery();
                        return MASS_ERR_GENERAL_SCSI_ERROR;

                case 1:
                        ErrorMessage<uint8_t > (PSTR("SCSI Error"), status);
                        ErrorMessage<uint8_t > (PSTR("LUN"), bTheLUN);
                        RequestSenseResponce rsp;

                        ret = RequestSense(bTheLUN, sizeof (RequestSenseResponce), (uint8_t*) & rsp);

                        if(ret) {
                                return MASS_ERR_GENERAL_SCSI_ERROR;
                        }
                        ErrorMessage<uint8_t > (PSTR("Response Code"), rsp.bResponseCode);
                        if(rsp.bResponseCode & 0x80) {
                                Notify(PSTR("Information field: "), 0x80);
                                for(int i = 0; i < 4; i++) {
                                        D_PrintHex<uint8_t > (rsp.CmdSpecificInformation[i], 0x80);
                                        Notify(PSTR(" "), 0x80);
                                }
                                Notify(PSTR("\r\n"), 0x80);
                        }
                        ErrorMessage<uint8_t > (PSTR("Sense Key"), rsp.bmSenseKey);
                        ErrorMessage<uint8_t > (PSTR("Add Sense Code"), rsp.bAdditionalSenseCode);
                        ErrorMessage<uint8_t > (PSTR("Add Sense Qual"), rsp.bAdditionalSenseQualifier);
                        // warning, this is not testing ASQ, only SK and ASC.
                        switch(rsp.bmSenseKey) {
                                case SCSI_S_UNIT_ATTENTION:
                                        switch(rsp.bAdditionalSenseCode) {
                                                case SCSI_ASC_MEDIA_CHANGED:
                                                        return MASS_ERR_MEDIA_CHANGED;
                                                default:
                                                        return MASS_ERR_UNIT_NOT_READY;
                                        }
                                case SCSI_S_NOT_READY:
                                        switch(rsp.bAdditionalSenseCode) {
                                                case SCSI_ASC_MEDIUM_NOT_PRESENT:
                                                        return MASS_ERR_NO_MEDIA;
                                                default:
                                                        return MASS_ERR_UNIT_NOT_READY;
                                        }
                                case SCSI_S_ILLEGAL_REQUEST:
                                        switch(rsp.bAdditionalSenseCode) {
                                                case SCSI_ASC_LBA_OUT_OF_RANGE:
                                                        return MASS_ERR_BAD_LBA;
                                                default:
                                                        return MASS_ERR_CMD_NOT_SUPPORTED;
                                        }
                                default:
                                        return MASS_ERR_GENERAL_SCSI_ERROR;
                        }

                        // case 4: return MASS_ERR_UNIT_BUSY; // Busy means retry later.
                        //    case 0x05/0x14: we stalled out
                        //    case 0x15/0x16: we naked out.
                default:
                        ErrorMessage<uint8_t > (PSTR("Gen SCSI Err"), status);
                        ErrorMessage<uint8_t > (PSTR("LUN"), bTheLUN);
                        return status;
        } // switch
}
Example #22
0
void BTHID::L2CAP_task() {
        switch(l2cap_state) {
                        /* These states are used if the HID device is the host */
                case L2CAP_CONTROL_SUCCESS:
                        if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
#endif
                                setProtocol(); // Set protocol before establishing HID interrupt channel
                                l2cap_state = L2CAP_INTERRUPT_SETUP;
                        }
                        break;

                case L2CAP_INTERRUPT_SETUP:
                        if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)) {
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
#endif
                                pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
                                delay(1);
                                pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
                                identifier++;
                                delay(1);
                                pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);

                                l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
                        }
                        break;

                        /* These states are used if the Arduino is the host */
                case L2CAP_CONTROL_CONNECT_REQUEST:
                        if(l2cap_check_flag(L2CAP_FLAG_CONTROL_CONNECTED)) {
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nSend HID Control Config Request"), 0x80);
#endif
                                identifier++;
                                pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
                                l2cap_state = L2CAP_CONTROL_CONFIG_REQUEST;
                        }
                        break;

                case L2CAP_CONTROL_CONFIG_REQUEST:
                        if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
                                setProtocol(); // Set protocol before establishing HID interrupt channel
                                delay(1); // Short delay between commands - just to be sure
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80);
#endif
                                identifier++;
                                pBtd->l2cap_connection_request(hci_handle, identifier, interrupt_dcid, HID_INTR_PSM);
                                l2cap_state = L2CAP_INTERRUPT_CONNECT_REQUEST;
                        }
                        break;

                case L2CAP_INTERRUPT_CONNECT_REQUEST:
                        if(l2cap_check_flag(L2CAP_FLAG_INTERRUPT_CONNECTED)) {
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80);
#endif
                                identifier++;
                                pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
                                l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
                        }
                        break;

                case L2CAP_INTERRUPT_CONFIG_REQUEST:
                        if(l2cap_check_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)) { // Now the HID channels is established
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nHID Channels Established"), 0x80);
#endif
                                pBtd->connectToHIDDevice = false;
                                pBtd->pairWithHIDDevice = false;
                                connected = true;
                                onInit();
                                l2cap_state = L2CAP_DONE;
                        }
                        break;

                case L2CAP_DONE:
                        break;

                case L2CAP_INTERRUPT_DISCONNECT:
                        if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)) {
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
#endif
                                identifier++;
                                pBtd->l2cap_disconnection_request(hci_handle, identifier, control_scid, control_dcid);
                                l2cap_state = L2CAP_CONTROL_DISCONNECT;
                        }
                        break;

                case L2CAP_CONTROL_DISCONNECT:
                        if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)) {
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
#endif
                                pBtd->hci_disconnect(hci_handle);
                                hci_handle = -1; // Reset handle
                                l2cap_event_flag = 0; // Reset flags
                                l2cap_state = L2CAP_WAIT;
                        }
                        break;
        }
}
Example #23
0
void ReplicationCtx::Close() {
    CloseMasterFD();
    CloseSlaveFD();
	CloseRepl();
    Notify();
}
Example #24
0
void BTHID::ACLData(uint8_t* l2capinbuf) {
        if(!pBtd->l2capConnectionClaimed && pBtd->incomingHIDDevice && !connected && !activeConnection) {
                if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
                        if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
                                pBtd->incomingHIDDevice = false;
                                pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
                                activeConnection = true;
                                hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
                                l2cap_state = L2CAP_WAIT;
                        }
                }
        }
        //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
        if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection
                if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
                        if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG_USB_HOST
                                Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
                                Notify(PSTR(" "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
                                Notify(PSTR(" "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
                                Notify(PSTR(" "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
                                Notify(PSTR(" "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
                                Notify(PSTR(" "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
#endif
                        } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_RESPONSE) {
                                if(((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) == SUCCESSFUL)) { // Success
                                        if(l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) {
                                                //Notify(PSTR("\r\nHID Control Connection Complete"), 0x80);
                                                identifier = l2capinbuf[9];
                                                control_scid[0] = l2capinbuf[12];
                                                control_scid[1] = l2capinbuf[13];
                                                l2cap_set_flag(L2CAP_FLAG_CONTROL_CONNECTED);
                                        } else if(l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) {
                                                //Notify(PSTR("\r\nHID Interrupt Connection Complete"), 0x80);
                                                identifier = l2capinbuf[9];
                                                interrupt_scid[0] = l2capinbuf[12];
                                                interrupt_scid[1] = l2capinbuf[13];
                                                l2cap_set_flag(L2CAP_FLAG_INTERRUPT_CONNECTED);
                                        }
                                }
                        } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
#ifdef EXTRADEBUG
                                Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
                                Notify(PSTR(" "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
                                Notify(PSTR(" SCID: "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
                                Notify(PSTR(" "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
                                Notify(PSTR(" Identifier: "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
#endif
                                if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
                                        identifier = l2capinbuf[9];
                                        control_scid[0] = l2capinbuf[14];
                                        control_scid[1] = l2capinbuf[15];
                                        l2cap_set_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST);
                                } else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
                                        identifier = l2capinbuf[9];
                                        interrupt_scid[0] = l2capinbuf[14];
                                        interrupt_scid[1] = l2capinbuf[15];
                                        l2cap_set_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST);
                                }
                        } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
                                if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
                                        if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
                                                //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
                                                identifier = l2capinbuf[9];
                                                l2cap_set_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS);
                                        } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
                                                //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
                                                identifier = l2capinbuf[9];
                                                l2cap_set_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS);
                                        }
                                }
                        } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
                                if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
                                        //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
                                        pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
                                } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
                                        //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
                                        pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
                                }
                        } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
                                if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
#ifdef DEBUG_USB_HOST
                                        Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
#endif
                                        identifier = l2capinbuf[9];
                                        pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
                                        Reset();
                                } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
#ifdef DEBUG_USB_HOST
                                        Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
#endif
                                        identifier = l2capinbuf[9];
                                        pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
                                        Reset();
                                }
                        } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
                                if(l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
                                        //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
                                        identifier = l2capinbuf[9];
                                        l2cap_set_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE);
                                } else if(l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
                                        //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
                                        identifier = l2capinbuf[9];
                                        l2cap_set_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE);
                                }
                        }
#ifdef EXTRADEBUG
                        else {
                                identifier = l2capinbuf[9];
                                Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
                                D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
                        }
#endif
                } else if(l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
#ifdef PRINTREPORT
                        Notify(PSTR("\r\nL2CAP Interrupt: "), 0x80);
                        for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
                                D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
                                Notify(PSTR(" "), 0x80);
                        }
#endif
                        if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
                                uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
                                ParseBTHID(this, (uint8_t)(length - 1), &l2capinbuf[9]);

                                switch(l2capinbuf[9]) {
                                        case 0x01: // Keyboard or Joystick events
                                                if(pRptParser[KEYBOARD_PARSER_ID])
                                                        pRptParser[KEYBOARD_PARSER_ID]->Parse(reinterpret_cast<HID *>(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
                                                break;

                                        case 0x02: // Mouse events
                                                if(pRptParser[MOUSE_PARSER_ID])
                                                        pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast<HID *>(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
                                                break;
#ifdef EXTRADEBUG
                                        default:
                                                Notify(PSTR("\r\nUnknown Report type: "), 0x80);
                                                D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
                                                break;
#endif
                                }
                        }
                } else if(l2capinbuf[6] == control_dcid[0] && l2capinbuf[7] == control_dcid[1]) { // l2cap_control
#ifdef PRINTREPORT
                        Notify(PSTR("\r\nL2CAP Control: "), 0x80);
                        for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
                                D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
                                Notify(PSTR(" "), 0x80);
                        }
#endif
                }
#ifdef EXTRADEBUG
                else {
                        Notify(PSTR("\r\nUnsupported L2CAP Data - Channel ID: "), 0x80);
                        D_PrintHex<uint8_t > (l2capinbuf[7], 0x80);
                        Notify(PSTR(" "), 0x80);
                        D_PrintHex<uint8_t > (l2capinbuf[6], 0x80);

                        Notify(PSTR("\r\nData: "), 0x80);
                        Notify(PSTR("\r\n"), 0x80);
                        for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
                                D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
                                Notify(PSTR(" "), 0x80);
                        }
                }
#endif
                L2CAP_task();
        }
}
Example #25
0
void CalibSort::Init(TTree *tree) {
  // The Init() function is called when the selector needs to initialize
  // a new tree or chain. Typically here the branch addresses and branch
  // pointers of the tree will be set.
  // It is normally not necessary to make changes to the generated
  // code, but the routine can be extended by the user if needed.
  // Init() will be called many times when running on PROOF
  // (once per file to be processed).
  
  // Set object pointer
  t_DetIds       = 0;
  t_DetIds1      = 0;
  t_DetIds3      = 0;
  t_HitEnergies  = 0;
  t_HitEnergies1 = 0;
  t_HitEnergies3 = 0;
  t_trgbits      = 0;
  // Set branch addresses and branch pointers
  if (!tree) return;
  fChain = tree;
  fCurrent = -1;
  fChain->SetMakeClass(1);

  fChain->SetBranchAddress("t_Run", &t_Run, &b_t_Run);
  fChain->SetBranchAddress("t_Event", &t_Event, &b_t_Event);
  fChain->SetBranchAddress("t_DataType", &t_DataType, &b_t_DataType);
  fChain->SetBranchAddress("t_ieta", &t_ieta, &b_t_ieta);
  fChain->SetBranchAddress("t_iphi", &t_iphi, &b_t_iphi);
  fChain->SetBranchAddress("t_EventWeight", &t_EventWeight, &b_t_EventWeight);
  fChain->SetBranchAddress("t_nVtx", &t_nVtx, &b_t_nVtx);
  fChain->SetBranchAddress("t_nTrk", &t_nTrk, &b_t_nTrk);
  fChain->SetBranchAddress("t_goodPV", &t_goodPV, &b_t_goodPV);
  fChain->SetBranchAddress("t_l1pt", &t_l1pt, &b_t_l1pt);
  fChain->SetBranchAddress("t_l1eta", &t_l1eta, &b_t_l1eta);
  fChain->SetBranchAddress("t_l1phi", &t_l1phi, &b_t_l1phi);
  fChain->SetBranchAddress("t_l3pt", &t_l3pt, &b_t_l3pt);
  fChain->SetBranchAddress("t_l3eta", &t_l3eta, &b_t_l3eta);
  fChain->SetBranchAddress("t_l3phi", &t_l3phi, &b_t_l3phi);
  fChain->SetBranchAddress("t_p", &t_p, &b_t_p);
  fChain->SetBranchAddress("t_pt", &t_pt, &b_t_pt);
  fChain->SetBranchAddress("t_phi", &t_phi, &b_t_phi);
  fChain->SetBranchAddress("t_mindR1", &t_mindR1, &b_t_mindR1);
  fChain->SetBranchAddress("t_mindR2", &t_mindR2, &b_t_mindR2);
  fChain->SetBranchAddress("t_eMipDR", &t_eMipDR, &b_t_eMipDR);
  fChain->SetBranchAddress("t_eHcal", &t_eHcal, &b_t_eHcal);
  fChain->SetBranchAddress("t_eHcal10", &t_eHcal10, &b_t_eHcal10);
  fChain->SetBranchAddress("t_eHcal30", &t_eHcal30, &b_t_eHcal30);
  fChain->SetBranchAddress("t_hmaxNearP", &t_hmaxNearP, &b_t_hmaxNearP);
  fChain->SetBranchAddress("t_rhoh", &t_rhoh, &b_t_rhoh);
  fChain->SetBranchAddress("t_selectTk", &t_selectTk, &b_t_selectTk);
  fChain->SetBranchAddress("t_qltyFlag", &t_qltyFlag, &b_t_qltyFlag);
  fChain->SetBranchAddress("t_qltyMissFlag", &t_qltyMissFlag, &b_t_qltyMissFlag);
  fChain->SetBranchAddress("t_qltyPVFlag", &t_qltyPVFlag, &b_t_qltyPVFlag);
  fChain->SetBranchAddress("t_gentrackP", &t_gentrackP, &b_t_gentrackP);
  fChain->SetBranchAddress("t_DetIds", &t_DetIds, &b_t_DetIds);
  fChain->SetBranchAddress("t_HitEnergies", &t_HitEnergies, &b_t_HitEnergies);
  fChain->SetBranchAddress("t_trgbits", &t_trgbits, &b_t_trgbits);
  fChain->SetBranchAddress("t_DetIds1", &t_DetIds1, &b_t_DetIds1);
  fChain->SetBranchAddress("t_DetIds3", &t_DetIds3, &b_t_DetIds3);
  fChain->SetBranchAddress("t_HitEnergies1", &t_HitEnergies1, &b_t_HitEnergies1);
  fChain->SetBranchAddress("t_HitEnergies3", &t_HitEnergies3, &b_t_HitEnergies3);

  Notify();
}
Example #26
0
ASErr Plugin::Message(char *caller, char *selector, void *message)
{
	ASErr error = kUnhandledMsgErr;

	//sAIUser->MessageAlert(ai::UnicodeString(caller));
	
	// Acquire any missing optional suites.
	AcquireOptionalSuites();

	/* Sweet Pea messages */

	

	if (strcmp(caller, kSPAccessCaller ) == 0)
	{
		if (strcmp( selector, kSPAccessUnloadSelector) == 0)
			error = UnloadPlugin((SPInterfaceMessage *)message);

		else if (strcmp( selector, kSPAccessReloadSelector) == 0)
			error = ReloadPlugin((SPInterfaceMessage *)message);
	}
	else if (strcmp(caller, kSPInterfaceCaller) == 0)
	{
		if (strcmp(selector, kSPInterfaceAboutSelector) == 0)
			error = kNoErr;

		else if (strcmp(selector, kSPInterfaceStartupSelector) == 0)
			error = kNoErr;
	}
	else if (strcmp(caller, kSPCacheCaller) == 0)
	{
		if (strcmp(selector, kSPPluginPurgeCachesSelector) == 0)
		{
			if (Purge())
				error = kSPPluginCachesFlushResponse;
			else
				error = kSPPluginCouldntFlushResponse;
		}
	}
	else if (strcmp( caller, kSPPropertiesCaller ) == 0)
	{
		if (strcmp( selector, kSPPropertiesAcquireSelector ) == 0)
		{
			error = AcquireProperty((SPPropertiesMessage *) message);
		}
		else if (strcmp( selector, kSPPropertiesReleaseSelector ) == 0)
		{
			error = ReleaseProperty((SPPropertiesMessage *) message);
		}
	}

	/* Some common AI messages */

	else if (strcmp(caller, kCallerAINotify) == 0)
	{
		AppContext appContext(((SPInterfaceMessage *)message)->d.self);

		// Ideally we would rely upon the caller to envelop our Notify method.
		// But since we won't work right if he doesn't, do this ourselves

		AINotifierMessage *msg = (AINotifierMessage *)message;

		if (strcmp(msg->type, kAIApplicationStartedNotifier) == 0)
			error = PostStartupPlugin();

		if (!error || error == kUnhandledMsgErr)
		{
			if (strcmp( selector, kSelectorAINotify ) == 0)
				error = Notify(msg);
		}
	}
	else if (strcmp(caller, kActionCaller) == 0)
	{
		if (strcmp( selector, kDoActionSelector ) == 0)
		{
			/*
			char *my_argv[] = { "program name", "arg1", "arg2", NULL };
			int my_argc = sizeof(my_argv) / sizeof(char*) - 1;

			QApplication a(my_argc, my_argv);
			MyQTUI w;
			w.show();
			a.exec();*/
			error = GoAction((DoActionMessage *)message);
		}
	}
	else if (strcmp(caller, kCallerAIMenu) == 0)
	{
		if (strcmp( selector, kSelectorAIGoMenuItem ) == 0)
		{
			//sAIUser->MessageAlert(ai::UnicodeString("GoMenuItem"));
			error = GoMenuItem((AIMenuMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIUpdateMenuItem ) == 0)
		{
			//sAIUser->MessageAlert(ai::UnicodeString("UpdateMenuItem"));
			error = UpdateMenuItem((AIMenuMessage *)message);
		}
	}
	else if (strcmp(caller, kCallerAIFilter) == 0)
	{
		if (strcmp( selector, kSelectorAIGetFilterParameters ) == 0)
		{
			error = GetFilterParameters((AIFilterMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIGoFilter ) == 0)
		{
			error = GoFilter((AIFilterMessage *)message);
		}
	}
	else if (strcmp(caller, kCallerAIPluginGroup) == 0)
	{
		if (strcmp( selector, kSelectorAINotifyEdits ) == 0)
		{
			error = PluginGroupNotify((AIPluginGroupMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIUpdateArt ) == 0)
		{
			error = PluginGroupUpdate((AIPluginGroupMessage *)message);
		}
	}
	else if (strcmp(caller, kCallerAIFileFormat) == 0)
	{
		if (strcmp( selector, kSelectorAIGetFileFormatParameters ) == 0)
		{
			error = GetFileFormatParameters((AIFileFormatMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIGoFileFormat ) == 0)
		{
			error = GoFileFormat((AIFileFormatMessage *)message);
		}
		else if (strcmp( selector, kSelectorAICheckFileFormat ) == 0)
		{
			error = CheckFileFormat((AIFileFormatMessage *)message);
		}
		else if ( strcmp( selector, kSelectorAIUpdateFileFormat ) == 0 )
		{
			error = FileFormatUpdate( (AIUpdateFileFormatMessage *)message );
		}
		else if (!strcmp( selector, kDoActionSelector))
		{
			error = SetFileFormatParameters( (DoActionMessage *) message );
		}
	}
	else if (strcmp(caller, kCallerAITool) == 0)
	{
		if (strcmp( selector, kSelectorAIEditToolOptions ) == 0)
		{
			error = EditTool((AIToolMessage *)message);
		}
		else if (strcmp( selector, kSelectorAITrackToolCursor ) == 0)
		{
			error = TrackToolCursor((AIToolMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIToolMouseDown ) == 0)
		{
			error = ToolMouseDown((AIToolMessage *)message);
			sAIUser->MessageAlert(ai::UnicodeString("Mouse down"));
		}
		else if (strcmp( selector, kSelectorAIToolMouseDrag ) == 0)
		{
			error = ToolMouseDrag((AIToolMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIToolMouseUp ) == 0)
		{
			sAIUser->MessageAlert(ai::UnicodeString("Mouse up"));
			//error = ToolMouseUp((AIToolMessage *)message);
		}
		else if (strcmp( selector, kSelectorAISelectTool ) == 0)
		{
			error = SelectTool((AIToolMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIDeselectTool ) == 0)
		{
			error = DeselectTool((AIToolMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIReselectTool ) == 0)
		{
			error = ReselectTool((AIToolMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIToolDecreaseDiameter ) == 0)
		{
			error = DecreaseDiameter((AIToolMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIToolIncreaseDiameter ) == 0)
		{
			error = IncreaseDiameter((AIToolMessage *)message);
		}
		

	} else if (strcmp(caller, kCallerAILiveEffect ) == 0)
	{
		if (strcmp( selector, kSelectorAIEditLiveEffectParameters ) == 0)
		{
			error = EditLiveEffectParameters((AILiveEffectEditParamMessage *)message);
		}
		else if (strcmp( selector, kSelectorAIGoLiveEffect ) == 0)
		{
			error = GoLiveEffect((AILiveEffectGoMessage *)message);
		}
		else if (strcmp( selector, kSelectorAILiveEffectInterpolate ) == 0)
		{
			error = LiveEffectInterpolate((AILiveEffectInterpParamMessage *)message);
		}
		else if (strcmp( selector, kSelectorAILiveEffectInputType ) == 0)
		{
			error = LiveEffectGetInputType((AILiveEffectInputTypeMessage *)message);
		}
		else if (strcmp( selector, kSelectorAILiveEffectScaleParameters ) == 0)
		{
			error = LiveEffectScaleParameters((AILiveEffectScaleParamMessage *)message);
		}
		else if (strcmp( selector, kSelectorAILiveEffectConverColorSpace ) == 0)
		{
			error = LiveEffectConvertColorSpace((AILiveEffectConvertColorMessage *)message);
		}
		else if (strcmp( selector, kSelectorAILiveEffectAdjustColors ) == 0)
		{
			error = LiveEffectAdjustColors((AILiveEffectAdjustColorsMessage *)message);
		}
		else if (strcmp( selector, kSelectorAILiveEffectHandleMerge ) == 0)
		{
			error = LiveEffectHandleMerge((AILiveEffectHandleMergeMessage *)message);
		}
	} else if (strcmp(caller, kCallerAITimer ) == 0)
	{
		if (strcmp( selector, kSelectorAIGoTimer ) == 0)
		{
			error = GoTimer((AITimerMessage *)message);
		}
	}
	else if (strcmp(caller, kCallerAIClipboard ) == 0)
	{
		if ( strcmp( selector, kSelectorAIGoClipboard ) == 0 )
			error = GoClipboard( (AIClipboardMessage *) message );

		else if ( strcmp( selector, kSelectorAICanCopyClipboard ) == 0 )
			error = CanCopyClipboard( (AIClipboardMessage *) message );

		else if ( strcmp( selector, kSelectorAICloneClipboard ) == 0 )
			error = CloneClipboard( (AIClipboardMessage *) message );

		else if ( strcmp( selector, kSelectorAIDisposeClipboard ) == 0 )
			error = DisposeClipboard( (AIClipboardMessage *) message );
	}
	else if (strcmp(caller, kAIWorkspaceCaller ) == 0)
	{
		if ( strcmp( selector, kAIWSWriteSelector ) == 0 )
			error = WorkspaceWrite( (AIWorkspaceMessage *) message );

		else if ( strcmp( selector, kAIWSRestoreSelector ) == 0 )
			error = WorkspaceRestore( (AIWorkspaceMessage *) message );

		else if ( strcmp( selector, kAIWSDefaultSelector ) == 0 )
			error = WorkspaceDefault( (AIWorkspaceMessage *) message );
	}
	return error;
}
Example #27
0
DWORD CImplRepairVul::_ThreadFuncInstallImpl()
{
	T_ComInit _init_com_;
	while(!m_bCanceled)
	{
		WaitForSingleObject(m_thinfo.m_hInstallEvent,INFINITE);
		if(m_thinfo.nInstallIndex>=m_arrDownloadItem.GetSize())
		{
			if(m_thinfo.isDownloadDone) // 如果文件已经下载结束 
				break;
			else 
				continue;
		}
		
		BOOL bLastInstallSuccess = FALSE;
		for( int i=m_thinfo.nInstallIndex;i<m_arrDownloadItem.GetSize() && !m_bCanceled;i++)
		{
			T_RepairItem &item = m_arrDownloadItem[i];
			if(item.stateDownload==-1)
				break;
			if(item.stateInstalled!=-1) // 已经安装了 
				continue;
			
			if(!bLastInstallSuccess)
				FixUpdateGarbage();

			m_thinfo.nInstallIndex = i + 1;
			if(item.stateDownload)
			{
				CString strFileName = item.strFilename;
				CString strInstallParam = item.strInstallParam;
#ifdef _DEBUG
				strInstallParam = _T("");
#endif
				_FixSystemRootSpecialPath( item );
				
				BOOL bUserPatcher = FALSE;
				E_InstalledResult res_inst = EINST_FAIL;
				DWORD dwExitCode = 0;
				INT userPatchCode = -1;
				BOOL disableCOM = ( item.type==VTYPE_SOFTLEAK && item.bDisableCOM );		
				Notify(EVulfix_InstallBegin, item.nID, i, m_thinfo.totalNum);	
				if( disableCOM )
				{
					if( m_pCurrentVulfix )
					{
						m_pCurrentVulfix->EnableVulCOM( item.nID, false );
						res_inst = EINST_SUCCESS;
					}
				}
				else
				{
					BOOL bHijacked = FALSE;
					if( !ExecuteFile(strFileName, strInstallParam, dwExitCode, bHijacked) )
						res_inst = EINST_FAIL_EXECUTE;
					else
					{
						BOOL exactInstalled = ERROR_SUCCESS_REBOOT_REQUIRED==dwExitCode || ERROR_SUCCESS_REBOOT_INITIATED==dwExitCode;
						if(!exactInstalled && item.type==VTYPE_OFFICE)
							 exactInstalled = 17025==dwExitCode;

						if( exactInstalled )
							res_inst = EINST_SUCCESS;
						else if( 0x80240017==dwExitCode )
						{
							// Vista 的未找到产品
							// Office 的未找到产品错误码 
							res_inst = EINST_FAIL_NOT_APPLICABLE;
						}
						else
						{
							if(dwExitCode==0)
								res_inst = EINST_SUCCESS_CHECK_FAILED;

							BOOL bMeetCondition = TRUE, bFoundInRegistry = FALSE;

							// 检测条件是否还继续满足 
							if( !item.strCondtion.IsEmpty() )
								bMeetCondition = EvaluateCondition( item.strCondtion );
							CSysEnv& sysEnv = singleton<CSysEnv>::Instance();
							if( item.type==VTYPE_OFFICE||item.type==VTYPE_SOFTLEAK )
							{
								// Office, Software 的检查注册表, 确认安装成功 
								if (sysEnv.m_WinVer >= WINVISTA)
								{
									CWUAUpdateInfoVistaLaterReg vs;
									vs.Init(0);
									bFoundInRegistry = vs.IsUpdateInstalled( item.nID );
								}
								else
								{
									CWUAUpdateInfoXP xp;
									xp.Init(0);
									bFoundInRegistry = xp.IsUpdateInstalled( item.nID );
								}
							}

							BOOL bInstalledCombined = !bMeetCondition || bFoundInRegistry;							
							if(bInstalledCombined)
							{
								res_inst = EINST_SUCCESS_CHECKED;
							}
							else
							{
								if(item.type==VTYPE_OFFICE) // 对office进行自定义安装
								{
									bUserPatcher = TRUE;
									Notify( EVulfix_InstallBeginUser, item.nID, i, dwExitCode);
									userPatchCode = _UserPatch(item);
									if(KPATCHER_OK==userPatchCode)
										res_inst = EINST_SUCCESS;
									else
									{
										res_inst = EINST_FAIL;	// 可能被360 拦截?? 然后就只能忽略了?? 不进行智能忽略!!
										//if(dwExitCode==17031) // 智能忽略
										//	res_inst = EINST_FAIL_NOT_APPLICABLE;
									}				
								}
								else if(item.type==VTYPE_SOFTLEAK)
								{
									if(bMeetCondition)
										res_inst = EINST_FAIL;
								}
							}

							LPCTSTR szFilename = _tcsrchr(strFileName, _T('\\'));
							SHOWMSG(_T("Installed Result: VulType:%d ExitCode:%08x(%d) \
									   \r\nConditionCheck:%d InReg:%d UserPatch:%d(%d)\
									   \r\nInstRes:%d(%d)(Exact:%d)  InstRes2:%d\
									   \r\nFile: %s \r\n")
									   , item.type, dwExitCode, dwExitCode, bMeetCondition, bFoundInRegistry, item.bUserPatcher, userPatchCode, res_inst, res_inst<=EINST_SUCCESS_CHECK_FAILED, exactInstalled, bInstalledCombined, szFilename+1);

							if(res_inst!=EINST_SUCCESS_CHECKED && res_inst!=EINST_SUCCESS)
							{
								if(bHijacked)
									res_inst = EINST_FAIL_HIJACKED;
							}
						}
					}
				}
				if( res_inst==EINST_FAIL_NOT_APPLICABLE )
				{
					m_objIgnore.AutoIgnore(item.nID, TRUE);
					m_objIgnore.SaveIgnoreDB();
				}

				BOOL bInstalled = res_inst<=EINST_SUCCESS_CHECK_FAILED;
				item.stateInstalled = res_inst;
				if( bInstalled )
					++ m_thinfo.nInstSuccess;
				if(bUserPatcher && !bInstalled && userPatchCode==KPATCHER_ERR_FILEBUSY)
					res_inst = EINST_FAIL_FILEBUSY;
				Notify( bInstalled ? EVulfix_InstallEnd : EVulfix_InstallError, item.nID, res_inst, bUserPatcher ? userPatchCode : dwExitCode);

				// 通知WUA 已经被修改了, 使得 Vista 的话, 需要重新的去扫描IUpdate 接口
				if( bInstalled && !disableCOM )
				{
					CWUAUpdateInfoVistaLater &wuaInfo = singleton<CWUAUpdateInfoVistaLater>::Instance();
					wuaInfo.SetWUAModified();
				}
				bLastInstallSuccess = bInstalled;
			}
		}
		
		if( m_bCanceled )
			break; 
		
		if( m_thinfo.isDownloadDone 
			&& m_thinfo.nInstallIndex>=(m_arrDownloadItem.GetSize()-1) )
		{			
			Notify( m_thinfo.totalNum==m_thinfo.nDownSuccess && m_thinfo.nDownSuccess==m_thinfo.nInstSuccess ? EVulfix_Task_Complete : EVulfix_Task_Error, 0, 0, 0);
			break;
		}
	}
Example #28
0
/* Will we need this in the future?
void NotifyFailSetConfDescr(uint8_t reason) {
        NotifyFailSetConfDescr();
        NotifyFail(reason);
}
*/
void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID) {
        Notify(PSTR("\r\nUnknown Device Connected - VID: "), 0x80);
        D_PrintHex<uint16_t > (VID, 0x80);
        Notify(PSTR(" PID: "), 0x80);
        D_PrintHex<uint16_t > (PID, 0x80);
}
uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
    uint8_t	buf[sizeof(USB_DEVICE_DESCRIPTOR)];
	uint8_t	rcode;
	UsbDevice *p = NULL;
	EpInfo *oldep_ptr = NULL;
    uint16_t PID;
    uint16_t VID;
    
    // get memory address of USB device address pool
	AddressPool	&addrPool = pUsb->GetAddressPool();    
#ifdef EXTRADEBUG
	Notify(PSTR("\r\nPS3USB Init"));
#endif
    // check if address has already been assigned to an instance
    if (bAddress) {
#ifdef DEBUG
        Notify(PSTR("\r\nAddress in use"));
#endif
        return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
    }
    
    // Get pointer to pseudo device with address 0 assigned
    p = addrPool.GetUsbDevicePtr(0);
    
    if (!p) {        
#ifdef DEBUG
	    Notify(PSTR("\r\nAddress not found"));
#endif
        return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
    }
    
    if (!p->epinfo) {
#ifdef DEBUG
        Notify(PSTR("\r\nepinfo is null"));
#endif
        return USB_ERROR_EPINFO_IS_NULL;
    }
    
    // Save old pointer to EP_RECORD of address 0
    oldep_ptr = p->epinfo;
    
    // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
    p->epinfo = epInfo;
    
    p->lowspeed = lowspeed;
    
    // Get device descriptor
    rcode = pUsb->getDevDescr(0, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);// Get device descriptor - addr, ep, nbytes, data
    // Restore p->epinfo
    p->epinfo = oldep_ptr;
    
    if(rcode)
        goto FailGetDevDescr;
    
    VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
    PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
    
    if(VID != PS3_VID || (PID != PS3_PID &&  PID != PS3NAVIGATION_PID && PID != PS3MOVE_PID))
        goto FailUnknownDevice;        
    
    // Allocate new address according to device class
    bAddress = addrPool.AllocAddress(parent, false, port);
    
    if (!bAddress)
		return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
    
    // Extract Max Packet Size from device descriptor
    epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; 
    
    // Assign new address to the device
    rcode = pUsb->setAddr( 0, 0, bAddress );
    if (rcode) {
        p->lowspeed = false;
        addrPool.FreeAddress(bAddress);
        bAddress = 0;
#ifdef DEBUG
        Notify(PSTR("\r\nsetAddr: "));
#endif
        PrintHex<uint8_t>(rcode);
        return rcode;
    }
#ifdef EXTRADEBUG
    Notify(PSTR("\r\nAddr: "));
    PrintHex<uint8_t>(bAddress);
#endif
    p->lowspeed = false;
    
    //get pointer to assigned address record
    p = addrPool.GetUsbDevicePtr(bAddress);
    if (!p) 
        return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
    
    p->lowspeed = lowspeed;        
    
    // Assign epInfo to epinfo pointer - only EP0 is known
    rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
    if (rcode)
        goto FailSetDevTblEntry;
    
                    
    /* The application will work in reduced host mode, so we can save program and data
       memory space. After verifying the PID and VID we will use known values for the
       configuration values for device, interface, endpoints and HID for the PS3 Controllers */
        
    /* Initialize data structures for endpoints of device */
    epInfo[ PS3_OUTPUT_PIPE ].epAddr = 0x02;    // PS3 output endpoint
    epInfo[ PS3_OUTPUT_PIPE ].epAttribs  = EP_INTERRUPT;
    epInfo[ PS3_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
    epInfo[ PS3_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
    epInfo[ PS3_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0;
    epInfo[ PS3_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
    epInfo[ PS3_INPUT_PIPE ].epAddr = 0x01;    // PS3 report endpoint
    epInfo[ PS3_INPUT_PIPE ].epAttribs  = EP_INTERRUPT;
    epInfo[ PS3_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
    epInfo[ PS3_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
    epInfo[ PS3_INPUT_PIPE ].bmSndToggle = bmSNDTOG0;
    epInfo[ PS3_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
        
    rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
    if( rcode )
        goto FailSetDevTblEntry;
        
    delay(200);//Give time for address change
        
    rcode = pUsb->setConf(bAddress, epInfo[ PS3_CONTROL_PIPE ].epAddr, 1);
    if( rcode )
        goto FailSetConf;
        
    if(PID == PS3_PID || PID == PS3NAVIGATION_PID) {
        if(PID == PS3_PID) {
#ifdef DEBUG
            Notify(PSTR("\r\nDualshock 3 Controller Connected"));
#endif                
            PS3Connected = true;
        } else { // must be a navigation controller
#ifdef DEBUG
            Notify(PSTR("\r\nNavigation Controller Connected"));
#endif
            PS3NavigationConnected = true;
        }
        /* Set internal bluetooth address and request for data */
        setBdaddr(my_bdaddr);
        enable_sixaxis();
        setLedOn(LED1);
            
        // Needed for PS3 Dualshock and Navigation commands to work
        for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
            writeBuf[i] = pgm_read_byte(&PS3_REPORT_BUFFER[i]);
            
        for (uint8_t i = 6; i < 10; i++)
            readBuf[i] = 0x7F; // Set the analog joystick values to center position
    }
    else  { // must be a Motion controller
#ifdef DEBUG
        Notify(PSTR("\r\nMotion Controller Connected"));
#endif                         
        PS3MoveConnected = true;
        setMoveBdaddr(my_bdaddr); // Set internal bluetooth address
        moveSetBulb(Red);
            
        // Needed for Move commands to work
        for (uint8_t i = 0; i < MOVE_REPORT_BUFFER_SIZE; i++)
            writeBuf[i] = pgm_read_byte(&MOVE_REPORT_BUFFER[i]);
    }

    bPollEnable = true;
    Notify(PSTR("\r\n"));
    timer = millis();
    return 0; // successful configuration
    
    /* diagnostic messages */  
FailGetDevDescr:
#ifdef DEBUG
    Notify(PSTR("\r\ngetDevDescr:"));
#endif
    goto Fail;    
FailSetDevTblEntry:
#ifdef DEBUG
    Notify(PSTR("\r\nsetDevTblEn:"));
#endif
    goto Fail;
FailSetConf:
#ifdef DEBUG
    Notify(PSTR("\r\nsetConf:"));
#endif
    goto Fail; 
FailUnknownDevice:
#ifdef DEBUG
    Notify(PSTR("\r\nUnknown Device Connected - VID: "));
    PrintHex<uint16_t>(VID);
    Notify(PSTR(" PID: "));
    PrintHex<uint16_t>(PID);
#endif
    rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
    goto Fail;
Fail:
#ifdef DEBUG
    Notify(PSTR("\r\nPS3 Init Failed, error code: "));
    Serial.print(rcode,HEX);
#endif    
    Release();
    return rcode;
}
Example #30
0
/*****************************************************************************
 * ItemChange: Playlist item change callback
 *****************************************************************************/
static int ItemChange( vlc_object_t *p_this, const char *psz_var,
                       vlc_value_t oldval, vlc_value_t newval, void *param )
{
    VLC_UNUSED(psz_var); VLC_UNUSED(oldval); VLC_UNUSED(newval);
    char           psz_tmp[MAX_LENGTH];
    char           psz_notify[MAX_LENGTH];
    char           *psz_title;
    char           *psz_artist;
    char           *psz_album;
    char           *psz_arturl;
    input_thread_t *p_input = playlist_CurrentInput( (playlist_t*)p_this );
    intf_thread_t  *p_intf  = param;
    intf_sys_t     *p_sys   = p_intf->p_sys;

    if( !p_input )
        return VLC_SUCCESS;

    if( p_input->b_dead )
    {
        /* Not playing anything ... */
        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }

    /* Wait a tad so the meta has been fetched
     * FIXME that's awfully wrong */
    msleep( 10000 );

    /* Playing something ... */
    input_item_t *p_input_item = input_GetItem( p_input );
    psz_title = input_item_GetTitleFbName( p_input_item );

    /* We need at least a title */
    if( EMPTY_STR( psz_title ) )
    {
        free( psz_title );
        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }

    psz_artist = input_item_GetArtist( p_input_item );
    psz_album = input_item_GetAlbum( p_input_item );

    if( !EMPTY_STR( psz_artist ) )
    {
        if( !EMPTY_STR( psz_album ) )
            snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s\n[%s]",
                      psz_title, psz_artist, psz_album );
        else
            snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s",
                      psz_title, psz_artist );
    }
    else
        snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>", psz_title );

    free( psz_title );
    free( psz_artist );
    free( psz_album );

    GdkPixbuf *pix = NULL;
    psz_arturl = input_item_GetArtURL( p_input_item );
    vlc_object_release( p_input );

    if( psz_arturl )
    {
        char *psz = make_path( psz_arturl );
        free( psz_arturl );
        psz_arturl = psz;
    }

    if( psz_arturl )
    { /* scale the art to show it in notify popup */
        GError *p_error = NULL;
        pix = gdk_pixbuf_new_from_file_at_scale( psz_arturl,
                                                 72, 72, TRUE, &p_error );
    }
    else /* else we show state-of-the art logo */
    {
        /* First try to get an icon from the current theme. */
        GtkIconTheme* p_theme = gtk_icon_theme_get_default();
        pix = gtk_icon_theme_load_icon( p_theme, "vlc", 72, 0, NULL);

        if( !pix )
        {
        /* Load icon from share/ */
            GError *p_error = NULL;
            char *psz_pixbuf;
            char *psz_data = config_GetDataDir();
            if( asprintf( &psz_pixbuf, "%s/icons/48x48/vlc.png", psz_data ) >= 0 )
            {
                pix = gdk_pixbuf_new_from_file( psz_pixbuf, &p_error );
                free( psz_pixbuf );
            }
            free( psz_data );
        }
    }

    free( psz_arturl );

    /* we need to replace '&' with '&amp;' because '&' is a keyword of
     * notification-daemon parser */
    const int i_len = strlen( psz_tmp );
    int i_notify = 0;
    for( int i = 0; i < i_len && i_notify < ( MAX_LENGTH - 5 ); i++ )
    { /* we use MAX_LENGTH - 5 because if the last char of psz_tmp is '&'
       * we will need 5 more characters: 'amp;\0' .
       * however that's unlikely to happen because the last char is '\0' */
        if( psz_tmp[i] != '&' )
        {
            psz_notify[i_notify] = psz_tmp[i];
        }
        else
        {
            strcpy( &psz_notify[i_notify], "&amp;" );
            i_notify += 4;
        }
        i_notify++;
    }
    psz_notify[i_notify] = '\0';

    vlc_mutex_lock( &p_sys->lock );

    Notify( p_this, psz_notify, pix, p_intf );

    vlc_mutex_unlock( &p_sys->lock );

    return VLC_SUCCESS;
}