implemented get_profile_pack_request
This commit is contained in:
parent
5e78b0df9b
commit
af54156f42
5 changed files with 140 additions and 38 deletions
|
@ -29,6 +29,17 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef octet_string sml_obj_req_entry;
|
||||
#define sml_obj_req_entry_parse(buf) sml_octet_string_parse(buf)
|
||||
#define sml_obj_req_entry_write(p, buf) sml_octet_string_write(p, buf)
|
||||
#define sml_obj_req_entry_free(p) sml_octet_string_free(p)
|
||||
|
||||
typedef struct sml_obj_req_entry_list_entry {
|
||||
sml_obj_req_entry *object_list_entry;
|
||||
|
||||
// list specific
|
||||
struct sml_obj_req_entry_list_entry *next;
|
||||
} sml_obj_req_entry_list;
|
||||
|
||||
typedef struct {
|
||||
octet_string *server_id; // optional
|
||||
|
@ -38,20 +49,16 @@ typedef struct {
|
|||
sml_time *begin_time; // optional
|
||||
sml_time *end_time; // optional
|
||||
sml_tree_path *parameter_tree_path;
|
||||
void *object_list; // sml_object_list * object_list; // optional sml_object_list not implemented yet
|
||||
sml_obj_req_entry_list *object_list; // optional
|
||||
sml_tree *das_details; // optional
|
||||
} sml_get_profile_pack_request;
|
||||
|
||||
|
||||
sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf);
|
||||
|
||||
sml_get_profile_pack_request *sml_get_profile_pack_request_init();
|
||||
|
||||
void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf);
|
||||
|
||||
void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,18 +23,15 @@
|
|||
#include <sml/sml_time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
sml_get_profile_pack_request *sml_get_profile_pack_request_init(){
|
||||
sml_get_profile_pack_request *msg = (sml_get_profile_pack_request *) malloc(sizeof(sml_get_profile_pack_request));
|
||||
memset(msg, 0, sizeof(sml_get_profile_pack_request));
|
||||
msg->parameter_tree_path = sml_tree_path_init();
|
||||
return msg;
|
||||
}
|
||||
|
||||
void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf) {
|
||||
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9);
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9);
|
||||
|
||||
sml_octet_string_write(msg->server_id, buf);
|
||||
sml_octet_string_write(msg->username, buf);
|
||||
sml_octet_string_write(msg->password, buf);
|
||||
|
@ -43,16 +40,28 @@ void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_b
|
|||
sml_time_write(msg->end_time, buf);
|
||||
sml_tree_path_write(msg->parameter_tree_path, buf);
|
||||
|
||||
printf("TODO: %s - some struct members aren't written", __FUNCTION__);
|
||||
sml_buf_optional_write(buf); // object_list
|
||||
sml_buf_optional_write(buf); // das_details
|
||||
if (msg->object_list) {
|
||||
int len = 1;
|
||||
sml_obj_req_entry_list *l = msg->object_list;
|
||||
for (l = msg->object_list; l->next; l = l->next) {
|
||||
len++;
|
||||
}
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, len);
|
||||
for (l = msg->object_list; l->next; l = l->next) {
|
||||
sml_obj_req_entry_write(l->object_list_entry, buf);
|
||||
}
|
||||
}
|
||||
else {
|
||||
sml_buf_optional_write(buf);
|
||||
}
|
||||
|
||||
sml_tree_write(msg->das_details, buf);
|
||||
}
|
||||
|
||||
|
||||
sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf) {
|
||||
|
||||
sml_get_profile_pack_request *msg = (sml_get_profile_pack_request *) malloc(sizeof(sml_get_profile_pack_request));
|
||||
memset(msg, 0, sizeof(sml_get_profile_pack_request));
|
||||
sml_get_profile_pack_request *msg = sml_get_profile_pack_request_init();
|
||||
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
|
@ -64,39 +73,70 @@ sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf
|
|||
goto error;
|
||||
}
|
||||
|
||||
printf("TODO:sml_get_profile_pack_request_parse -> not implemented yet");
|
||||
|
||||
/* msg->client_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
msg->username = sml_octet_string_parse(buf);
|
||||
msg->password = sml_octet_string_parse(buf);
|
||||
msg->with_rawdata = sml_boolean_parse(buf);
|
||||
msg->begin_time = sml_time_parse(buf);
|
||||
msg->end_time = sml_time_parse(buf);
|
||||
msg->parameter_tree_path = sml_tree_path_parse(buf);
|
||||
|
||||
if (!sml_buf_optional_is_skipped(buf)) {
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
int i, len = sml_buf_get_next_length(buf);
|
||||
sml_obj_req_entry_list *last = 0, *n = 0;
|
||||
for (i = len; i > 0; i--) {
|
||||
n = (sml_obj_req_entry_list *) malloc(sizeof(sml_obj_req_entry_list));
|
||||
memset(n, 0, sizeof(sml_obj_req_entry_list));
|
||||
n->object_list_entry = sml_obj_req_entry_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
if (msg->object_list == 0) {
|
||||
msg->object_list = n;
|
||||
last = msg->object_list;
|
||||
}
|
||||
else {
|
||||
last->next = n;
|
||||
last = n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg->list_name = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
*/
|
||||
/*msg->act_sensor_time = SML_SKIP_OPTIONAL sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->val_list = sml_list_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
msg->das_details = sml_tree_parse(buf);
|
||||
|
||||
msg->list_signature = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->act_gateway_time = SML_SKIP_OPTIONAL sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
*/
|
||||
|
||||
return msg;
|
||||
|
||||
error:
|
||||
error:
|
||||
sml_get_profile_pack_request_free(msg);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg){
|
||||
printf("NYI: %s\n", __FUNCTION__);
|
||||
if (msg) {
|
||||
sml_octet_string_free(msg->server_id);
|
||||
sml_octet_string_free(msg->username);
|
||||
sml_octet_string_free(msg->password);
|
||||
sml_boolean_free(msg->with_rawdata);
|
||||
sml_time_free(msg->begin_time);
|
||||
sml_time_free(msg->end_time);
|
||||
sml_tree_path_free(msg->parameter_tree_path);
|
||||
|
||||
if (msg->object_list) {
|
||||
sml_obj_req_entry_list *n = 0, *d = msg->object_list;
|
||||
do {
|
||||
n = d->next;
|
||||
sml_obj_req_entry_free(d->object_list_entry);
|
||||
free(d);
|
||||
d = n;
|
||||
} while (d);
|
||||
}
|
||||
sml_tree_free(msg->das_details);
|
||||
free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ OBJS = \
|
|||
src/sml_tree_test.o \
|
||||
src/sml_file_test.o \
|
||||
src/sml_open_request_test.o \
|
||||
src/sml_get_profile_pack_request_test.o \
|
||||
src/sml_message_test.o
|
||||
|
||||
test_run: libsml test
|
||||
|
|
53
test/src/sml_get_profile_pack_request_test.c
Normal file
53
test/src/sml_get_profile_pack_request_test.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed
|
||||
// DAI-Labor, TU-Berlin
|
||||
//
|
||||
// This file is part of libSML.
|
||||
//
|
||||
// libSML is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libSML is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../unity/unity_fixture.h"
|
||||
#include "test_helper.h"
|
||||
#include <sml/sml_get_profile_pack_request.h>
|
||||
|
||||
TEST_GROUP(sml_get_profile_pack_request);
|
||||
|
||||
sml_buffer *buf;
|
||||
|
||||
TEST_SETUP(sml_get_profile_pack_request) {
|
||||
buf = sml_buffer_init(512);
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(sml_get_profile_pack_request) {
|
||||
sml_buffer_free(buf);
|
||||
}
|
||||
|
||||
TEST(sml_get_profile_pack_request, init) {
|
||||
sml_get_profile_pack_request *r = sml_get_profile_pack_request_init();
|
||||
TEST_ASSERT_NOT_NULL(r);
|
||||
}
|
||||
|
||||
TEST(sml_get_profile_pack_request, parse) {
|
||||
hex2binary("7901010101010101730648616C6C6F0648616C6C6F0648616C6C6F01", sml_buf_get_current_buf(buf));
|
||||
sml_get_profile_pack_request *r = sml_get_profile_pack_request_parse(buf);
|
||||
TEST_ASSERT_NOT_NULL(r);
|
||||
TEST_ASSERT_NOT_NULL(r->object_list);
|
||||
TEST_ASSERT_NOT_NULL(r->object_list->next);
|
||||
TEST_ASSERT_NOT_NULL(r->object_list->next->next);
|
||||
TEST_ASSERT_NULL(r->object_list->next->next->next);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(sml_get_profile_pack_request) {
|
||||
RUN_TEST_CASE(sml_get_profile_pack_request, init);
|
||||
RUN_TEST_CASE(sml_get_profile_pack_request, parse);
|
||||
}
|
|
@ -31,6 +31,7 @@ static void runAllTests() {
|
|||
RUN_TEST_GROUP(sml_tree_path);
|
||||
RUN_TEST_GROUP(sml_proc_par_value);
|
||||
RUN_TEST_GROUP(sml_open_request);
|
||||
RUN_TEST_GROUP(sml_get_profile_pack_request);
|
||||
RUN_TEST_GROUP(sml_message);
|
||||
RUN_TEST_GROUP(sml_file);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue