Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit fbbd412

Browse files
author
Antti Yli-Tokola
committed
Add instructions how to use set_value_updated API
1 parent d26b7c2 commit fbbd412

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

docs/dev_man_serv_enable.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The Client API allows setting values to Resources, an array of Resource Instance
6767

6868
The **Write** operation is used to overwrite the value of a Resource, an array of Resource Instances or multiple Resources from an Object Instance.
6969

70-
Whenever there is a valid `PUT` operation for any of the resources, the application will receive a callback:
70+
Whenever there is a valid `PUT` operation for any of the resources, the application will receive a callback:
7171

7272
```
7373
void value_updated(M2MBase *base, M2MBase::BaseType type)
@@ -119,6 +119,33 @@ void value_updated(M2MBase *base, M2MBase::BaseType type) {
119119
}
120120
}
121121
```
122+
By default callbacks are handled in value_updated() function but application can also define callback function for individual resource.
123+
Check the code snippet below for usage.
124+
125+
```
126+
static void value_updated_global(const char *name) {
127+
if(name) {
128+
...
129+
}
130+
}
131+
132+
void M2MLWClient::value_updated_function(const char* name) {
133+
if (name) {
134+
...
135+
}
136+
}
137+
138+
M2MResource* res = inst->create_dynamic_resource("D", "ResourceTest", true);
139+
char buffer[20];
140+
int size = sprintf(buffer,"%d",_value);
141+
res->set_operation(M2MBase::GET_PUT_POST_DELETE_ALLOWED);
142+
res->set_value((const uint8_t*)buffer, (const uint32_t)size);
143+
res->set_value_updated_function(value_updated_callback(this,&MbedClient::value_updated_function));
144+
/* Overloaded function can be used If callback function is not in class scope.
145+
res2->set_value_updated_function(value_updated_callback2(&value_updated_global));
146+
*/
147+
148+
```
122149

123150
## The Write Attributes operation
124151

@@ -182,7 +209,7 @@ if(_object) {
182209
(const uint32_t)size);
183210
res->set_execute_function(execute_callback(this,&M2MLWClient::execute_function));
184211
/* Overloaded function can be used If callback function is not in class scope.
185-
res->set_execute_function(&execute_function_2);
212+
res->set_execute_function(execute_callback_2(&execute_function_2));
186213
*/
187214
```
188215

0 commit comments

Comments
 (0)