aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/service/svccache.h
blob: 1e989e57bc70566895c8aa6855044dc41a029d6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef _SVC_CACHE_H
#define _SVC_CACHE_H

#include <api/service/svc_enum.h>
#include <bfc/ptrlist.h>

/**
  This is a caching version of SvcEnum. Upon creation, it enumerates all
  service factories in the family and keeps them in a list. Then you can
  call findService() with a search string to quickly find the service you
  want. If you don't have a search string, you can still use a SvcEnum.
*/

class SvcCache {
protected:
  SvcCache(FOURCC type);
 
public:
  waServiceFactory *findServiceFactory(const wchar_t *searchval);

private:
  class waServiceFactoryCompare {
  public:
    static int compareItem(waServiceFactory *p1, waServiceFactory* p2);
    static int compareAttrib(const wchar_t *attrib, waServiceFactory *item);
  };
  PtrListQuickSorted<waServiceFactory, waServiceFactoryCompare> list;
};

template <class T>
class SvcCacheT : public SvcCache {
public:
  SvcCacheT() : SvcCache(T::getServiceType()) { }

  T *findService(const char *key, int global_lock=TRUE) {
    waServiceFactory *sf = findServiceFactory(key);
    if (sf == NULL) return NULL;
    T *ret = castService<T>(sf, global_lock);
    return ret;
  }
};

#endif