📄 manager.cpp
字号:
/*
* TOPPERS/JSP Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* Just Standard Profile Kernel
*
* Copyright (C) 2000-2003 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: manager.cpp,v 1.1 2006/04/14 02:46:05 9564907 Exp $
*/
// $Header: J:\\SapporoSoft\\usb20\\S1R72V05\\Debug\\Repository/S1R72V05_Toppers/Toppers/cfg/base/manager.cpp,v 1.1 2006/04/14 02:46:05 9564907 Exp $
#ifdef _MSC_VER
# pragma warning(disable:4786)
# define CDECL __cdecl
#else
# define CDECL
#endif
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include "base/event.h"
#include "base/message.h"
#include "base/component.h"
#include "base/directorymap.h"
using namespace std;
Event<StartupEvent> startupEvent;
Event<ShutdownEvent> shutdownEvent;
int CDECL main(int argc, char ** argv)
{
ShutdownEvent evt;
OptionParameter & option= getOptionParameter();
evt.exit_code = EXIT_FAILURE;
if(SingletonBase::isValid() && Component::isValid()) {
option.parseOption(argc, argv, "-h");
try {
startupEvent.raise();
Component::executeComponents(option);
evt.exit_code = EXIT_SUCCESS;
}
catch(Exception & e)
{
cerr << Message("Program failed in its process by following reason.\n","僾儘僌儔儉偼抳柦揑側僄儔乕偵傛傝拞抐偝傟傑偟偨.\n");
cerr << " " << e.getDetails() << '\n';
}
catch(ExceptionMessage & e) {
CHECKPOINT("catch(ExceptionMessage)");
cerr << "Program failed : " << e << '\n';
}
catch(bad_alloc & e) {
CHECKPOINT("catch(bad_alloc)");
cerr << "Program failed : bad_alloc (" << e.what() << ")\n";
}
catch(...) {
CHECKPOINT("catch(...)");
cerr << "Program filed : Unknown Exception Occured\n";
}
}
else
cerr << "Program initialization failure\n";
try {
DebugMessage("shutdown event - exitcode(%)\n") << evt.exit_code;
shutdownEvent.raise(evt);
}
catch(Exception & e)
{
DebugMessage("exception was raised in the event - %\n") << e.getDetails();
cerr << Message("Program failed in its process by following reason.\n","僾儘僌儔儉偼抳柦揑側僄儔乕偵傛傝拞抐偝傟傑偟偨.\n");
cerr << " " << e.getDetails() << '\n';
}
catch(...) {
DebugMessage("exception was raised in the event\n");
CHECKPOINT("catch(...) in shutdownEvent::raise");
evt.exit_code = EXIT_FAILURE;
}
DebugMessage("Exit code (%)\n") << evt.exit_code;
return evt.exit_code;
}
/************************************* 僥僗僩僗傿乕僩 *************************************/
#ifdef TESTSUITE
#include "coverage_undefs.h"
namespace {
extern void testsuite(TestSuiteControl & _suite_control);
TestSuite testsuite_onTop("Entrypoint(main)", testsuite);
class TestComponent : public Component
{
public:
int mode;
void parseOption(OptionParameter &)
{
switch(mode) {
case 0:
CHECKPOINT("TestComponent::case 0");
break;
case 1:
ExceptionMessage("exception").throwException();
case 2:
throw bad_alloc();
}
}
};
void dummyStartupHandler(StartupEvent &)
{
TestSuite::check("dummyStartupHandler");
}
int dummyShutdownHandler_exit_code;
void dummyShutdownHandler(ShutdownEvent & evt)
{
dummyShutdownHandler_exit_code = evt.exit_code;
TestSuite::check("dummyShutdownHandler");
}
//僥僗僩僗傿乕僩偺杮懱
void testsuite(TestSuiteControl & _suite_control)
{
SingletonBase::ContextChain chain;
chain.saveContext<Component::ComponentInfo>();
chain.saveContext<Event<StartupEvent>::handler_list_type>();
chain.saveContext<Event<ShutdownEvent>::handler_list_type>();
BEGIN_CASE("1","main娭悢扨懱 + 僐儞億乕僱儞僩側偟") {
chain.renewInstance();
Event<StartupEvent>::add(dummyStartupHandler);
Event<ShutdownEvent>::add(dummyShutdownHandler);
BEGIN_CASE("1","晛捠偵幚峴偡傞") {
TestSuite::clearCheckpoints();
char * argv[] = { "test.exe" };
Exception::setThrowControl(true);
TestComponent test;
test.mode = 0;
TEST_CASE("1","main娭悢偼EXIT_SUCCESS傪曉偡", main(1, argv) == EXIT_SUCCESS);
TEST_CASE("2","椺奜偑幚峴偝傟側偄 catch(Exception)", !TestSuite::isReached("catch(Exception)"));
TEST_CASE("3","椺奜偑幚峴偝傟側偄 catch(bad_alloc)", !TestSuite::isReached("catch(bad_alloc)"));
TEST_CASE("4","椺奜偑幚峴偝傟側偄 catch(...)", !TestSuite::isReached("catch(...)"));
TEST_CASE("5","Component偑幚峴偝傟偰偄傞", TestSuite::isReached("TestComponent::case 0"));
TEST_CASE("6","僗僞乕僩傾僢僾僴儞僪儔偑婲摦偝傟偰偄傞", TestSuite::isReached("dummyStartupHandler"));
TEST_CASE("7","僔儍僢僩僟僂儞僴儞僪儔偑婲摦偝傟偰偄傞", TestSuite::isReached("dummyShutdownHandler"));
TEST_CASE("8","僔儍僢僩僟僂儞僴儞僪儔偼EXIT_SUCCESS傪庴偗偰偄傞", dummyShutdownHandler_exit_code == EXIT_SUCCESS);
} END_CASE;
BEGIN_CASE("2","Exception椺奜傪曉偡") {
TestSuite::clearCheckpoints();
char * argv[] = { "test.exe" };
Exception::setThrowControl(true);
TestComponent test;
test.mode = 1;
TEST_CASE("1","main娭悢偼EXIT_FAILURE傪曉偡", main(1, argv) == EXIT_FAILURE);
TEST_CASE("2","椺奜偑幚峴偝傟傞 catch(Exception)", TestSuite::isReached("catch(Exception)"));
TEST_CASE("3","椺奜偑幚峴偝傟側偄 catch(bad_alloc)", !TestSuite::isReached("catch(bad_alloc)"));
TEST_CASE("4","椺奜偑幚峴偝傟側偄 catch(...)", !TestSuite::isReached("catch(...)"));
TEST_CASE("5","僗僞乕僩傾僢僾僴儞僪儔偑婲摦偝傟偰偄傞", TestSuite::isReached("dummyStartupHandler"));
TEST_CASE("6","僔儍僢僩僟僂儞僴儞僪儔偑婲摦偝傟偰偄傞", TestSuite::isReached("dummyShutdownHandler"));
TEST_CASE("7","僔儍僢僩僟僂儞僴儞僪儔偼EXIT_FAILURE傪庴偗偰偄傞", dummyShutdownHandler_exit_code == EXIT_FAILURE);
} END_CASE;
BEGIN_CASE("3","bad_alloc椺奜傪曉偡") {
TestSuite::clearCheckpoints();
char * argv[] = { "test.exe" };
Exception::setThrowControl(true);
TestComponent test;
test.mode = 2;
TEST_CASE("1","main娭悢偼EXIT_FAILURE傪曉偡", main(1, argv) == EXIT_FAILURE);
TEST_CASE("2","懳墳偡傞catch偺傒偑幚峴偝傟偰偄傞", !TestSuite::isReached("catch(Exception)") && TestSuite::isReached("catch(bad_alloc)") && !TestSuite::isReached("catch(...)"));
TEST_CASE("3","僗僞乕僩傾僢僾僴儞僪儔偑婲摦偝傟偰偄傞", TestSuite::isReached("dummyStartupHandler"));
TEST_CASE("4","僔儍僢僩僟僂儞僴儞僪儔偑婲摦偝傟偰偄傞", TestSuite::isReached("dummyShutdownHandler"));
TEST_CASE("5","僔儍僢僩僟僂儞僴儞僪儔偼EXIT_FAILURE傪庴偗偰偄傞", dummyShutdownHandler_exit_code == EXIT_FAILURE);
} END_CASE;
} END_CASE;
chain.restoreContext();
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -