Skip to content

Commit b4cb0d3

Browse files
Yogesh PandeYogesh Pande
Yogesh Pande
authored and
Yogesh Pande
committed
Test for Device Object Management.
1 parent cd71e4e commit b4cb0d3

15 files changed

+749
-197
lines changed

Makefile

+1-33
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ ifeq ($(DEBUG),1)
4141
override CFLAGS += -DHAVE_DEBUG
4242
endif
4343

44-
TESTDIRS := $(UNITTESTS:%=build-%)
45-
CLEANTESTDIRS := $(UNITTESTS:%=clean-%)
4644
COVERAGEFILE := ./lcov/coverage.info
4745

4846
#
@@ -55,37 +53,7 @@ $(eval $(call generate_rules,$(LIB),$(SRCS)))
5553
# Extend default clean rule
5654
clean: clean-extra
5755

58-
.PHONY: release
59-
release:
60-
7z a nanostack_$(VERSION).zip *.a *.lib include
61-
62-
$(TESTDIRS):
63-
@make -C $(@:build-%=%)
64-
6556
$(CLEANDIRS):
6657
@make -C $(@:clean-%=%) clean
6758

68-
$(CLEANTESTDIRS):
69-
@make -C $(@:clean-%=%) clean
70-
71-
.PHONY: test
72-
test: $(TESTDIRS)
73-
@mkdir -p lcov
74-
@mkdir -p lcov/results
75-
@rm -f lcov/results/*
76-
@find ./test -name '*.xml' | xargs cp -t ./lcov/results/
77-
@rm -f lcov/index.xml
78-
@./xsl_script.sh
79-
@cp junit_xsl.xslt lcov/.
80-
@xsltproc -o lcov/testresults.html lcov/junit_xsl.xslt lcov/index.xml
81-
@rm -f lcov/junit_xsl.xslt
82-
@rm -f lcov/index.xml
83-
@rm -rf lcov/results
84-
@lcov -d test/. -c -o $(COVERAGEFILE)
85-
@lcov -q -r $(COVERAGEFILE) "/usr*" -o $(COVERAGEFILE)
86-
@lcov -q -r $(COVERAGEFILE) "/test*" -o $(COVERAGEFILE)
87-
@genhtml -q $(COVERAGEFILE) --show-details --prefix $(CURDIR:%/applications/libService=%) --output-directory lcov/html
88-
@echo LibService unit tests built
89-
90-
clean-extra: $(CLEANDIRS) \
91-
$(CLEANTESTDIRS)
59+
clean-extra: $(CLEANDIRS)

mbed-client/m2mbase.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,23 @@ class M2MBase : public M2MReportObserver {
7878
* supported by a given resource.
7979
*/
8080
typedef enum {
81-
NOT_ALLOWED = 0x00,
82-
GET_ALLOWED = 0x01,
83-
PUT_ALLOWED = 0x02,
84-
GET_PUT_ALLOWED = 0x03,
85-
POST_ALLOWED = 0x04,
86-
GET_POST_ALLOWED = 0x05,
87-
PUT_POST_ALLOWED = 0x06,
88-
GET_PUT_POST_ALLOWED = 0x07,
89-
DELETE_ALLOWED = 0x08
81+
NOT_ALLOWED = 0x00,
82+
GET_ALLOWED = 0x01,
83+
PUT_ALLOWED = 0x02,
84+
GET_PUT_ALLOWED = 0x03,
85+
POST_ALLOWED = 0x04,
86+
GET_POST_ALLOWED = 0x05,
87+
PUT_POST_ALLOWED = 0x06,
88+
GET_PUT_POST_ALLOWED = 0x07,
89+
DELETE_ALLOWED = 0x08,
90+
GET_DELETE_ALLOWED = 0x09,
91+
PUT_DELETE_ALLOWED = 0x0A,
92+
GET_PUT_DELETE_ALLOWED = 0x0B,
93+
POST_DELETE_ALLOWED = 0x0C,
94+
GET_POST_DELETE_ALLOWED = 0x0D,
95+
PUT_POST_DELETE_ALLOWED = 0x0E,
96+
GET_PUT_POST_DELETE_ALLOWED = 0x0F,
97+
9098
}Operation;
9199

