Example #1
0
// [public] Quesries the type of interface of this object.
HRESULT CClassFactory::QueryInterface(REFIID riid, void **ppInterface)
{
	LOG_APPEND("--- CClassFactory::QueryInterface ---");


	if (riid == IID_IUnknown)
	{
		LOG_APPEND("--- IID_Unknown ---");
		*ppInterface = static_cast<IUnknown *>(this);
	}
	else if (riid == IID_IClassFactory)
	{
		LOG_APPEND("--- IID_IClassFactory ---");
		*ppInterface = static_cast<IClassFactory *>(this);                		
	}
	else
	{
		*ppInterface = NULL;
		return E_NOINTERFACE;
	}

	reinterpret_cast<IUnknown *>(*ppInterface)->AddRef();

	return S_OK;
}
Example #2
0
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID FAR *ppv)
{
	LOG_INIT();
	LOG_APPEND("------ DllGetClassObject -----");
	CClassFactory *pClassFactory;
	const COCLASS_REGISTER *pCoClass;
	HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;

	// scan for the right one
	for (pCoClass = g_CoClasses; pCoClass->pClsid != NULL; pCoClass++)
	{
		if (*pCoClass->pClsid == rclsid)
		{
			pClassFactory = new CClassFactory(pCoClass);
			if (pClassFactory != NULL)
			{
				hr = pClassFactory->QueryInterface(riid, ppv);

				pClassFactory->Release();
				break;
			}
			else
			{
				hr = E_OUTOFMEMORY;
				break;
			}
		}
	}

	return hr;
}
Example #3
0
void mtt::FileTransfer::handshakeFinished(PeerCommunication* p)
{
	LOG_APPEND("handshake " << p->getAddressName());
	if (!torrent->files.progress.empty())
		p->sendBitfield(torrent->files.progress.toBitfield());

	addPeer(p);
}
Example #4
0
void mtt::FileTransfer::messageReceived(PeerCommunication* p, PeerMessage& msg)
{
	LOG_APPEND("msg " << msg.id << " " << p->getAddressName());

	if (msg.id == Piece)
	{
		LOG_APPEND("piece " << msg.piece.info.index << " " << msg.piece.info.begin << " " << p->getAddressName());

		auto status = downloader.pieceBlockReceived(msg.piece);

		std::lock_guard<std::mutex> guard(peersMutex);
		downloader.removeBlockRequests(activePeers, msg.piece, status, p);

		if (auto peer = getActivePeer(p))
		{
			peer->downloaded += msg.piece.info.length;
			peer->lastActivityTime = (uint32_t)time(0);
		}
	}
	else if (msg.id == Unchoke)
	{
		std::lock_guard<std::mutex> guard(peersMutex);
		if (auto peer = getActivePeer(p))
		{
			downloader.evaluateNextRequests(peer);
			peer->lastActivityTime = (uint32_t)time(0);
		}
	}
	else if (msg.id == Interested)
	{
		uploader.isInterested(p);
	}
	else if (msg.id == Request)
	{
		if (uploader.pieceRequest(p, msg.request))
		{
			std::lock_guard<std::mutex> guard(peersMutex);
			if (auto peer = getActivePeer(p))
				peer->uploaded += msg.request.length;
		}
	}
}
Example #5
0
void ASTConsumer::AddClassDecl(clang::NamedDecl* decl, const std::string& name, const std::string& parent_name)
{
	// Cast to a record (NOTE: CXXRecord is a temporary clang type and will change in future revisions)
	clang::CXXRecordDecl* record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(decl);
	assert(record_decl != 0 && "Failed to cast to record declaration");

	// Check for forward-declared types
	bool forward_decl = false;
	if (record_decl->isThisDeclarationADefinition() == clang::VarDecl::DeclarationOnly)
	{
		//
		// This classification of CXXRecord also comes through the AST like so:
		//
		//    namespace ns
		//    {
		//        class ClassName { };
		//    }
		//
		//    CXXRecord ns::ClassName
		//       CXXRecord ns::ClassName::ClassName
		//       CXXConstructor ns::ClassName::ClassName
		//
		// So before every constructor of a class, there's a superfluous CXX declaration of the same name.
		// Not sure why it's here, however the "free standing" flag is documented in the code to mark
		// these cases:
		//
		//    namespace ns
		//    {
		//       class ClassName;
		//    }
		//
		//    CXXRecord ns::ClassName
		//
		// And these are the exact cases that represent a reflected forward-declaration!
		//

		if (!record_decl->isFreeStanding())
			return;
		forward_decl = true;
	}

	// Ignore classes with virtual bases
	if (!forward_decl && record_decl->getNumVBases())
	{
		Status().Print(record_decl->getLocation(), m_ASTContext.getSourceManager(), va("Class '%s' has an unsupported virtual base class", name.c_str()));
		return;
	}

	// Name gets added to the database if it's not already there
	cldb::Name type_name = m_DB.GetName(name.c_str());

	// Parse base classes
	std::vector<cldb::Name> base_names;
	if (!forward_decl && record_decl->getNumBases())
	{
		for (clang::CXXRecordDecl::base_class_const_iterator base_it = record_decl->bases_begin(); base_it != record_decl->bases_end(); base_it++)
		{
			cldb::Name base_name;
			Status status = ParseBaseClass(*this, type_name, *base_it, base_name);
			if (status.HasWarnings())
			{
				status.Print(record_decl->getLocation(), m_ASTContext.getSourceManager(), va("Failed to reflect class '%s'", name.c_str()));
				return;
			}

			// If the base class is valid, then add the inheritance relationship
			m_DB.AddTypeInheritance(type_name, base_name);
			base_names.push_back(base_name);
		}
	}

	if (record_decl->isAnonymousStructOrUnion())
	{
		// Add declarations to the parent
		const clang::ASTRecordLayout& layout = m_ASTContext.getASTRecordLayout(record_decl);
		AddContainedDecls(decl, parent_name, &layout);
	}
	else
	{
		LOG(ast, INFO, "class %s", name.c_str());

		// Ensure there's at least an empty class definition in the database for this name
		cldb::Class* class_ptr = m_DB.GetFirstPrimitive<cldb::Class>(name.c_str());
		if (class_ptr == nullptr)
		{
			bool is_class = record_decl->getTagKind() == clang::TTK_Class;
			m_DB.AddPrimitive(cldb::Class(m_DB.GetName(name.c_str()), m_DB.GetName(parent_name.c_str()), is_class));
			class_ptr = m_DB.GetFirstPrimitive<cldb::Class>(name.c_str());
		}

		if (!forward_decl)
		{
			// Fill in the missing class size
			const clang::ASTRecordLayout& layout = m_ASTContext.getASTRecordLayout(record_decl);
			class_ptr->size = layout.getSize().getQuantity();

			for (size_t i = 0; i < base_names.size(); i++)
				LOG_APPEND(ast, INFO, (i == 0) ? " : %s" : ", %s", base_names[i].text.c_str());
			LOG_NEWLINE(ast);

			// Populate class contents
			AddContainedDecls(decl, name, &layout);
		}

		else
		{
			// Forward-declaration log
			LOG_NEWLINE(ast);
		}
	}
}
Example #6
0
void mtt::FileTransfer::connectionClosed(PeerCommunication* p, int code)
{
	LOG_APPEND("closed " << p->getAddressName());
	removePeer(p);
}