File: auto_device_class.cpp

package info (click to toggle)
tango 10.0.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 89,936 kB
  • sloc: cpp: 201,786; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 272; sql: 72; ruby: 24
file content (60 lines) | stat: -rw-r--r-- 1,321 bytes parent folder | download | duplicates (4)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "utils/auto_device_class.h"

std::vector<TangoTest::detail::ClassRegistrarBase *> *TangoTest::detail::ClassRegistrarBase::registrars = nullptr;

namespace
{
std::vector<std::string> get_enabled_classes()
{
    std::vector<std::string> result;

    const char *maybe_env = std::getenv(TangoTest::detail::k_enabled_classes_env_var);

    if(maybe_env == nullptr)
    {
        return result;
    }

    std::string env{maybe_env};

    size_t pos = 0;
    while(true)
    {
        size_t next = env.find(';', pos);
        if(next == std::string::npos)
        {
            result.push_back(env.substr(pos));
            break;
        }

        result.push_back(env.substr(pos, next - 1));
        pos = next + 1;
    }

    return result;
}

bool contains(const std::vector<std::string> &haystack, const std::string &needle)
{
    return std::find(haystack.begin(), haystack.end(), needle) != haystack.end();
}

} // namespace

namespace Tango
{
void DServer::class_factory()
{
    std::vector<std::string> enabled = get_enabled_classes();

    for(auto *registrar : *TangoTest::detail::ClassRegistrarBase::registrars)
    {
        if(!enabled.empty() && !contains(enabled, registrar->name))
        {
            continue;
        }

        add_class(registrar->init_class());
    }
}
} // namespace Tango