#include <Filecache.h>
Collaboration diagram for ACE_Filecache_Object:

Public Types | |
| enum | Creation_States { ACE_READING = 1, ACE_WRITING = 2 } |
| enum | Error_Conditions { ACE_SUCCESS = 0, ACE_ACCESS_FAILED, ACE_OPEN_FAILED, ACE_COPY_FAILED, ACE_STAT_FAILED, ACE_MEMMAP_FAILED, ACE_WRITE_FAILED } |
Public Methods | |
| ACE_Filecache_Object (const ACE_TCHAR *filename, ACE_SYNCH_RW_MUTEX &lock, LPSECURITY_ATTRIBUTES sa=0, int mapit=1) | |
| Creates a file for reading. More... | |
| ACE_Filecache_Object (const ACE_TCHAR *filename, off_t size, ACE_SYNCH_RW_MUTEX &lock, LPSECURITY_ATTRIBUTES sa=0) | |
| Creates a file for writing. More... | |
| ~ACE_Filecache_Object (void) | |
| Only if reference count is zero should this be called. More... | |
| int | acquire (void) |
| Increment the reference_count_. More... | |
| int | release (void) |
| Decrement the reference_count_. More... | |
| int | error (void) const |
| int | error (int error_value, const ACE_TCHAR *s=ACE_LIB_TEXT("ACE_Filecache_Object")) |
| const ACE_TCHAR * | filename (void) const |
| filename_ accessor. More... | |
| ACE_HANDLE | handle (void) const |
| handle_ accessor. More... | |
| void * | address (void) const |
| Base memory address for memory mapped file. More... | |
| off_t | size (void) const |
| size_ accessor. More... | |
| int | update (void) const |
| True if file on disk is newer than cached file. More... | |
Protected Methods | |
| ACE_Filecache_Object (void) | |
| Prevent from being called. More... | |
| void | init (void) |
| Common initialization code,. More... | |
Private Methods | |
| int | error_i (int error_value, const ACE_TCHAR *s=ACE_LIB_TEXT("ACE_Filecache_Object")) |
| Internal error logging method, no locking. More... | |
Private Attributes | |
| ACE_TCHAR * | tempname_ |
| The temporary file name and the real file name. The real file is copied into the temporary file for safety reasons. More... | |
| ACE_TCHAR | filename_ [MAXPATHLEN+1] |
| ACE_Mem_Map | mmap_ |
| Holds the memory mapped version of the temporary file. More... | |
| ACE_HANDLE | handle_ |
| The descriptor to the temporary file. More... | |
| ACE_stat | stat_ |
| Used to compare against the real file to test if an update is needed. More... | |
| off_t | size_ |
| int | action_ |
| Status indicators. More... | |
| int | error_ |
| int | stale_ |
| If set to 1, means the object is flagged for removal. More... | |
| LPSECURITY_ATTRIBUTES | sa_ |
| Security attribute object. More... | |
| ACE_SYNCH_RW_MUTEX | junklock_ |
| The default initializer. More... | |
| ACE_SYNCH_RW_MUTEX & | lock_ |
| Provides a bookkeeping mechanism for users of this object. More... | |
Friends | |
| class | ACE_Filecache |
Definition at line 243 of file Filecache.h.
|
|
Definition at line 303 of file Filecache.h.
00304 {
00305 ACE_READING = 1,
00306 ACE_WRITING = 2
00307 };
|
|
|
Definition at line 309 of file Filecache.h.
00310 {
00311 ACE_SUCCESS = 0,
00312 ACE_ACCESS_FAILED,
00313 ACE_OPEN_FAILED,
00314 ACE_COPY_FAILED,
00315 ACE_STAT_FAILED,
00316 ACE_MEMMAP_FAILED,
00317 ACE_WRITE_FAILED
00318 };
|
|
||||||||||||||||||||
|
Creates a file for reading.
Definition at line 480 of file Filecache.cpp. References ACE_OS::access, ACE_ACCESS_FAILED, ACE_LIB_TEXT, ACE_MAP_PRIVATE, ACE_MEMMAP_FAILED, ACE_OPEN_FAILED, ACE_READING, ACE_STAT_FAILED, ACE_SYNCH_RW_MUTEX, ACE_TCHAR, action_, ACE_OS::close, error_i, filename, filename_, handle_, init, ACE_Mem_Map::map, mmap_, ACE_OS::open, PROT_READ, R_MASK, R_OK, READ_FLAGS, size_, ACE_OS::stat, stat_, ACE_OS_String::strcpy, and tempname_.
00484 : tempname_ (0), 00485 mmap_ (), 00486 handle_ (0), 00487 // stat_ (), 00488 size_ (0), 00489 action_ (0), 00490 error_ (0), 00491 stale_ (0), 00492 sa_ (sa), 00493 junklock_ (), 00494 lock_ (lock) 00495 { 00496 this->init (); 00497 00498 // ASSERT strlen(filename) < sizeof (this->filename_) 00499 ACE_OS::strcpy (this->filename_, filename); 00500 this->action_ = ACE_Filecache_Object::ACE_READING; 00501 // place ourselves into the READING state 00502 00503 // Can we access the file? 00504 if (ACE_OS::access (this->filename_, R_OK) == -1) 00505 { 00506 this->error_i (ACE_Filecache_Object::ACE_ACCESS_FAILED); 00507 return; 00508 } 00509 00510 // Can we stat the file? 00511 if (ACE_OS::stat (this->filename_, &this->stat_) == -1) 00512 { 00513 this->error_i (ACE_Filecache_Object::ACE_STAT_FAILED); 00514 return; 00515 } 00516 00517 this->size_ = this->stat_.st_size; 00518 this->tempname_ = this->filename_; 00519 00520 // Can we open the file? 00521 this->handle_ = ACE_OS::open (this->tempname_, 00522 READ_FLAGS, R_MASK, this->sa_); 00523 if (this->handle_ == ACE_INVALID_HANDLE) 00524 { 00525 this->error_i (ACE_Filecache_Object::ACE_OPEN_FAILED, 00526 ACE_LIB_TEXT ("ACE_Filecache_Object::ctor: open")); 00527 return; 00528 } 00529 00530 if (mapit) 00531 { 00532 // Can we map the file? 00533 if (this->mmap_.map (this->handle_, -1, 00534 PROT_READ, ACE_MAP_PRIVATE, 0, 0, this->sa_) != 0) 00535 { 00536 this->error_i (ACE_Filecache_Object::ACE_MEMMAP_FAILED, 00537 ACE_LIB_TEXT ("ACE_Filecache_Object::ctor: map")); 00538 ACE_OS::close (this->handle_); 00539 this->handle_ = ACE_INVALID_HANDLE; 00540 return; 00541 } 00542 } 00543 00544 // Ok, finished! 00545 this->action_ = ACE_Filecache_Object::ACE_READING; 00546 } |
|
||||||||||||||||||||
|
Creates a file for writing.
Definition at line 548 of file Filecache.cpp. References ACE_OS::access, ACE_ACCESS_FAILED, ACE_LIB_TEXT, ACE_MEMMAP_FAILED, ACE_OPEN_FAILED, ACE_SYNCH_RW_MUTEX, ACE_TCHAR, ACE_WRITE_FAILED, ACE_WRITING, action_, ACE_OS::close, error_i, F_OK, filename, filename_, handle_, init, ACE_Mem_Map::map, MAP_SHARED, mmap_, ACE_OS::open, PROT_RDWR, ACE_OS::pwrite, R_OK, size, size_, ACE_OS_String::strcpy, tempname_, W_MASK, W_OK, and WRITE_FLAGS.
00552 : stale_ (0), 00553 sa_ (sa), 00554 lock_ (lock) 00555 { 00556 this->init (); 00557 00558 this->size_ = size; 00559 ACE_OS::strcpy (this->filename_, filename); 00560 this->action_ = ACE_Filecache_Object::ACE_WRITING; 00561 00562 // Can we access the file? 00563 if (ACE_OS::access (this->filename_, R_OK|W_OK) == -1 00564 // Does it exist? 00565 && ACE_OS::access (this->filename_, F_OK) != -1) 00566 { 00567 // File exists, but we cannot access it. 00568 this->error_i (ACE_Filecache_Object::ACE_ACCESS_FAILED); 00569 return; 00570 } 00571 00572 this->tempname_ = this->filename_; 00573 00574 // Can we open the file? 00575 this->handle_ = ACE_OS::open (this->tempname_, WRITE_FLAGS, W_MASK, this->sa_); 00576 if (this->handle_ == ACE_INVALID_HANDLE) 00577 { 00578 this->error_i (ACE_Filecache_Object::ACE_OPEN_FAILED, 00579 ACE_LIB_TEXT ("ACE_Filecache_Object::acquire: open")); 00580 return; 00581 } 00582 00583 // Can we write? 00584 if (ACE_OS::pwrite (this->handle_, "", 1, this->size_ - 1) != 1) 00585 { 00586 this->error_i (ACE_Filecache_Object::ACE_WRITE_FAILED, 00587 ACE_LIB_TEXT ("ACE_Filecache_Object::acquire: write")); 00588 ACE_OS::close (this->handle_); 00589 return; 00590 } 00591 00592 // Can we map? 00593 if (this->mmap_.map (this->handle_, this->size_, PROT_RDWR, MAP_SHARED, 00594 0, 0, this->sa_) != 0) 00595 { 00596 this->error_i (ACE_Filecache_Object::ACE_MEMMAP_FAILED, 00597 ACE_LIB_TEXT ("ACE_Filecache_Object::acquire: map")); 00598 ACE_OS::close (this->handle_); 00599 } 00600 00601 // Ok, done! 00602 } |
|
|
Only if reference count is zero should this be called.
Definition at line 604 of file Filecache.cpp. References ACE_SUCCESS, ACE_OS::close, error_, handle_, mmap_, and ACE_Mem_Map::unmap.
00605 {
00606 if (this->error_ == ACE_SUCCESS)
00607 {
00608 this->mmap_.unmap ();
00609 ACE_OS::close (this->handle_);
00610 this->handle_ = ACE_INVALID_HANDLE;
00611 }
00612 }
|
|
|
Prevent from being called.
Definition at line 464 of file Filecache.cpp. References init.
|
|
|
Increment the reference_count_.
Definition at line 615 of file Filecache.cpp. References lock_. Referenced by ACE_Filecache::create, and ACE_Filecache::finish.
00616 {
00617 return this->lock_.tryacquire_read ();
00618 }
|
|
|
Base memory address for memory mapped file.
Definition at line 713 of file Filecache.cpp. References ACE_Mem_Map::addr, and mmap_. Referenced by ACE_Filecache_Handle::address.
|
|
||||||||||||
|
|
|
|
Definition at line 676 of file Filecache.cpp. References error_. Referenced by ACE_Filecache_Handle::error.
00677 {
00678 // The existence of the object means a read lock is being held.
00679 return this->error_;
00680 }
|
|
||||||||||||
|
Internal error logging method, no locking.
Definition at line 683 of file Filecache.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, error_, and LM_ERROR. Referenced by ACE_Filecache_Object, and release.
00684 {
00685 s = s;
00686 ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("%p.\n"), s));
00687 this->error_ = error_value;
00688 return error_value;
00689 }
|
|
|
filename_ accessor.
Definition at line 692 of file Filecache.cpp. References filename_. Referenced by ACE_Filecache_Object, and ACE_Filecache::finish.
00693 {
00694 // The existence of the object means a read lock is being held.
00695 return this->filename_;
00696 }
|
|
|
handle_ accessor.
Definition at line 706 of file Filecache.cpp. References handle_.
00707 {
00708 // The existence of the object means a read lock is being held.
00709 return this->handle_;
00710 }
|
|
|
Common initialization code,.
Definition at line 453 of file Filecache.cpp. References ACE_SUCCESS, error_, filename_, handle_, ACE_OS_String::memset, size_, and tempname_. Referenced by ACE_Filecache_Object.
00454 {
00455 this->filename_[0] = '\0';
00456 this->handle_ = ACE_INVALID_HANDLE;
00457 this->error_ = ACE_SUCCESS;
00458 this->tempname_ = 0;
00459 this->size_ = 0;
00460
00461 ACE_OS::memset (&(this->stat_), 0, sizeof (this->stat_));
00462 }
|
|
|
Decrement the reference_count_.
Definition at line 621 of file Filecache.cpp. References ACE_MAP_PRIVATE, ACE_MEMMAP_FAILED, ACE_OPEN_FAILED, ACE_READING, ACE_STAT_FAILED, ACE_WRITE_FAILED, ACE_WRITING, action_, ACE_OS::close, error_, error_i, handle_, lock_, ACE_Mem_Map::map, mmap_, ACE_OS::open, PROT_READ, R_MASK, READ_FLAGS, size_, ACE_OS::stat, ACE_OS::unlink, ACE_Mem_Map::unmap, W_MASK, ACE_OS::write, and WRITE_FLAGS. Referenced by ACE_Filecache::finish.
00622 {
00623 if (this->action_ == ACE_WRITING)
00624 {
00625 // We are safe since only one thread has a writable Filecache_Object
00626
00627 #if 0
00628 ACE_HANDLE original = ACE_OS::open (this->filename_, WRITE_FLAGS, W_MASK,
00629 this->sa_);
00630 if (original == ACE_INVALID_HANDLE)
00631 this->error_ = ACE_Filecache_Object::ACE_OPEN_FAILED;
00632 else if (ACE_OS::write (original, this->mmap_.addr (),
00633 this->size_) == -1)
00634 {
00635 this->error_ = ACE_Filecache_Object::ACE_WRITE_FAILED;
00636 ACE_OS::close (original);
00637 ACE_OS::unlink (this->filename_);
00638 }
00639 else if (ACE_OS::stat (this->filename_, &this->stat_) == -1)
00640 this->error_ = ACE_Filecache_Object::ACE_STAT_FAILED;
00641 #endif
00642
00643 this->mmap_.unmap ();
00644 ACE_OS::close (this->handle_);
00645 this->handle_ = ACE_INVALID_HANDLE;
00646
00647 #if 0
00648 // Leave the file in an acquirable state.
00649 this->handle_ = ACE_OS::open (this->tempname_, READ_FLAGS, R_MASK);
00650 if (this->handle_ == ACE_INVALID_HANDLE)
00651 {
00652 this->error_i (ACE_Filecache_Object::ACE_OPEN_FAILED,
00653 "ACE_Filecache_Object::acquire: open");
00654 }
00655 else if (this->mmap_.map (this->handle_, -1,
00656 PROT_READ,
00657 ACE_MAP_PRIVATE,
00658 0,
00659 0,
00660 this->sa_) != 0)
00661 {
00662 this->error_i (ACE_Filecache_Object::ACE_MEMMAP_FAILED,
00663 "ACE_Filecache_Object::acquire: map");
00664 ACE_OS::close (this->handle_);
00665 this->handle_ = ACE_INVALID_HANDLE;
00666 }
00667
00668 this->action_ = ACE_Filecache_Object::ACE_READING;
00669 #endif
00670 }
00671
00672 return this->lock_.release ();
00673 }
|
|
|
size_ accessor.
Definition at line 699 of file Filecache.cpp. References size_. Referenced by ACE_Filecache_Object, and ACE_Filecache_Handle::size.
00700 {
00701 // The existence of the object means a read lock is being held.
00702 return this->size_;
00703 }
|
|
|
True if file on disk is newer than cached file.
Definition at line 720 of file Filecache.cpp. References ACE_stat, ACE_OS::difftime, and ACE_OS::stat. Referenced by ACE_Filecache::fetch.
00721 {
00722 // The existence of the object means a read lock is being held.
00723 int result;
00724 ACE_stat statbuf;
00725
00726 if (ACE_OS::stat (this->filename_, &statbuf) == -1)
00727 result = 1;
00728 else
00729 // non-portable code may follow
00730 #if defined (ACE_HAS_WINCE)
00731 // Yup, non-portable... there's probably a way to safely implement
00732 // difftime() on WinCE, but for now, this will have to do. It flags
00733 // every file as having changed since cached.
00734 result = 1;
00735 #else
00736 result = ACE_OS::difftime (this->stat_.st_mtime, statbuf.st_mtime) < 0;
00737 #endif /* ACE_HAS_WINCE */
00738
00739 return result;
00740 }
|
|
|
Definition at line 246 of file Filecache.h. |
|
|
Status indicators.
Definition at line 337 of file Filecache.h. Referenced by ACE_Filecache_Object, ACE_Filecache::finish, and release. |
|
|
Definition at line 338 of file Filecache.h. Referenced by error, error_i, init, release, and ~ACE_Filecache_Object. |
|
|
Definition at line 324 of file Filecache.h. Referenced by ACE_Filecache_Object, filename, ACE_Filecache::finish, and init. |
|
|
The descriptor to the temporary file.
Definition at line 330 of file Filecache.h. Referenced by ACE_Filecache_Object, handle, init, release, and ~ACE_Filecache_Object. |
|
|
The default initializer.
Definition at line 347 of file Filecache.h. |
|
|
Provides a bookkeeping mechanism for users of this object.
Definition at line 350 of file Filecache.h. Referenced by acquire, ACE_Filecache::finish, release, and ACE_Filecache::remove_i. |
|
|
Holds the memory mapped version of the temporary file.
Definition at line 327 of file Filecache.h. Referenced by ACE_Filecache_Object, address, release, and ~ACE_Filecache_Object. |
|
|
Security attribute object.
Definition at line 344 of file Filecache.h. |
|
|
Definition at line 334 of file Filecache.h. Referenced by ACE_Filecache_Object, init, release, and size. |
|
|
If set to 1, means the object is flagged for removal.
Definition at line 341 of file Filecache.h. Referenced by ACE_Filecache::finish, and ACE_Filecache::remove_i. |
|
|
Used to compare against the real file to test if an update is needed.
Definition at line 333 of file Filecache.h. Referenced by ACE_Filecache_Object. |
|
|
The temporary file name and the real file name. The real file is copied into the temporary file for safety reasons.
Definition at line 323 of file Filecache.h. Referenced by ACE_Filecache_Object, and init. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002