Пример #1
0
void TorrentCreator::WriteHashToDatabase(void)
{
    TRACE( "Start updating bt_generator_maininfo database\n" );

    CTime currentTime = CTime::GetCurrentTime();
    m_pIPData->SetCreationTime( (time_t)currentTime.GetTime() );

    DBInterface db;
    string torrentfilename = m_pIPData->GetTorrentFileName();
    db.OpenConnection(IP_BITTORRENT_DATABASE, "onsystems", "ebertsux37", "bittorrent_data");

    char aQuery[1024];
    sprintf( aQuery, "UPDATE bt_generator_maininfo SET info_hash = '%s', generate='F', creation_date = %s WHERE auto_torrent_id = %u",
             GetHashString(m_pIPData->GetInfohash()).c_str(), currentTime.Format( "%Y%m%d%H%M%S" ), m_pIPData->GetTorrentID() );
    int ret = db.executeQuery(aQuery);

    TRACE( "Done updating bt_generator_maininfo database\n" );
}
Пример #2
0
//
// send a message to a message handler through message pump
DWORD CToolBox::SendMessage(DWORD msg, DWORD size, void *data, 
		IHashString *name, IHashString *compType)
{
#if defined _PROFILE || defined _DEBUG
	
	// Check if the message is in the map
	PROFILERMESSAGECOUNTMAP::iterator itr;
	itr = m_MessageProfileMap.find( msg );
	if (itr != m_MessageProfileMap.end())
	{
		// If it is then increment the count
		(itr->second)++;
	}
	else
	{
		// otherwise add it
		m_MessageProfileMap.insert( pair<DWORD,int>(msg,1) );
	}

#endif // _PROFILE

	bool bMsgHandledOnce = false;
	MSGPUMPMAP::iterator mplIter;
	MSGPUMPFUNC mpFunc;
	IComponent *comp;
	DWORD retVal;
	MSGIDHANDLERMAP::iterator mihmIter;
	MSGPRIORITYMAP *msgPriorityMap;
	MSGPRIORITYMAP::iterator mlIter;
	MSGHANDLER *msgHandler;
	MSGPUMP *msgPump;

	retVal = MSG_NOT_HANDLED;

	// get list of message handler for this particlar message
	mihmIter = m_MsgHandlers.find(msg);
	if (mihmIter == m_MsgHandlers.end())
	{
		return MSG_NOT_HANDLED;
	}

	// grab the map of messages
	msgPriorityMap = mihmIter->second;

	// grab msg pump filter
	COMPTYPETOMSGPUMPMAP::iterator itrComponentFilter; 
	bool bFilter = false;
	if( compType != NULL )
	{
		itrComponentFilter = m_CompTypeToMsgPumpMap.find( compType->GetUniqueID() );
		if( itrComponentFilter != m_CompTypeToMsgPumpMap.end() )
		{
			bFilter = true;
		}
	}

	// Loop though map of message handlers that respond to this message
	for (mlIter = msgPriorityMap->begin(); mlIter != msgPriorityMap->end(); ++mlIter)
	{
		msgHandler = &mlIter->second;
		retVal = MSG_NOT_HANDLED;

		// Check to see if this is going to a Singleton, skip pumphandlers if true
		bool bToSingleton = ( (compType != NULL) && (m_ComponentsGet.find(compType->GetUniqueID()) != m_ComponentsGet.end()) );
		// we can't send the message to message pumps if name is NULL & compType is NULL
		if (!bToSingleton && ((name != NULL) || (compType != NULL)))
		{
			// and if Component type is NULL or if it matches, then we can send
			if ((compType == NULL) || (*compType == *msgHandler->m_ClassName))
			{
				// iterate through the message pumps and send message
				for (mplIter = m_MsgPumps.begin(); mplIter != m_MsgPumps.end();
						++mplIter)
				{
					msgPump = &mplIter->second;
					// get the component that handles this message pump
					comp = msgPump->m_Comp;
					// get the function pointer
					mpFunc = msgPump->m_MsgPumpFunc;

					// If the MsgPump has a ComponentFilter, we want to check to make sure the compType matches up
					if( (msgPump->m_bComponentFilter) && (bFilter) )
					{
						// Check ComponentMap for MsgPump
						MSGPUMPSET::iterator itrMsgPump = itrComponentFilter->second.find( msgPump->m_Comp->GetComponentType()->GetUniqueID() );
						if( itrMsgPump == itrComponentFilter->second.end() )
						{
							continue;
						}
					}

					// call the function and see if the message was handled
					retVal = (comp->*mpFunc)(size, data, name, 
						msgHandler->m_ClassName, msgHandler->m_MsgFunc);

					// if anything but not handled
					if (retVal != MSG_NOT_HANDLED)
					{
						// ok, check if possible error or performance issue and log as warning
						// this is triggered if user doesn't specify compType
						if ((compType == NULL) && (!msgPump->m_bHierarchical))
						{
							Log(LOGWARNING, _T("Message %s sent to %s, without component type %s\n")
								_T("  Can cause performance or conflict errors\n"),
								GetHashString(msg), name->GetString(), 
								msgHandler->m_ClassName->GetString());
						}

						// switch MSG_HANDLED_XX to MSG_HANDLED and return on anything but proceed
						if (retVal != MSG_HANDLED_PROCEED)
						{
							if (retVal == MSG_HANDLED_STOP)
								retVal = MSG_HANDLED;

							return retVal;
						}
						else
						{
							// Message is handled by at least one pump handler...
							retVal = MSG_HANDLED;
							// ...lets make note of this
							bMsgHandledOnce = true;
						}
					}
				}
			}
		}


		// if the msg was not handled by any of the specific message
		// pumps it must be a singleton and use general message pump
		if (retVal == MSG_NOT_HANDLED)
		{
			// get the component
			COMPONENTCREATEFUNC *getFunc;
			COMPONENTMAP::iterator cmIter;
			IComponent *theComponent;

			// if the componentType is null, use all components with registered
			// message handler
			if ((compType == NULL) || (*compType == *msgHandler->m_ClassName))
			{
				IHashString *className = msgHandler->m_ClassName;
				// ok, let's call the class's get function if available
				cmIter = m_ComponentsGet.find(className->GetUniqueID());
				// hmm, this error happens, if component registers message handler
				// but doesn't have a get routine, which means they are not a singleton
				if (cmIter != m_ComponentsGet.end())
				{
					getFunc = cmIter->second;
					assert(getFunc != NULL);

					theComponent = (*getFunc)(0, NULL);
					assert(theComponent != NULL);

					// send the message to the handler
					retVal = (theComponent->*msgHandler->m_MsgFunc)(size, data);
					// return on error or MSG_HANDLED_STOP
					/*
					if ((retVal != MSG_HANDLED_PROCEED) && (retVal != MSG_NOT_HANDLED))
					{
						// switch MSG_HANDLED_XX to MSG_HANDLED
						if (retVal == MSG_HANDLED_STOP)
							retVal = MSG_HANDLED;
						return retVal;
					}
					*/
					if (retVal != MSG_NOT_HANDLED)
					{
						// switch MSG_HANDLED_XX to MSG_HANDLED and return on anything but proceed
						if (retVal != MSG_HANDLED_PROCEED)
						{
							if (retVal == MSG_HANDLED_STOP)
								retVal = MSG_HANDLED;

							return retVal;
						}
						else
						{
							retVal = MSG_HANDLED;
							// ...lets make note of this
							bMsgHandledOnce = true;
						}
					}
				}
				else
				{
//					SetErrorValue(WARN_OBJECT_NOT_FOUND);
//					Log(LOGWARNING, _T("Unable to send global message to non-singleton object %s\n"),
//						(TCHAR *)msgHandler->m_ClassName->GetString());
				}
			}
		}
	}

	// switch MSG_HANDLED_XX to MSG_HANDLED
	if ((retVal == MSG_HANDLED_PROCEED) || (retVal == MSG_HANDLED_STOP) || bMsgHandledOnce)
		retVal = MSG_HANDLED;

#ifdef VERBOSE_MESSAGE_WARNINGS
	if (retVal == MSG_NOT_HANDLED)
	{
		const TCHAR *szName = (name == NULL) ? _T("NULL") : name->GetString();
		const TCHAR *szCompName = (compType == NULL) ? _T("NULL") : compType->GetString();
		Log(LOGWARNING, _T("Message %s sent to %s of type %s, was not handled by anyone\n"),
				GetHashString(msg), szName, szCompName);
	}
#endif

	return retVal;
}