pdf/plugin_impl/library_impl.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <cassert>
00028 #include <string.h>
00029 #include "library_impl.h"
00030
00031 namespace pdf
00032 {
00033
00034
00035
00036 static const std::string g_ext_table[] =
00037 {
00038 ".pdf"
00039 };
00040 static const int EXT_TABLE_SIZE =
00041 sizeof(g_ext_table) / sizeof(g_ext_table[0]);
00042
00043
00044 utils::ObjectTable<PluginLibraryImpl>
00045 PluginLibraryImpl::g_instances_table;
00046
00047
00048 PluginLibraryImpl::PluginLibraryImpl()
00049 {
00050
00051
00052
00053 query_interface = query_interface_impl;
00054 release = release_impl;
00055 is_supported_document = is_supported_document_impl;
00056 create_document = create_document_impl;
00057
00058
00059 g_instances_table.add_interface<IPluginUnknown>(this);
00060 g_instances_table.add_interface<IPluginLibrary>(this);
00061 }
00062
00063 PluginLibraryImpl::~PluginLibraryImpl()
00064 {
00065 g_instances_table.remove(this);
00066 }
00067
00068 PluginStatus
00069 PluginLibraryImpl::query_interface_impl(IPluginUnknown *thiz,
00070 const UDSString *id,
00071 void **ptr)
00072 {
00073
00074
00075
00076 PluginLibraryImpl *instance = g_instances_table.get_object(thiz);
00077 if (g_instances_table.query_interface(instance, id->get_buffer(id), ptr))
00078 {
00079 return PLUGIN_OK;
00080 }
00081 return PLUGIN_FAIL;
00082 }
00083
00084 int PluginLibraryImpl::release_impl( IPluginUnknown *thiz )
00085 {
00086 PluginLibraryImpl *instance = g_instances_table.get_object(thiz);
00087 delete instance;
00088 return 0;
00089 }
00090
00091 PluginBool
00092 PluginLibraryImpl::is_supported_document_impl(IPluginUnknown *thiz,
00093 const UDSString *path)
00094 {
00095
00096
00097 if (path != 0)
00098 {
00099 const char * pos = strrchr(path->get_buffer(path), '.');
00100 for(int i = 0; i < EXT_TABLE_SIZE; ++i)
00101 {
00102 if (pos)
00103 {
00104 if (strncmp(pos,
00105 g_ext_table[i].c_str(),
00106 g_ext_table[i].length()) == 0)
00107 {
00108 return PLUGIN_TRUE;
00109 }
00110 }
00111 }
00112 }
00113 return PLUGIN_FALSE;
00114 }
00115
00116 IPluginUnknown *
00117 PluginLibraryImpl::create_document_impl(IPluginUnknown * thiz)
00118 {
00119 PluginLibraryImpl *obj = g_instances_table.get_object(thiz);
00120
00121 if (obj)
00122 {
00123
00124 DocPtr doc = new PluginDocImpl;
00125
00126
00127 doc->release_signal.add_slot(obj,
00128 &PluginLibraryImpl::on_document_released);
00129
00130
00131 obj->documents.push_back(doc);
00132 return static_cast<IPluginUnknown *>(doc);
00133 }
00134 return 0;
00135 }
00136
00137 void PluginLibraryImpl::on_document_released(PluginDocImpl * doc)
00138 {
00139 DocumentsIter iter = std::find(documents.begin(), documents.end(), doc);
00140 if (iter != documents.end())
00141 {
00142 delete *iter;
00143 documents.erase(iter);
00144 }
00145 }
00146
00147 }
00148