Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Filecache.cpp
blob5f6ebf01a7cc36d70f4edec7237d14491b100ca9
1 #include "ace/FILE_Connector.h"
2 #include "ace/OS_NS_unistd.h"
4 #include "JAWS/Filecache.h"
5 #include "JAWS/Cache_List_T.h"
7 void
8 JAWS_Referenced_Filecache_Factory::destroy (JAWS_Cache_Object *object)
10 JAWS_FILE *file = (JAWS_FILE *) object->data ();
11 file->close ();
12 if (file->map ())
13 file->map ()->close ();
14 delete file;
15 this->JAWS_Referenced_Cache_Object_Factory::destroy (object);
18 void
19 JAWS_Counted_Filecache_Factory::destroy (JAWS_Cache_Object *object)
21 JAWS_FILE *file = (JAWS_FILE *) object->data ();
22 file->close ();
23 if (file->map ())
24 file->map ()->close ();
25 delete file;
26 this->JAWS_Counted_Cache_Object_Factory::destroy (object);
29 JAWS_Cached_FILE::JAWS_Cached_FILE (const char *const &filename,
30 JAWS_Filecache_Proxy::Cache_Manager *cm)
31 : JAWS_Filecache_Proxy (filename, cm)
33 ACE_HANDLE handle = ACE_INVALID_HANDLE;
35 if (this->data () != 0)
37 handle = ACE_OS::dup (this->data ()->get_handle ());
39 else
41 JAWS_FILE *file = new JAWS_FILE;
42 ACE_FILE_Connector file_connector;
44 int result = file_connector.connect (*file, ACE_FILE_Addr (filename));
45 if (result == -1 || file->get_handle () == ACE_INVALID_HANDLE)
47 // TODO: do something here!
50 ACE_FILE_Info info;
51 file->get_info (info);
53 handle = ACE_OS::dup (file->get_handle ());
56 JAWS_Cached_FILE cf (filename, file, info.size_, cm);
57 if (cf.data () != 0)
59 new (this) JAWS_Cached_FILE (filename, cm);
60 return;
65 this->file_.set_handle (handle);
68 JAWS_Cached_FILE::JAWS_Cached_FILE (const char *const &filename,
69 JAWS_FILE *&file,
70 size_t size,
71 JAWS_Filecache_Proxy::Cache_Manager *cm)
72 : JAWS_Filecache_Proxy (filename, file, size, cm)
76 JAWS_Cached_FILE::~JAWS_Cached_FILE ()
78 this->file_.close ();
81 ACE_FILE_IO *
82 JAWS_Cached_FILE::file ()
84 return &(this->file_);
87 ACE_Mem_Map *
88 JAWS_Cached_FILE::mmap ()
90 return (this->data () == 0 ? 0 : this->data ()->mem_map ());