#include <Storable_Naming_Context.h>
Collaboration diagram for TAO_Storable_Naming_Context::File_Open_Lock_and_Check:
Public Member Functions | |
File_Open_Lock_and_Check (TAO_Storable_Naming_Context *context, const char *mode) | |
Constructor - we always need the object which we guard. | |
~File_Open_Lock_and_Check (void) | |
Destructor. | |
void | release (void) |
Releases the lock, closes the file, and deletes the I/O stream. | |
TAO_Storable_Base & | peer (void) |
Returns the stream to read/write on. | |
Private Types | |
enum | { mode_write = 1, mode_read = 2, mode_create = 4 } |
Symbolic values for the flags in the above. More... | |
Private Member Functions | |
File_Open_Lock_and_Check (void) | |
Default constructor. | |
Private Attributes | |
int | closed_ |
A flag to keep us from trying to close things more than once. | |
TAO_Storable_Naming_Context * | context_ |
We need to save the pointer to our parent for cleaning up. | |
TAO_Storable_Base * | fl_ |
The pointer to the actual file I/O (bridge pattern). | |
int | rwflags_ |
The flags that we were opened with. |
Guard class for the TAO_Storable_Naming_Context. It opens a file for read/write and sets a lock on it. It then checks if the file has changed and re-reads it if it has.
The destructor insures that the lock gets released.
How to use this class: File_Open_Lock_and_Check flck(this, name_len > 1 ? "r" : "rw");
Definition at line 413 of file Storable_Naming_Context.h.
Member Enumeration Documentation
|
Symbolic values for the flags in the above.
Definition at line 447 of file Storable_Naming_Context.h.
00447 { mode_write = 1, mode_read = 2, mode_create = 4 }; |
|
Constructor - we always need the object which we guard.
Definition at line 418 of file Storable_Naming_Context.cpp. References ACE_CString, ACE_TEXT_CHAR_TO_TCHAR, ACE_TRACE, TAO_Storable_Base::close(), closed_, TAO_Naming_Service_Persistence_Factory::create_stream(), TAO_Storable_Naming_Context::factory_, TAO_Storable_Base::last_changed(), TAO_Storable_Naming_Context::last_changed_, TAO_Storable_Naming_Context::load_map(), mode_create, mode_read, mode_write, TAO_Storable_Naming_Context::name_, TAO_Storable_Base::open(), TAO_Storable_Naming_Context::persistence_directory_, TAO_Storable_Naming_Context::redundant_, rwflags_, TAO_Storable_Naming_Context::storable_context_, and ACE_OS::strlen().
00421 :closed_(1), 00422 context_(context) 00423 { 00424 ACE_TRACE("File_Open_Lock_and_Check"); 00425 // We only accept a subset of mode argument, check it 00426 rwflags_ = 0; 00427 for( unsigned int i = 0; i<ACE_OS::strlen(mode); i++ ) 00428 { 00429 switch (mode[i]) 00430 { 00431 case 'r': rwflags_ |= mode_read; 00432 break; 00433 case 'w': rwflags_ |= mode_write; 00434 break; 00435 case 'c': rwflags_ |= mode_create; 00436 break; 00437 default: rwflags_ = -1; 00438 } 00439 } 00440 if( rwflags_ <= 0 ) 00441 { 00442 errno = EINVAL; 00443 throw CORBA::PERSIST_STORE(); 00444 } 00445 00446 // build the file name 00447 ACE_CString file_name(context->persistence_directory_); 00448 file_name += "/"; 00449 file_name += context->name_; 00450 00451 // Create the stream 00452 fl_ = context->factory_->create_stream(file_name, ACE_TEXT_CHAR_TO_TCHAR(mode)); 00453 if (TAO_Storable_Naming_Context::redundant_) 00454 { 00455 if (fl_->open() != 0) 00456 { 00457 delete fl_; 00458 throw CORBA::PERSIST_STORE(); 00459 } 00460 00461 // acquire a lock on it 00462 if (fl_ -> flock(0, 0, 0) != 0) 00463 { 00464 fl_->close(); 00465 delete fl_; 00466 throw CORBA::INTERNAL(); 00467 } 00468 00469 // now that the file is successfully opened and locked it must be 00470 // unlocked/closed before we leave this class 00471 closed_ = 0; 00472 00473 if ( ! (rwflags_ & mode_create) ) 00474 { 00475 // Check if our copy is up to date 00476 time_t new_last_changed = fl_->last_changed(); 00477 if( new_last_changed > context->last_changed_ ) 00478 { 00479 context->last_changed_ = new_last_changed; 00480 // Throw our map away 00481 delete context->storable_context_; 00482 // and build a new one from disk 00483 context->load_map(this); 00484 } 00485 } 00486 } 00487 else if ( ! context->storable_context_ || (rwflags_ & mode_write) ) 00488 { 00489 if (fl_->open() != 0) 00490 { 00491 delete fl_; 00492 throw CORBA::PERSIST_STORE(); 00493 } 00494 00495 // now that the file is successfully opened 00496 // unlocked/closed before we leave this class 00497 closed_ = 0; 00498 00499 if(!context->storable_context_) 00500 { 00501 // Load the map from disk 00502 context->load_map(this); 00503 } 00504 } 00505 else 00506 { 00507 // Need to insure that fl_ gets deleted 00508 delete fl_; 00509 } 00510 } |
|
Destructor.
Definition at line 533 of file Storable_Naming_Context.cpp. References ACE_TRACE.
|
|
Default constructor.
|
|
Returns the stream to read/write on.
Definition at line 540 of file Storable_Naming_Context.cpp. References ACE_TRACE. Referenced by TAO_Storable_Naming_Context::bind(), TAO_Storable_Naming_Context::bind_context(), TAO_Storable_Naming_Context::destroy(), TAO_Storable_Naming_Context::load_map(), TAO_Storable_Naming_Context::new_context(), TAO_Storable_Naming_Context::rebind(), TAO_Storable_Naming_Context::rebind_context(), TAO_Storable_Naming_Context::recreate_all(), and TAO_Storable_Naming_Context::unbind().
|
|
Releases the lock, closes the file, and deletes the I/O stream.
Definition at line 514 of file Storable_Naming_Context.cpp. References ACE_TRACE, and TAO_Storable_Naming_Context::redundant_. Referenced by TAO_Storable_Naming_Context::bind(), TAO_Storable_Naming_Context::bind_context(), TAO_Storable_Naming_Context::bind_new_context(), TAO_Storable_Naming_Context::list(), TAO_Storable_Naming_Context::rebind(), TAO_Storable_Naming_Context::rebind_context(), TAO_Storable_Naming_Context::resolve(), and TAO_Storable_Naming_Context::unbind().
00515 { 00516 ACE_TRACE("release"); 00517 if ( ! closed_ ) 00518 { 00519 // If we updated the disk, save the time stamp 00520 if(TAO_Storable_Naming_Context::redundant_) 00521 { 00522 if( rwflags_ & mode_write ) 00523 context_->last_changed_ = fl_->last_changed(); 00524 fl_->funlock(0, 0, 0); 00525 } 00526 fl_->close(); 00527 delete fl_; 00528 closed_ = 1; 00529 } 00530 } |
|
A flag to keep us from trying to close things more than once.
Definition at line 435 of file Storable_Naming_Context.h. Referenced by File_Open_Lock_and_Check(). |
|
We need to save the pointer to our parent for cleaning up.
Definition at line 438 of file Storable_Naming_Context.h. |
|
The pointer to the actual file I/O (bridge pattern).
Definition at line 441 of file Storable_Naming_Context.h. |
|
The flags that we were opened with.
Definition at line 444 of file Storable_Naming_Context.h. Referenced by File_Open_Lock_and_Check(). |