xref: /OK3568_Linux_fs/external/rockit/tgi/sdk/include/RTTaskNodeFactory.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2020 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  *  author: <martin.cheng@rock-chips.com>
17  *    date: 2020-04-23
18  *  module: task node factory
19  *
20  */
21 
22 #ifndef SRC_RT_TASK_TASK_NODE_RTTASKNODEFACTORY_H_
23 #define SRC_RT_TASK_TASK_NODE_RTTASKNODEFACTORY_H_
24 
25 #include <list>
26 
27 #include "rt_header.h"
28 #include "RTTaskNodeDef.h"
29 
30 class RTTaskNode;
31 class RTTaskNodeToken;
32 class RTTaskNodeFactory;
33 typedef RTTaskNode* (*RTNodeCreate)();
34 typedef struct _RTNodeStub {
35     const INT32  mUid;
36     const char  *mName;
37     const char  *mVersion;
38     RTNodeCreate mCreateObj;
39     RTPadCaps    mCapsSrc;
40     RTPadCaps    mCapsSink;
41 } RTNodeStub;
42 
43 #define REGISTRY_STATIC_VAR_INNER(var_name, line) var_name##_##line##__
44 #define REGISTRY_STATIC_VAR(var_name, line) \
45     REGISTRY_STATIC_VAR_INNER(var_name, line)
46 
47 #define RT_NODE_FACTORY_CREATE_NODE(idName) \
48     RTTaskNodeFactory::instance()->createNode(idName)
49 
50 #define RT_NODE_FACTORY_GET_UID_BY_NAME(name) \
51     RTTaskNodeFactory::instance()->getUidByName(name)
52 
53 #define RT_NODE_FACTORY_GET_STUB_BY_UID(uid) \
54     RTTaskNodeFactory::instance()->getStubByUid(uid)
55 
56 #define RT_NODE_FACTORY_REGISTER_STUB(stub) \
57     auto REGISTRY_STATIC_VAR(stub, __LINE__) = RTTaskNodeToken(stub);
58 
59 class RTTaskNodeFactory {
60  public:
61     RTTaskNodeFactory();
62     virtual ~RTTaskNodeFactory();
63     static RTTaskNodeFactory* instance();
64 
65  public:
66     RT_RET      registerStub(RTNodeStub* stub);
67     RTTaskNode* createNode(const char* name);
68     RTTaskNode* createNode(RTStubUid stubKey);
69     RTTaskNode* createNode(RTPadCaps* caps);
70     RTTaskNode* createNode(RTNodeStub* stub);
71     RTStubUid   getUidByName(const char* name);
72     RTNodeStub* getStubByUid(RTStubUid stubKey);
73 
74  private:
75     std::list<RTNodeStub*>    mStubs;
76 };
77 
78 class RTTaskNodeToken {
79  public:
80     explicit RTTaskNodeToken(const RTNodeStub &stub);
~RTTaskNodeToken()81     virtual ~RTTaskNodeToken() {}
82  private:
83     RTNodeStub *mNodeStub;
84 };
85 
86 #endif  // SRC_RT_TASK_TASK_NODE_RTTASKNODEFACTORY_H_
87