ctkConfigurationStore_p.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKCONFIGURATIONSTORE_P_H
  16. #define CTKCONFIGURATIONSTORE_P_H
  17. #include <ctkLDAPSearchFilter.h>
  18. #include "ctkConfigurationImpl_p.h"
  19. #include <QSharedPointer>
  20. #include <QHash>
  21. #include <QDir>
  22. #include <QMutex>
  23. class ctkConfigurationImpl;
  24. class ctkConfigurationAdminFactory;
  25. class ctkPluginContext;
  26. class ctkPlugin;
  27. /**
  28. * ctkConfigurationStore manages all active configurations along with persistence. The current
  29. * implementation uses a filestore and serialization of the configuration dictionaries to files
  30. * identified by their pid. Persistence details are in the constructor, saveConfiguration, and
  31. * deleteConfiguration and can be factored out separately if required.
  32. */
  33. class ctkConfigurationStore
  34. {
  35. public:
  36. ctkConfigurationStore(ctkConfigurationAdminFactory* configurationAdminFactory,
  37. ctkPluginContext* context);
  38. void saveConfiguration(const QString& pid, ctkConfigurationImpl* config);
  39. void removeConfiguration(const QString& pid);
  40. ctkConfigurationImplPtr getConfiguration(const QString& pid, const QString& location);
  41. ctkConfigurationImplPtr createFactoryConfiguration(
  42. const QString& factoryPid, const QString& location);
  43. ctkConfigurationImplPtr findConfiguration(const QString& pid);
  44. QList<ctkConfigurationImplPtr> getFactoryConfigurations(const QString& factoryPid);
  45. QList<ctkConfigurationImplPtr> listConfigurations(const ctkLDAPSearchFilter& filter);
  46. void unbindConfigurations(QSharedPointer<ctkPlugin> plugin);
  47. private:
  48. QMutex mutex;
  49. ctkConfigurationAdminFactory* configurationAdminFactory;
  50. static const QString STORE_DIR; // = "store"
  51. static const QString PID_EXT; // = ".pid"
  52. QHash<QString, ctkConfigurationImplPtr> configurations;
  53. int createdPidCount;
  54. QDir store;
  55. void writeConfigurationFile(QFile& configFile,
  56. const ctkDictionary& configProperties);
  57. void deleteConfigurationFile(QFile& configFile);
  58. };
  59. #endif // CTKCONFIGURATIONSTORE_P_H