92100
protected:

mbed-client/m2mconstants.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const uint8_t LENGTH8 = 0x08;
143143
const uint8_t LENGTH16 = 0x10;
144144
const uint8_t LENGTH24 = 0x18;
145145

146-
const int COAP_CONTENT_OMA_TLV_TYPE = 99;
147-
const int COAP_CONTENT_OMA_JSON_TYPE = 100;
146+
const uint8_t COAP_CONTENT_OMA_TLV_TYPE = 99;
147+
const uint8_t COAP_CONTENT_OMA_JSON_TYPE = 100;
148148

149149
#endif // M2MCONSTANTS_H

mbed-client/m2mresource.h

+22
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ friend class M2MObjectInstance;
142142
*/
143143
virtual void remove_observation_level(M2MBase::Observation observation_level);
144144

145+
/**
146+
* @brief Handles GET request for the registered objects.
147+
* @param nsdl, NSDL handler for the Coap library.
148+
* @param received_coap_header, Received CoAP message from the server.
149+
* @param observation_handler, Handler object for sending
150+
* observation callbacks.
151+
* @return sn_coap_hdr_s, Message that needs to be sent to server.
152+
*/
153+
virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl,
154+
sn_coap_hdr_s *received_coap_header,
155+
M2MObservationHandler *observation_handler = NULL);
156+
/**
157+
* @brief Handles PUT request for the registered objects.
158+
* @param nsdl, NSDL handler for the Coap library.
159+
* @param received_coap_header, Received CoAP message from the server.
160+
* @param observation_handler, Handler object for sending
161+
* observation callbacks.
162+
* @return sn_coap_hdr_s, Message that needs to be sent to server.
163+
*/
164+
virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl,
165+
sn_coap_hdr_s *received_coap_header,
166+
M2MObservationHandler *observation_handler = NULL);
145167

146168
private:
147169

mbed-client/m2mresourceinstance.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ friend class M2MResource;
187187
M2MObservationHandler *observation_handler = NULL);
188188

189189
/**
190-
* @brief Handles GET request for the registered objects.
190+
* @brief Handles POST request for the registered objects.
191191
* @param nsdl, NSDL handler for the Coap library.
192192
* @param received_coap_header, Received CoAP message from the server.
193193
* @param observation_handler, Handler object for sending

source/include/m2mtlvdeserializer.h

+59-18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ class M2MTLVDeserializer {
2929

3030
public :
3131

32+
typedef enum {
33+
None,
34+
NotFound,
35+
NotAllowed,
36+
NotValid
37+
} Error;
38+
39+
typedef enum {
40+
Put,
41+
Post
42+
} Operation;
43+
44+
3245
/**
3346
* Constructor.
3447
*/
@@ -79,33 +92,61 @@ public :
7992
/**
8093
* Deserialises the given binary that must encode object instances. Binary
8194
* array can be checked before invoking this method with
82-
* {@link #isObjectInstance(byte[])}.
83-
* @param tlv Binary in OMA-TLV format
84-
* @return List of <code>M2MObjectInstance</code> objects.
85-
* @throws IllegalArgumentException if given binary is not a valid OMA-TLV
86-
* or it encodes a structure other than object instances.
87-
* @see #deserializeResources(byte[])
8895
*/
89-
void deserialise_object_instances(uint8_t* tlv, uint32_t tlv_size, M2MObjectInstanceList &list);
96+
M2MTLVDeserializer::Error deserialise_object_instances(uint8_t* tlv,
97+
uint32_t tlv_size,
98+
M2MObject &object,
99+
M2MTLVDeserializer::Operation operation);
90100

