📄 stdafx.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
*
* 忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation
* 偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
* 弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
* 傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
* 棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
* (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
* 尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
* 僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
* (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
* 幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
* 偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
* 偲丏
* (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
* 嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
* 曬崘偡傞偙偲丏
* (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
* 奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
*
* 杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
* 傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
* 娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
* 愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
*
* @(#) $Id: stdafx.cpp,v 1.9 2003/06/30 15:58:39 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"
#include "kernellog.h"
using namespace std;
#ifdef _DEBUG
DWORD Count;
char Buffer[1024];
#define DebugOut(x) ::WriteFile(::GetStdHandle(STD_OUTPUT_HANDLE),Buffer, (x), &Count, NULL)
#else
#define DebugOut(x) /##/
#endif
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 = false;
list<CDevice *>::iterator scope;
list<CInformation *>::iterator view;
list<CKernelLog *>::iterator watcher;
DebugOut(::wsprintfA(Buffer,"AttachKernel\n"));
::EnterCriticalSection(&cs);
if((Kernel != 0) && (Kernel != kernel))
{
//妱崬傒-1 => 僇乕僱儖偺KeepAlive
if(FAILED(Kernel->Fire_OnInterruptRequest(-1)))
{
//愙懕傪幐偭偨僇乕僱儖偺僨僞僢僠
DetachKernel(Kernel);
}else
{
//愙懕嵪傒僇乕僱儖偑偁傞
if(::MessageBox(NULL,_T("怴偟偄僇乕僱儖偑婲摦偝傟丄僨僶僀僗儅僱乕僕儍偵愙懕偟傛偆偲偟偰偄傑偡丅\n怴偟偄僇乕僱儖偵愙懕愭傪愗傝懼偊傑偡偐?"),_T("TOPPERS/JSP Windows - DeviceManager"),MB_YESNO) == IDYES)
DetachKernel(Kernel);
}
}
if(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 ++;
}
watcher = WatcherList.begin();
while(watcher != WatcherList.end())
{
(*watcher)->Fire_OnKernelStart();
watcher ++;
}
DebugOut(::wsprintfA(Buffer,"AttachKernel was performed successfully\n"));
result = true;
}
::LeaveCriticalSection(&cs);
return result;
}
bool CExeModule::DetachKernel(CKernel *kernel)
{
bool result;
list<CDevice *>::iterator scope;
list<CInformation *>::iterator view;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -