svccache.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef _SVC_CACHE_H
  2. #define _SVC_CACHE_H
  3. #include <api/service/svc_enum.h>
  4. #include <bfc/ptrlist.h>
  5. /**
  6. This is a caching version of SvcEnum. Upon creation, it enumerates all
  7. service factories in the family and keeps them in a list. Then you can
  8. call findService() with a search string to quickly find the service you
  9. want. If you don't have a search string, you can still use a SvcEnum.
  10. */
  11. class SvcCache {
  12. protected:
  13. SvcCache(FOURCC type);
  14. public:
  15. waServiceFactory *findServiceFactory(const wchar_t *searchval);
  16. private:
  17. class waServiceFactoryCompare {
  18. public:
  19. static int compareItem(waServiceFactory *p1, waServiceFactory* p2);
  20. static int compareAttrib(const wchar_t *attrib, waServiceFactory *item);
  21. };
  22. PtrListQuickSorted<waServiceFactory, waServiceFactoryCompare> list;
  23. };
  24. template <class T>
  25. class SvcCacheT : public SvcCache {
  26. public:
  27. SvcCacheT() : SvcCache(T::getServiceType()) { }
  28. T *findService(const char *key, int global_lock=TRUE) {
  29. waServiceFactory *sf = findServiceFactory(key);
  30. if (sf == NULL) return NULL;
  31. T *ret = castService<T>(sf, global_lock);
  32. return ret;
  33. }
  34. };
  35. #endif