blob: e3711eb539b1fe87996e480e8ca9e3dd7b3a5cf4 [file] [log] [blame]
Beerappa S M7af96e52021-04-20 18:57:54 +00001/*
2 * Copyright 2021-present Open Networking Foundation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
12 */
13
14
15#ifndef DMI_PHYCOMP_FACTORY_H_
16#define DMI_PHYCOMP_FACTORY_H_
17
18#include "hw_management_service.grpc.pb.h"
19#include "hw_management_service.pb.h"
20#include <iostream>
21#include <string>
22/*
23 * PhyComponent
24 * PhyComponent implement the same interface so that the classes can refer
25 * to the interface not the concrete Component
26 */
27class PhyComponent
28{
29 public:
30 dmi::Component comp;
31 uint8_t comp_number;
32
33 /*Interfaces where each subclasses implements thier specific details*/
34 virtual uint8_t UpdateComp(uint8_t comp_number) = 0;
35 virtual uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields) = 0;
36
37 virtual ~PhyComponent() {}
38};
39
40
41/*
42 * Concrete Component
43 * define Component to be created
44 */
45class FanComp : public PhyComponent
46{
47 public:
48 FanComp()
49 {
50 /*Fill the default/common parameters here*/
51 this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_FAN);
52 this->comp.set_is_fru( 1 );
53 }
54
55 uint8_t UpdateComp(uint8_t comp_number);
56 uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
57 ~FanComp() {}
58};
59
60
61
62/*
63 * Concrete Component
64 * define Component to be created
65 */
66class DiskComp : public PhyComponent
67{
68 public:
69 DiskComp()
70 {
71 this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_STORAGE);
72 this->comp.set_is_fru( 0 );
73 }
74
75 uint8_t UpdateComp(uint8_t comp_number);
76 uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
77 ~DiskComp() {}
78};
79
80
81/*
82 * Concrete Component
83 * define Component to be created
84 */
85class ContainerComp : public PhyComponent
86{
87 public:
88 ContainerComp()
89 {
90 this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_CONTAINER);
91 this->comp.set_is_fru( 0 );
92 //set the container attribute
93 }
94
95 uint8_t UpdateComp(uint8_t comp_number);
96 uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
97 ~ContainerComp() {}
98};
99
100
101
102/*
103 * Concrete Component
104 * define Component to be created
105 */
106class PortComp : public PhyComponent
107{
108 public:
109 PortComp()
110 {
111 this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_PORT );
112 this->comp.set_is_fru( 0 );
113 }
114
115 uint8_t UpdateComp(uint8_t comp_number);
116 uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
117 ~PortComp() {}
118};
119
120
121/*
122 * Concrete Component
123 * define Component to be created
124 */
125class CPUComp : public PhyComponent
126{
127 public:
128 CPUComp()
129 {
130 this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_CPU );
131 this->comp.set_is_fru( 0 );
132 }
133
134 uint8_t UpdateComp(uint8_t comp_number);
135 uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
136 ~CPUComp() {}
137};
138
139/*
140 * Concrete Component
141 * define Component to be created
142 */
143class TransceiverComp : public PhyComponent
144{
145 public:
146 TransceiverComp()
147 {
148 this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_TRANSCEIVER );
149 this->comp.set_is_fru ( 1 );
150 }
151
152 uint8_t UpdateComp(uint8_t comp_number);
153 uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
154 ~TransceiverComp() {}
155};
156
157
158/*
159 * Creator
160 * contains the implementation for all of the methods
161 * to manipulate products except for the factory method
162 */
163class Creator
164{
165 public:
166
167 virtual PhyComponent* CreateFanCompInst() = 0;
168 virtual PhyComponent* CreateDiskCompInst() = 0;
169 virtual PhyComponent* CreateContainerCompInst() = 0;
170 virtual PhyComponent* CreatePortCompInst() = 0;
171 virtual PhyComponent* CreateCPUCompInst() = 0;
172 virtual PhyComponent* CreateTransceiverCompInst() = 0;
173 virtual void removeComponent( PhyComponent *comp ) = 0;
174 virtual ~Creator() {}
175};
176
177/*
178 * Concrete Creator
179 * implements factory method that is responsible for creating
180 * one or more concrete products ie. it is class that has
181 * the knowledge of how to create the products
182 */
183class ConcreteComp : public Creator
184{
185 public:
186 ~ConcreteComp() {}
187
188 PhyComponent* CreateFanCompInst()
189 {
190 return new FanComp();
191 }
192
193 PhyComponent* CreateDiskCompInst()
194 {
195 return new DiskComp();
196 }
197
198 PhyComponent* CreateContainerCompInst()
199 {
200 return new ContainerComp();
201 }
202
203 PhyComponent* CreatePortCompInst()
204 {
205 return new PortComp();
206 }
207
208 PhyComponent* CreateCPUCompInst()
209 {
210 return new CPUComp();
211 }
212
213 PhyComponent* CreateTransceiverCompInst()
214 {
215 return new TransceiverComp();
216 }
217
218 void removeComponent( PhyComponent *comp )
219 {
220 delete comp;
221 }
222};
223#endif
224