91101
/**
92102
* Deserialises the given binary that must encode resources. Binary array
93-
* can be checked before invoking this method with {@link #isResource(byte[])}.
94-
* @param tlv Binary in OMA-TLV format
95-
* @return List of <code>M2MObjectInstance</code> objects.
96-
* @throws IllegalArgumentException if given binary is not a valid OMA-TLV
97-
* or it encodes a structure other than object instances.
98-
* @see #deserializeResources(byte[])
103+
* can be checked before invoking this method.
104+
*/
105+
M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv,
106+
uint32_t tlv_size,
107+
M2MObjectInstance &object_instance,
108+
M2MTLVDeserializer::Operation operation);
109+
110+
/**
111+
* Deserialises the given binary that must encode resource instances. Binary array
112+
* can be checked before invoking this method.
99113
*/
100-
void deserialize_resources(uint8_t *tlv, uint32_t tlv_size, M2MResourceList &list);
114+
M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
115+
uint32_t tlv_size,
116+
M2MResource &resource,
117+
M2MTLVDeserializer::Operation operation);
118+
101119

102120
private:
103121

104-
void deserialize_object_instances(uint8_t *tlv, uint32_t tlv_size, uint32_t offset, M2MObjectInstanceList &list);
105-
106-
void deserialize_resources(uint8_t *tlv, uint32_t tlv_size, uint32_t offset, M2MResourceList &list);
122+
M2MTLVDeserializer::Error deserialize_object_instances(uint8_t *tlv,
123+
uint32_t tlv_size,
124+
uint32_t offset,
125+
M2MObject &object,
126+
M2MTLVDeserializer::Operation operation,
127+
bool update_value);
107128

108-
void deserialize_resource_instances(uint8_t *tlv, uint32_t tlv_size, uint32_t offset, M2MResourceInstanceList &list);
129+
M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv,
130+
uint32_t tlv_size,
131+
uint32_t offset,
132+
M2MObjectInstance &object_instance,
133+
M2MTLVDeserializer::Operation operation,
134+
bool update_value);
135+
136+
M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
137+
uint32_t tlv_size,
138+
uint32_t offset,
139+
M2MResource &resource,
140+
M2MObjectInstance &object_instance,
141+
M2MTLVDeserializer::Operation operation,
142+
bool update_value);
143+
144+
M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
145+
uint32_t tlv_size,
146+
uint32_t offset,
147+
M2MResource &resource,
148+
M2MTLVDeserializer::Operation operation,
149+
bool update_value);
109150

110151
bool is_object_instance(uint8_t *tlv, uint32_t offset);
111152

source/include/m2mtlvserializer.h

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class M2MTLVSerializer {
8282
*/
8383
uint8_t* serialize(M2MResourceList resource_list, uint32_t &size);
8484

85+
uint8_t* serialize(M2MResource *resource, uint32_t &size);
86+
8587
private :
8688

8789
uint8_t* serialize_object_instances(M2MObjectInstanceList object_instance_list, uint32_t &size);

source/m2mnsdlinterface.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,12 @@ uint8_t M2MNsdlInterface::received_from_server_callback(struct nsdl_s * /*nsdl_h
454454
if(base) {
455455
M2MObject* object = (M2MObject*)base;
456456
object->create_object_instance(instance_id);
457-
coap_response = object->handle_post_request(_nsdl_handle,
458-
coap_header,
459-
this);
457+
value_updated(object);
460458
} else {
461459
coap_response = sn_nsdl_build_response(_nsdl_handle,
462460
coap_header,
463461
COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED);
464462
}
465-
466463
}
467464
}else{
468465
coap_response = sn_nsdl_build_response(_nsdl_handle,
@@ -827,6 +824,8 @@ bool M2MNsdlInterface::create_nsdl_resource_structure(M2MResource *res,
827824

828825
success = create_nsdl_resource((*it),inst_name);
829826
}
827+
// Register the main Resource as well along with ResourceInstances
828+
success = create_nsdl_resource(res,res_name);
830829
}
831830
} else {
832831
tr_debug("M2MNsdlInterface::create_nsdl_resource_structure - res_name %s", res_name.c_str());

0 commit comments

Comments
 (0)