- Timestamp:
- 12/13/01 17:25:49 (23 years ago)
- Location:
- trunk/MagicSoft/Control/SubsystemIO
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Control/SubsystemIO/Subsystem.plain.hxx
r1054 r1113 219 219 220 220 221 221 ///////////////////////////////////////////////////////////////////////// 222 //////////////// IMPLEMENTATION DETAILS ///////////////////////////////// 223 ///////////////////////////////////////////////////////////////////////// 224 225 //we implement commandListener as a TCPListener derived class, to be 226 //able to custom the behaviour by overriding it's methods, namely 227 //process, which is called when something arrives. 228 //This could be though as inheritance for implementation, which is not 229 //desired. Can be avoided by using signals/slots 222 230 private: 223 231 /** … … 225 233 */ 226 234 char* ccName; 235 227 236 /** 228 237 * Aproximate (+- 500ms) time in microsec, between each report is sent 229 * to CC 238 * to CC. 239 * It is expressed in microsec, despite the big uncertanty in these 240 * units, because is feed directly to usleep. This should be changed at 241 * least to ms: remember then to multiply per 1000 in usleep. Take care 242 * also with long periods: usleep will accept only long int 230 243 */ 231 244 unsigned long int reportPeriod; 232 245 246 /** 247 * TCP/IP port for commandListener socket, here at subsystem machine 248 */ 233 249 unsigned short int portCommandListener; 250 251 /** 252 * TCP/IP port for reportListener socket in CC machine 253 */ 234 254 unsigned short int portReportListener; 235 255 236 //we implement commandListener as a TCPListener derived class, to be237 //able to custom the behaviour by overriding it's methods, namely238 //process239 256 240 257 /* maxTimeoutCount. Times subsystem tries to reconnect CC (with reportPeriod) … … 251 268 short int maxTimeoutCount; 252 269 253 270 /** 271 * If locked == true Subsystem is being commanded by CC. 272 */ 254 273 bool locked; 274 275 /** 276 * When REPOR received, reporting = true, and thread 277 * ReportingAndCheckingLoop is started 278 */ 255 279 bool reporting; 280 /** 281 * mutex used to prevent that while reporting state is being checked 282 * in ReportingAndCheckingLoop thread, connection closing is detected 283 * in TCPListener thread and reporting is set at the same time. 284 * 285 * I'm not sure if really needed 286 */ 256 287 pthread_mutex_t mutex4reporting; 288 /** 289 * Accessor function for reporting bool variable that takes care of 290 * properly locking the resource 291 */ 257 292 inline bool Reporting(){ 258 293 pthread_mutex_lock(&mutex4reporting); … … 261 296 return ret; 262 297 } 298 299 /** 300 * Accessor function for reporting bool variable that takes care of 301 * properly locking the resource 302 */ 263 303 inline void SetReporting(bool trueValue) 264 304 { … … 268 308 } 269 309 270 //we implement reportSender as an instance of class TCPSender 310 /** 311 * We implement reportSender as an instance of class TCPSender 312 */ 271 313 TCPSender reportSender; 272 //reporting and trying connections to cc are implemented as 273 //PeriodicActions 274 314 315 /** 316 * mutex used to prevent that while report is being send 317 * in ReportingAndCheckingLoop thread, it is changed at the same time 318 * in the main thread 319 * 320 * This mutex is for sure crucial 321 * 322 * SuspendComm and ResumeComm lock/unlock it to achieve this purpose 323 */ 275 324 pthread_mutex_t mutex4report; 325 326 /** 327 * Method that we override from TCPListener and gets called when some 328 * command arrives. Here is where all the LOCK, REPOR protocol is 329 * checked and where ReportingAndCheckingLoop thread is started and 330 * stopped 331 */ 276 332 virtual void process(); 333 334 /** 335 * Method that we also override from TCPListener and mainly gets 336 * called when endofline is received (connection closed by the other 337 * partner); we don't call it explicitely when the protocol is 338 * not followed (this is done in ResetConnectionToCC). As in 339 * ResetConnectionToCC we properly 340 * close reportSender, and stop ReportingAndCheckingLoop 341 */ 277 342 virtual void ClosingChannel(); 278 343 344 /** 345 * Method that actually sends the report via reportSender and returns 346 * if it was successful (to be used inside a PeriodicAction or 347 * whatever). 348 * It will also fail if we didn't receive an acknowledge for 349 * last report several (timeoutCount) times, as asynchronously checked 350 * in method CheckReportAcknowledge. 351 * Before actually sending this->reportString it calls the 352 * GenerateReport method that some real subsystems (as Subsystem 353 * derived classes) will override to fill this string. It also calls 354 * ExtractTimeStampFromLastReportTo to be able to check the timestamp 355 * later (in CheckReportAcknowledge) when the acknowledge arrives. 356 */ 279 357 bool SendReport(); 358 359 /** 360 * Does the actual check of the report acknowledge (when it arrives) 361 * and puts acknowledgeReceivedForLastReport to true; for synchronizing 362 * the threads its better it does 363 * not do anything else like resetting connection itself. If the 364 * acknowledge doesn't arrive acknowledgeReceivedForLastReport will 365 * remain false. SendReport will know and increase the timeoutCount. 366 */ 280 367 void CheckReportAcknowledge(); 281 //to be able to checkreportacknowledge on has to have the timestamp of 282 //the last report sent 368 369 /** 370 * to be able to checkreportacknowledge on has to have the timestamp of 371 * the last report sent 372 */ 283 373 char lastTimeStamp[TIMESTAMP_LEN]; 284 void ExtractTimeStampFromLastReportTo(char *); 374 375 /** 376 * Extracts this timestamp to its parameter lastTimeStamp 377 */ 378 void ExtractTimeStampFromLastReportTo(char * lastTimeStamp); 379 380 /** 381 * the thread handle itself for ReportingAndCheckingLoop 382 */ 285 383 pthread_t reportThread; 384 385 /** 386 * make up for pthread use. Allows pthread to effectively start a 387 * non-static function, which is very convenient to avoid the use of 388 * self 389 */ 286 390 inline static void * pthread_ReportingAndCheckingLoop(void* self) 287 391 { 288 392 return (void *) ( ((Subsystem* )self)->ReportingAndCheckingLoop() ); 289 393 } 290 291 394 395 /** 396 * The actual method started in reportThread 397 */ 292 398 void * ReportingAndCheckingLoop(); 293 399
Note:
See TracChangeset
for help on using the changeset viewer.