[363] | 1 | /*
|
---|
| 2 | * TOPPERS/JSP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Just Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | *
|
---|
| 9 | * ä¸è¨èä½æ¨©è
|
---|
| 10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 11 | * ã«ãã£ã¦å
|
---|
| 12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 15 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 21 | * ç¨ã§ããå½¢ã§åé
|
---|
| 22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 24 | * è
|
---|
| 25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 30 | * ã¨ï¼
|
---|
| 31 | * (a) åé
|
---|
| 32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 34 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 35 | * (b) åé
|
---|
| 36 | å¸ã®å½¢æ
|
---|
| 37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 38 | * å ±åãããã¨ï¼
|
---|
| 39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 40 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 42 | 責ãããã¨ï¼
|
---|
| 43 | *
|
---|
| 44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ã
|
---|
| 46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 49 | *
|
---|
| 50 | * @(#) $Id: jsp_common.cpp,v 1.4 2003/12/20 06:51:58 takayuki Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | #include "jsp/jsp_common.h"
|
---|
| 54 |
|
---|
| 55 | #include "base/option.h"
|
---|
| 56 |
|
---|
| 57 | #include <ctime>
|
---|
| 58 |
|
---|
| 59 | #if defined(_MSC_VER) || defined(__BORLANDC__)
|
---|
| 60 | # define GETLOGINNAME_WINDOWS
|
---|
| 61 | # include <windows.h>
|
---|
| 62 | #elif __GNUC__
|
---|
| 63 | # define GETLOGINNAME_UNIX
|
---|
| 64 | # include <unistd.h>
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 | using namespace std;
|
---|
| 68 |
|
---|
| 69 | #if 0
|
---|
| 70 | namespace {
|
---|
| 71 | string get_loginname(void) throw()
|
---|
| 72 | {
|
---|
| 73 | string result("TOPPERS/JSP KernelConfigurator");
|
---|
| 74 |
|
---|
| 75 | #ifdef GETLOGINNAME_WINDOWS
|
---|
| 76 | char buffer[1024];
|
---|
| 77 | DWORD sz = 1024;
|
---|
| 78 | ::GetUserName(buffer, &sz);
|
---|
| 79 | result.assign(buffer);
|
---|
| 80 | #elif defined(GETLOGINNAME_UNIX)
|
---|
| 81 | result.assign(getlogin());
|
---|
| 82 | #endif
|
---|
| 83 |
|
---|
| 84 | return result;
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | #endif
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | //ã¤ã³ã¯ã«ã¼ããã¡ã¤ã«ã®å½¢ãå¤æ´ãã
|
---|
| 91 | string ToppersJsp::conv_includefile(string file) throw()
|
---|
| 92 | {
|
---|
| 93 | OptionParameter & option = getOptionParameter();
|
---|
| 94 | string result;
|
---|
| 95 |
|
---|
| 96 | //ilãªãã·ã§ã³ãä»ããã¨ãã«ã¯ "<...>" å½¢å¼ã§åºå
|
---|
| 97 | if(option["il"].isValid())
|
---|
| 98 | result = string("<") + file + ">";
|
---|
| 99 | else
|
---|
| 100 | result = string("\"") + file + "\"";
|
---|
| 101 |
|
---|
| 102 | return result;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | //ã«ã¼ãã«ã®å¤æ°åã®å½¢ãå¤æ´ãã
|
---|
| 106 | string ToppersJsp::conv_kernelobject(string obj) throw()
|
---|
| 107 | {
|
---|
| 108 | OptionParameter & option = getOptionParameter();
|
---|
| 109 | string result;
|
---|
| 110 |
|
---|
| 111 | result = obj;
|
---|
| 112 |
|
---|
| 113 | // TOPPERS/JSP rel 1.3ããå¾ã¯ã«ã¼ãã«å¤æ°ã®é ã« _kernel_ ãã¤ãã
|
---|
| 114 | if(!option["1.3"].isValid())
|
---|
| 115 | result = string("_kernel_") + obj;
|
---|
| 116 |
|
---|
| 117 | return result;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | ToppersJsp::SpecialtyFile::SpecialtyFile(void) throw() : MultipartStream(), RuntimeObject(true)
|
---|
| 121 | {}
|
---|
| 122 |
|
---|
| 123 | #if 0
|
---|
| 124 | string ToppersJsp::get_agreement(string filename) throw()
|
---|
| 125 | {
|
---|
| 126 | const char * base_agreement =
|
---|
| 127 | "/*\n"
|
---|
| 128 | " * TOPPERS/JSP Kernel\n"
|
---|
| 129 | " * Toyohashi Open Platform for Embedded Real-Time Systems/\n"
|
---|
| 130 | " * Just Standard Profile Kernel\n"
|
---|
| 131 | " * \n"
|
---|
| 132 | " * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory\n"
|
---|
| 133 | " * Toyohashi Univ. of Technology, JAPAN\n"
|
---|
| 134 | " * \n"
|
---|
| 135 | " * ä¸è¨èä½æ¨©è
|
---|
| 136 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation \n"
|
---|
| 137 | " * ã«ãã£ã¦å
|
---|
| 138 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨\n"
|
---|
| 139 | " * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢\n"
|
---|
| 140 | " * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 141 | å¸ï¼ä»¥ä¸ï¼\n"
|
---|
| 142 | " * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼\n"
|
---|
| 143 | " * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½\n"
|
---|
| 144 | " * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼\n"
|
---|
| 145 | " * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼\n"
|
---|
| 146 | " * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿\n"
|
---|
| 147 | " * ç¨ã§ããå½¢ã§åé
|
---|
| 148 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 149 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨\n"
|
---|
| 150 | " * è
|
---|
| 151 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨\n"
|
---|
| 152 | " * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼\n"
|
---|
| 153 | " * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿\n"
|
---|
| 154 | " * ç¨ã§ããªãå½¢ã§åé
|
---|
| 155 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã\n"
|
---|
| 156 | " * ã¨ï¼\n"
|
---|
| 157 | " * (a) åé
|
---|
| 158 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 159 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è\n"
|
---|
| 160 | " * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼\n"
|
---|
| 161 | " * (b) åé
|
---|
| 162 | å¸ã®å½¢æ
|
---|
| 163 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«\n"
|
---|
| 164 | " * å ±åãããã¨ï¼\n"
|
---|
| 165 | " * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ\n"
|
---|
| 166 | " * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 167 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 168 | 責ãããã¨ï¼\n"
|
---|
| 169 | " * \n"
|
---|
| 170 | " * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 171 | ã\n"
|
---|
| 172 | " * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã\n"
|
---|
| 173 | " * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´\n"
|
---|
| 174 | " * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼\n"
|
---|
| 175 | " * \n";
|
---|
| 176 |
|
---|
| 177 | string work(base_agreement);
|
---|
| 178 |
|
---|
| 179 | //CVSã®ID風ã®ãã®ããã£ã¤ãã
|
---|
| 180 | time_t t;
|
---|
| 181 | time(&t);
|
---|
| 182 |
|
---|
| 183 | work += string(" * @(#)$Id: ");
|
---|
| 184 | work += filename;
|
---|
| 185 | work += " ";
|
---|
| 186 | work += static_cast<const char *>(asctime(localtime(&t)));
|
---|
| 187 |
|
---|
| 188 | work.erase(work.size() - 1); //asctimeã§æ¹è¡ãå
|
---|
| 189 | ¥ãã®ã§chomp
|
---|
| 190 |
|
---|
| 191 | work += " ";
|
---|
| 192 | work += get_loginname();
|
---|
| 193 | work += " Exp $\n */\n\n";
|
---|
| 194 |
|
---|
| 195 | return work;
|
---|
| 196 | }
|
---|
| 197 | #endif
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | /***************************************** ãã¹ãã¹ã£ã¼ã *****************************************/
|
---|
| 201 |
|
---|
| 202 | #ifdef TESTSUITE
|
---|
| 203 |
|
---|
| 204 | class SpecialtyFile_test : public ToppersJsp::SpecialtyFile
|
---|
| 205 | {
|
---|
| 206 | public:
|
---|
| 207 | ~SpecialtyFile_test(void) throw() { TestSuite::check("SpecialtyFile::~SpecialtyFile"); }
|
---|
| 208 | TESTSUITE_PROTOTYPE(main)
|
---|
| 209 | };
|
---|
| 210 |
|
---|
| 211 | TESTSUITE(main, SpecialtyFile_test)
|
---|
| 212 | {
|
---|
| 213 | BEGIN_CASE("constructor","constructor") {
|
---|
| 214 | BEGIN_CASE("1","çæããã¨ROTã«ä¹ã") {
|
---|
| 215 | SpecialtyFile_test file;
|
---|
| 216 |
|
---|
| 217 | if(RuntimeObjectTable::getInstance<SpecialtyFile_test>() == 0)
|
---|
| 218 | TEST_FAIL;
|
---|
| 219 | } END_CASE;
|
---|
| 220 |
|
---|
| 221 | BEGIN_CASE("2","ç ´æ£ã®å¯¾è±¡ã«ãªã£ã¦ãã") {
|
---|
| 222 | Singleton<RuntimeObjectTable>::Context context;
|
---|
| 223 | Singleton<RuntimeObjectTable>::saveContext(context);
|
---|
| 224 |
|
---|
| 225 | Singleton<RuntimeObjectTable>::renewInstance();
|
---|
| 226 |
|
---|
| 227 | new SpecialtyFile_test;
|
---|
| 228 |
|
---|
| 229 | TEST_CASE("0","[åæ] ç»é²ããã¦ãã", RuntimeObjectTable::getInstance<SpecialtyFile_test>() != 0);
|
---|
| 230 |
|
---|
| 231 | TestSuite::clearCheckpoints();
|
---|
| 232 | Singleton<RuntimeObjectTable>::renewInstance(); //ã¤ã³ã¹ã¿ã³ã¹ã®åçæã§ROTãåé¤ããã
|
---|
| 233 |
|
---|
| 234 | TEST_CASE("1","ROTãã解é¤ããã¦ãã", RuntimeObjectTable::getInstance<SpecialtyFile_test>() == 0);
|
---|
| 235 | TEST_CASE("2","ãã¹ãã©ã¯ã¿ãèµ·åããã¦ãã", TestSuite::isReached("SpecialtyFile::~SpecialtyFile"));
|
---|
| 236 |
|
---|
| 237 | Singleton<RuntimeObjectTable>::restoreContext(context);
|
---|
| 238 | } END_CASE;
|
---|
| 239 | } END_CASE;
|
---|
| 240 |
|
---|
| 241 | BEGIN_CASE("createInstance","createInstance") {
|
---|
| 242 | BEGIN_CASE("1","ã¤ã³ã¹ã¿ã³ã¹ãçæã§ãã") {
|
---|
| 243 | SpecialtyFile_test * file = SpecialtyFile::createInstance<SpecialtyFile_test>("test.txt");
|
---|
| 244 |
|
---|
| 245 | file->disableOutput(); //åºåããã¦ãå°ãã®ã§
|
---|
| 246 |
|
---|
| 247 | TEST_CASE("1","éNULLãè¿ã", file != 0);
|
---|
| 248 | TEST_CASE("2","ãã¡ã¤ã«åãæ£å¸¸", file->getFilename().compare("test.txt") == 0);
|
---|
| 249 | } END_CASE;
|
---|
| 250 |
|
---|
| 251 | BEGIN_CASE("2","空æåã渡ãã¨ä¾å¤") {
|
---|
| 252 |
|
---|
| 253 | bool result = false;
|
---|
| 254 | try {
|
---|
| 255 | SpecialtyFile::createInstance<SpecialtyFile_test>("");
|
---|
| 256 | }
|
---|
| 257 | catch(Exception &) {
|
---|
| 258 | result = true;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | TEST_CASE("1","ä¾å¤ãèµ·ãã", result);
|
---|
| 262 | TEST_CASE("2","ãªãã¸ã§ã¯ãã¯ãªã", RuntimeObjectTable::getInstance<SpecialtyFile_test>() == 0);
|
---|
| 263 | } END_CASE;
|
---|
| 264 | } END_CASE;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | namespace {
|
---|
| 268 | extern void testsuite(TestSuiteControl & _suite_control);
|
---|
| 269 | TestSuite testsuite_onTop("TOPPERS/JSP Common Function(main)", testsuite);
|
---|
| 270 |
|
---|
| 271 | //ãã¹ãã¹ã£ã¼ãã®æ¬ä½
|
---|
| 272 | void testsuite(TestSuiteControl & _suite_control)
|
---|
| 273 | {
|
---|
| 274 | Singleton<OptionParameter>::Context context;
|
---|
| 275 | Singleton<OptionParameter>::saveContext(context);
|
---|
| 276 |
|
---|
| 277 | BEGIN_CASE("conv_includefile","conv_includefile") {
|
---|
| 278 | BEGIN_CASE("1","-ilãä»ãã¦ããªãã¨ããã«ã¯ã©ã¼ãã§ããã") {
|
---|
| 279 | Singleton<OptionParameter>::renewInstance();
|
---|
| 280 |
|
---|
| 281 | if(ToppersJsp::conv_includefile("test.h").compare("\"test.h\"") != 0)
|
---|
| 282 | TEST_FAIL;
|
---|
| 283 | } END_CASE;
|
---|
| 284 |
|
---|
| 285 | BEGIN_CASE("1","-ilãä»ãã¦ããã¨<>ã§ããã") {
|
---|
| 286 | Singleton<OptionParameter>::renewInstance();
|
---|
| 287 | char * argv[] = {"test.exe","-il"};
|
---|
| 288 | getOptionParameter().parseOption(2, argv);
|
---|
| 289 |
|
---|
| 290 | if(ToppersJsp::conv_includefile("test.h").compare("<test.h>") != 0)
|
---|
| 291 | TEST_FAIL;
|
---|
| 292 | } END_CASE;
|
---|
| 293 | } END_CASE;
|
---|
| 294 |
|
---|
| 295 | BEGIN_CASE("conv_kernelobject","conv_kernelobject") {
|
---|
| 296 | BEGIN_CASE("1","-1.3ãä»ãã¦ããªãã¨_kernel_ãä»ã") {
|
---|
| 297 | Singleton<OptionParameter>::renewInstance();
|
---|
| 298 |
|
---|
| 299 | if(ToppersJsp::conv_kernelobject("test").compare("_kernel_test") != 0)
|
---|
| 300 | TEST_FAIL;
|
---|
| 301 | } END_CASE;
|
---|
| 302 |
|
---|
| 303 | BEGIN_CASE("1","-1.3ãä»ãã¦ããã¨ãã®ã¾ã¾åºã¦ãã") {
|
---|
| 304 | Singleton<OptionParameter>::renewInstance();
|
---|
| 305 | char * argv[] = {"test.exe","-1.3"};
|
---|
| 306 | getOptionParameter().parseOption(2, argv);
|
---|
| 307 |
|
---|
| 308 | if(ToppersJsp::conv_kernelobject("test").compare("test") != 0)
|
---|
| 309 | TEST_FAIL;
|
---|
| 310 | } END_CASE;
|
---|
| 311 | } END_CASE;
|
---|
| 312 |
|
---|
| 313 | Singleton<OptionParameter>::restoreContext(context);
|
---|
| 314 |
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 | #endif
|
---|
| 318 |
|
---|
| 319 |
|
---|