00001 /* 00002 * File Name: collection_impl.h 00003 */ 00004 00005 /* 00006 * This file is part of uds-plugin-pdf. 00007 * 00008 * uds-plugin-pdf is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation, either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * uds-plugin-pdf is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 /** 00023 * Copyright (C) 2008 iRex Technologies B.V. 00024 * All rights reserved. 00025 */ 00026 00027 #ifndef DUMMY_PLUGIN_COLLECTION_IMPL_H_ 00028 #define DUMMY_PLUGIN_COLLECTION_IMPL_H_ 00029 00030 #include <vector> 00031 #include <cassert> 00032 #include "plugin_inc.h" 00033 #include "interfaces_utils.h" 00034 #include "signal_slot.h" 00035 #include "pdf_observer.h" 00036 #include "pdf_collection.h" 00037 00038 using namespace utils; 00039 00040 namespace pdf 00041 { 00042 00043 /// PluginCollectionImpl provides a template based collection container. 00044 /// Through this class, caller is able to store data inside the collection. 00045 /// If caller wants to strore pointe data in the collection, it's necessary 00046 /// for caller to connect the release_signal, so that when collection object 00047 /// is to be released, the caller can be notified. 00048 class PluginCollectionImpl : public IPluginUnknown 00049 , public IPluginCollection 00050 { 00051 public: 00052 PluginCollectionImpl(void) 00053 { 00054 query_interface = query_interface_impl; 00055 release = release_impl; 00056 get_data = get_data_impl; 00057 get_num_elements = get_num_elements_impl; 00058 00059 g_instances_table.add_interface<IPluginUnknown>(this); 00060 g_instances_table.add_interface<IPluginCollection>(this); 00061 } 00062 00063 ~PluginCollectionImpl(void) 00064 { 00065 // the collection data should be released here 00066 g_instances_table.remove(this); 00067 delete data; 00068 data = 0; 00069 } 00070 00071 void set_data(PDFCollectionBase *coll) 00072 { 00073 data = coll; 00074 } 00075 00076 public: 00077 utils::Signal<PluginCollectionImpl *> release_signal; 00078 00079 private: 00080 // IPluginUnknown 00081 static PluginStatus query_interface_impl(IPluginUnknown *thiz, 00082 const UDSString *id, 00083 void **ptr ) 00084 { 00085 // check object. 00086 PluginCollectionImpl *instance = g_instances_table.get_object(thiz); 00087 if (g_instances_table.query_interface(instance, id->get_buffer(id), ptr)) 00088 { 00089 return PLUGIN_OK; 00090 } 00091 return PLUGIN_FAIL; 00092 } 00093 00094 static int release_impl(IPluginUnknown *thiz ) 00095 { 00096 PluginCollectionImpl *instance = g_instances_table.get_object(thiz); 00097 if (instance->release_signal.count() > 0) 00098 { 00099 instance->release_signal.broadcast(instance); 00100 } 00101 else 00102 { 00103 delete instance; 00104 } 00105 return 0; 00106 } 00107 00108 // IPluginCollection 00109 static PluginStatus get_data_impl(IPluginUnknown *thiz, 00110 void **data_ptr) 00111 { 00112 PluginCollectionImpl *instance = g_instances_table.get_object(thiz); 00113 instance->data->get_first_element(data_ptr); 00114 return PLUGIN_OK; 00115 } 00116 00117 static int get_num_elements_impl(IPluginUnknown *thiz ) 00118 { 00119 PluginCollectionImpl *instance = g_instances_table.get_object(thiz); 00120 return instance->data->get_count(); 00121 } 00122 00123 private: 00124 static ObjectTable<PluginCollectionImpl> g_instances_table; 00125 PDFCollectionBase *data; 00126 00127 }; 00128 00129 00130 00131 }; // namespace dummy 00132 00133 #endif // PLUGIN_COLLECTION_IMPL_H_ 00134