Skip to content

Commit ed4f06e

Browse files
committed
Make get_res writable
1 parent df9375b commit ed4f06e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ void value_increment(void)
5656
value_increment_mutex.unlock();
5757
}
5858

59-
void put_update(const char* /*object_name*/)
59+
void get_res_update(const char* /*object_name*/)
60+
{
61+
printf("Counter resource set to %d\n", (int)m2m_get_res->get_value_int());
62+
}
63+
64+
void put_res_update(const char* /*object_name*/)
6065
{
6166
printf("PUT update %d\n", (int)m2m_put_res->get_value_int());
6267
}
@@ -157,19 +162,24 @@ int main(void)
157162
M2MObjectList m2m_obj_list;
158163

159164
// GET resource 3200/0/5501
160-
m2m_get_res = M2MInterfaceFactory::create_resource(m2m_obj_list, 3200, 0, 5501, M2MResourceInstance::INTEGER, M2MBase::GET_ALLOWED);
165+
// PUT also allowed for resetting the resource
166+
m2m_get_res = M2MInterfaceFactory::create_resource(m2m_obj_list, 3200, 0, 5501, M2MResourceInstance::INTEGER, M2MBase::GET_PUT_ALLOWED);
161167
if (m2m_get_res->set_value(0) != true) {
162168
printf("m2m_get_res->set_value() failed\n");
163169
return -1;
164170
}
171+
if (m2m_get_res->set_value_updated_function(get_res_update) != true) {
172+
printf("m2m_get_res->set_value_updated_function() failed\n");
173+
return -1;
174+
}
165175

166176
// PUT resource 3201/0/5853
167177
m2m_put_res = M2MInterfaceFactory::create_resource(m2m_obj_list, 3201, 0, 5853, M2MResourceInstance::INTEGER, M2MBase::GET_PUT_ALLOWED);
168178
if (m2m_put_res->set_value(0) != true) {
169179
printf("m2m_put_res->set_value() failed\n");
170180
return -1;
171181
}
172-
if (m2m_put_res->set_value_updated_function(put_update) != true) {
182+
if (m2m_put_res->set_value_updated_function(put_res_update) != true) {
173183
printf("m2m_put_res->set_value_updated_function() failed\n");
174184
return -1;
175185
}

0 commit comments

Comments
 (0)