⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stdafx.cpp

📁 嵌入式系统开发 TOPPERS and JSP Kernel Release 1.3 TOPPERS = Toyohashi Open Platform for Embedded Real-Tim
💻 CPP
字号:
/* *  TOPPERS/JSP Kernel *      Toyohashi Open Platform for Embedded Real-Time Systems/ *      Just Standard Profile Kernel *  *  Copyright (C) 2000-2002 by Embedded and Real-Time Systems Laboratory *                              Toyohashi Univ. of Technology, JAPAN *  *  惧淡螟侯涪荚は·Free Software Foundation によって给山されている  *  GNU General Public License の Version 2 に淡揭されている掘凤か·笆 *  布の(1)×(4)の掘凤を塔たす眷圭に嘎り·塑ソフトウェア∈塑ソフトウェ *  アを猖恃したものを崔むˉ笆布票じ∷を蝗脱ˇ剩澜ˇ猖恃ˇ浩芹邵∈笆布· *  网脱と钙ぶ∷することを痰浸で钓满するˉ *  (1) 塑ソフトウェアをソ〖スコ〖ドの妨で网脱する眷圭には·惧淡の螟侯 *      涪山绩·この网脱掘凤および布淡の痰瘦沮惮年が·そのままの妨でソ〖 *      スコ〖ド面に崔まれていることˉ *  (2) 塑ソフトウェアを浩网脱材墙なバイナリコ〖ド∈リロケ〖タブルオブ *      ジェクトファイルやライブラリなど∷の妨で网脱する眷圭には·网脱 *      に燃うドキュメント∈网脱荚マニュアルなど∷に·惧淡の螟侯涪山绩· *      この网脱掘凤および布淡の痰瘦沮惮年を非很することˉ *  (3) 塑ソフトウェアを浩网脱稍材墙なバイナリコ〖ドの妨または怠达に寥 *      み哈んだ妨で网脱する眷圭には·肌のいずれかの掘凤を塔たすことˉ *    (a) 网脱に燃うドキュメント∈网脱荚マニュアルなど∷に·惧淡の螟侯 *        涪山绩·この网脱掘凤および布淡の痰瘦沮惮年を非很することˉ *    (b) 网脱の妨轮を·侍に年める数恕によって·惧淡螟侯涪荚に鼠桂する *        ことˉ *  (4) 塑ソフトウェアの网脱により木儡弄または粗儡弄に栏じるいかなる禄 *      巢からも·惧淡螟侯涪荚を倘勒することˉ *  *  塑ソフトウェアは·痰瘦沮で捏丁されているものであるˉ惧淡螟侯涪荚は· *  塑ソフトウェアに簇して·その努脱材墙拉も崔めて·いかなる瘦沮も乖わ *  ないˉまた·塑ソフトウェアの网脱により木儡弄または粗儡弄に栏じたい *  かなる禄巢に簇しても·その勒扦を砷わないˉ *  *  @(#) $Id: stdafx.cpp,v 1.3 2002/04/10 11:27:26 takayuki Exp $ *//* * デバイスマネ〖ジャ 塑挛(CExeModule) */#pragma warning(disable:4786)#include "stdafx.h"#ifdef _ATL_STATIC_REGISTRY#include <statreg.h>#include <statreg.cpp>#endif#include <atlimpl.cpp>#include <algorithm>#include <initguid.h>#include "devicemanager.h"#include "device.h"#include "kernel.h"#include "information.h"using namespace std;DWORD Count;char Buffer[1024];#define DebugOut(x) ::WriteFile(::GetStdHandle(STD_OUTPUT_HANDLE),Buffer, (x), &Count, NULL)CExeModule::CExeModule(void) : Kernel(0){	::InitializeCriticalSection(&cs);}DeviceID CExeModule::AddDevice(CDevice *device){	list<CDevice *>::iterator scope;	list<CInformation *>::iterator view;	::EnterCriticalSection(&cs);	scope = find(DeviceList.begin(), DeviceList.end(), device);	if(scope != DeviceList.end())	{		::LeaveCriticalSection(&cs);		return 0;	}	DebugOut(::wsprintfA(Buffer,"AddDevice\n"));	view = ViewerList.begin();	while(view != ViewerList.end())	{		(*view)->Fire_OnDeviceChanged(1,reinterpret_cast<long>(device));		view ++;	}	DeviceList.push_back(device);	::LeaveCriticalSection(&cs);	return reinterpret_cast<DeviceID>(device);}bool CExeModule::DeleteDevice(CDevice *device){	list<CDevice *>::iterator dev;	map<Range,CDevice *>::iterator mem[2];	::EnterCriticalSection(&cs);	DebugOut(::wsprintfA(Buffer,"DelDevice\n"));	dev = find(DeviceList.begin(), DeviceList.end(), device);	if(dev == DeviceList.end())	{		::LeaveCriticalSection(&cs);		return false;	}	mem[0] = DeviceMap.begin();	while(mem[0] != DeviceMap.end())	{		if((*mem[0]).second == device)		{			mem[1] = mem[0];			mem[0] ++;			DeviceMap.erase(mem[1]);		}else			mem[0] ++;	}	DeviceList.erase(dev);	list<CInformation *>::iterator view;	view = ViewerList.begin();	while(view != ViewerList.end())	{		(*view)->Fire_OnDeviceChanged(2,reinterpret_cast<long>(device));		view ++;	}	::LeaveCriticalSection(&cs);	return true;}bool CExeModule::Map(CDevice *device, Range area){	map<Range,CDevice *>::iterator scope;	::EnterCriticalSection(&cs);		scope = DeviceMap.begin();	while(scope != DeviceMap.end())	{		if( area.IsIncludedIn((*scope).first) )		{			::LeaveCriticalSection(&cs);			return false;		}		scope ++;	}	DeviceMap[area] = device;	DebugOut(::wsprintfA(Buffer,"Map\n"));	list<CInformation *>::iterator view;	view = ViewerList.begin();	while(view != ViewerList.end())	{		(*view)->Fire_OnDeviceChanged(3,reinterpret_cast<long>(device),area.GetBase());		view ++;	}	::LeaveCriticalSection(&cs);	return true;}bool CExeModule::Unmap(CDevice *device, unsigned long address){	map<Range,CDevice *>::iterator scope;	Range work(address);	::EnterCriticalSection(&cs);	scope = DeviceMap.begin();	while(scope != DeviceMap.end())	{		if( (*scope).second == device && work.IsIncludedIn((*scope).first) )		{			DeviceMap.erase(scope);			DebugOut(::wsprintfA(Buffer,"Unmap\n"));			list<CInformation *>::iterator view;			view = ViewerList.begin();			while(view != ViewerList.end())			{				(*view)->Fire_OnDeviceChanged(4,reinterpret_cast<long>(device),address);				view ++;			}			::LeaveCriticalSection(&cs);			return true;		}		scope ++;	}	::LeaveCriticalSection(&cs);	return false;}void CExeModule::AddViewer(CInformation *view){	list<CInformation *>::iterator scope;	::EnterCriticalSection(&cs);	scope = find(ViewerList.begin(), ViewerList.end(), view);	if(scope == ViewerList.end())		ViewerList.push_back(view);	::LeaveCriticalSection(&cs);}void CExeModule::RemoveViewer(CInformation *view){	list<CInformation *>::iterator scope;	::EnterCriticalSection(&cs);	scope = find(ViewerList.begin(), ViewerList.end(), view);	if(scope != ViewerList.end())		ViewerList.erase(scope);	::LeaveCriticalSection(&cs);}bool CExeModule::AttachKernel(CKernel *kernel){	bool result;	list<CDevice *>::iterator scope;	list<CInformation *>::iterator view;	DebugOut(::wsprintfA(Buffer,"AttachKernel\n"));	::EnterCriticalSection(&cs);	if( (result = Kernel == 0) )	{		Kernel = kernel;		scope = DeviceList.begin();		while(scope != DeviceList.end())		{			(*scope)->Fire_OnKernelStart();			scope ++;		}		view = ViewerList.begin();		while(view != ViewerList.end())		{			(*view)->Fire_OnKernelChanged(1);			view ++;		}	}	::LeaveCriticalSection(&cs);	return result;}bool CExeModule::DetachKernel(CKernel *kernel){	bool result;	list<CDevice *>::iterator scope;	list<CInformation *>::iterator view;	DebugOut(::wsprintfA(Buffer,"DetachKernel\n"));	::EnterCriticalSection(&cs);	if( (result = Kernel == kernel) )	{		scope = DeviceList.begin();		while(scope != DeviceList.end())		{			(*scope)->Fire_OnKernelExit();			scope ++;		}		view = ViewerList.begin();		while(view != ViewerList.end())		{			(*view)->Fire_OnKernelChanged(2);			view ++;		}		Kernel = 0l;	}	::LeaveCriticalSection(&cs);	return result;}bool CExeModule::Read(CKernel * kernel, unsigned long address, unsigned long sz, unsigned char data[]){	bool result;	map<Range,CDevice *>::iterator scope;	DebugOut(::wsprintfA(Buffer,"Read\n"));	::EnterCriticalSection(&cs);	if(Kernel != kernel)	{		::LeaveCriticalSection(&cs);		DebugOut(::wsprintfA(Buffer,"Illegal Kernel\n"));				return false;	}	scope = DeviceMap.find(Range(address,sz));		result = (scope != DeviceMap.end());	if(result)		(*scope).second->Fire_OnRead(address, sz, data);	::LeaveCriticalSection(&cs);	return result;}bool CExeModule::Write(CKernel *kernel, unsigned long address, unsigned long sz, unsigned char *data){	bool result;	map<Range,CDevice *>::iterator scope;	DebugOut(::wsprintfA(Buffer,"Write\n"));	::EnterCriticalSection(&cs);	if(Kernel != kernel)	{		::LeaveCriticalSection(&cs);		DebugOut(::wsprintfA(Buffer,"Illegal Kernel\n"));		return false;	}	scope = DeviceMap.find(Range(address,sz));		result = (scope != DeviceMap.end());	if(result)	{		DebugOut(::wsprintfA(Buffer,"FireWrite\n"));		(*scope).second->Fire_OnWrite(address, sz,data);	}	::LeaveCriticalSection(&cs);	return result;}bool CExeModule::RaiseInterrupt(unsigned long inhno){	bool result = false;	::EnterCriticalSection(&cs);	if(Kernel != 0 && Kernel->Fire_OnInterruptRequest(inhno) >= 0)		result = true;	::LeaveCriticalSection(&cs);	return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -