29
29
30
30
using DeviceControllerFactory = chip::Controller::DeviceControllerFactory;
31
31
32
- constexpr const char kCommissionerAlpha [] = " alpha" ;
33
- constexpr const char kCommissionerBeta [] = " beta" ;
34
- constexpr const char kCommissionerGamma [] = " gamma" ;
35
-
36
- constexpr chip::FabricId kCommissionerAlphaFabricId = 1 ;
37
- constexpr chip::FabricId kCommissionerBetaFabricId = 2 ;
38
- constexpr chip::FabricId kCommissionerGammaFabricId = 3 ;
32
+ constexpr chip::FabricId kIdentityAlphaFabricId = 1 ;
33
+ constexpr chip::FabricId kIdentityBetaFabricId = 2 ;
34
+ constexpr chip::FabricId kIdentityGammaFabricId = 3 ;
39
35
40
36
CHIP_ERROR CHIPCommand::Run ()
41
37
{
@@ -52,7 +48,7 @@ CHIP_ERROR CHIPCommand::Run()
52
48
factoryInitParams.listenPort = static_cast <uint16_t >(mDefaultStorage .GetListenPort () + CurrentCommissionerIndex ());
53
49
ReturnLogErrorOnFailure (DeviceControllerFactory::GetInstance ().Init (factoryInitParams));
54
50
55
- ReturnLogErrorOnFailure (InitializeCommissioner (CurrentCommissionerName (), CurrentCommissionerIndex ()));
51
+ ReturnLogErrorOnFailure (InitializeCommissioner (GetIdentity (), CurrentCommissionerIndex ()));
56
52
57
53
chip::DeviceLayer::PlatformMgr ().ScheduleWork (RunQueuedCommand, reinterpret_cast <intptr_t >(this ));
58
54
ReturnLogErrorOnFailure (StartWaiting (GetWaitDuration ()));
@@ -64,18 +60,31 @@ CHIP_ERROR CHIPCommand::Run()
64
60
// since the CHIP thread and event queue have been stopped, preventing any thread
65
61
// races.
66
62
//
67
- ReturnLogErrorOnFailure (ShutdownCommissioner (CurrentCommissionerName ()));
63
+ ReturnLogErrorOnFailure (ShutdownCommissioner (GetIdentity ()));
68
64
69
65
return CHIP_NO_ERROR;
70
66
}
71
67
72
- std::string CHIPCommand::CurrentCommissionerName ()
68
+ void CHIPCommand::SetIdentity (const char * identity)
69
+ {
70
+ std::string name = std::string (identity);
71
+ if (name.compare (kIdentityAlpha ) != 0 && name.compare (kIdentityBeta ) != 0 && name.compare (kIdentityGamma ) != 0 )
72
+ {
73
+ ChipLogError (chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s]" , name.c_str (), kIdentityAlpha ,
74
+ kIdentityBeta , kIdentityGamma );
75
+ chipDie ();
76
+ }
77
+
78
+ mCommissionerName .SetValue (const_cast <char *>(identity));
79
+ }
80
+
81
+ std::string CHIPCommand::GetIdentity ()
73
82
{
74
- std::string name = mCommissionerName .HasValue () ? mCommissionerName .Value () : kCommissionerAlpha ;
75
- if (name.compare (kCommissionerAlpha ) != 0 && name.compare (kCommissionerBeta ) != 0 && name.compare (kCommissionerGamma ) != 0 )
83
+ std::string name = mCommissionerName .HasValue () ? mCommissionerName .Value () : kIdentityAlpha ;
84
+ if (name.compare (kIdentityAlpha ) != 0 && name.compare (kIdentityBeta ) != 0 && name.compare (kIdentityGamma ) != 0 )
76
85
{
77
- ChipLogError (chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s]" , name.c_str (), kCommissionerAlpha ,
78
- kCommissionerBeta , kCommissionerGamma );
86
+ ChipLogError (chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s]" , name.c_str (), kIdentityAlpha ,
87
+ kIdentityBeta , kIdentityGamma );
79
88
chipDie ();
80
89
}
81
90
@@ -86,28 +95,28 @@ uint16_t CHIPCommand::CurrentCommissionerIndex()
86
95
{
87
96
uint16_t index = 0 ;
88
97
89
- std::string name = CurrentCommissionerName ();
90
- if (name.compare (kCommissionerAlpha ) == 0 )
98
+ std::string name = GetIdentity ();
99
+ if (name.compare (kIdentityAlpha ) == 0 )
91
100
{
92
- index = kCommissionerAlphaFabricId ;
101
+ index = kIdentityAlphaFabricId ;
93
102
}
94
- else if (name.compare (kCommissionerBeta ) == 0 )
103
+ else if (name.compare (kIdentityBeta ) == 0 )
95
104
{
96
- index = kCommissionerBetaFabricId ;
105
+ index = kIdentityBetaFabricId ;
97
106
}
98
- else if (name.compare (kCommissionerGamma ) == 0 )
107
+ else if (name.compare (kIdentityGamma ) == 0 )
99
108
{
100
- index = kCommissionerGammaFabricId ;
109
+ index = kIdentityGammaFabricId ;
101
110
}
102
111
103
112
VerifyOrDieWithMsg (index != 0 , chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s]" , name.c_str (),
104
- kCommissionerAlpha , kCommissionerBeta , kCommissionerGamma );
113
+ kIdentityAlpha , kIdentityBeta , kIdentityGamma );
105
114
return index ;
106
115
}
107
116
108
117
chip::Controller::DeviceCommissioner & CHIPCommand::CurrentCommissioner ()
109
118
{
110
- auto item = mCommissioners .find (CurrentCommissionerName ());
119
+ auto item = mCommissioners .find (GetIdentity ());
111
120
return *item->second .get ();
112
121
}
113
122
0 commit comments