Skip to content
Snippets Groups Projects
Commit b7b39d65 authored by Arun Muthusamy's avatar Arun Muthusamy
Browse files

fix dynamic dongle obj memory alloc

parent 76d3fd75
No related branches found
No related tags found
No related merge requests found
#include "dongle_language.h"
#include "dongle_dynamic.h"
static struct blob_buf blob_buffer;
static struct ubus_context *ctx = NULL;
enum {
LANGUAGE_NAME,
__LANGUAGE_MAX,
};
const struct blobmsg_policy set_language_policy[__LANGUAGE_MAX] = {
[LANGUAGE_NAME] = {.name = "profile_name", .type = BLOBMSG_TYPE_STRING},
};
int
set_language(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
system("echo set language ubus method called > /dev/console");
struct blob_attr *tb[__LANGUAGE_MAX];
char language_name[128];
struct write_result *response;
if (blobmsg_parse(set_language_policy, __LANGUAGE_MAX, tb, blob_data(msg), blob_len(msg)) != 0) {
fprintf(stderr, "set_language blob Parse failed\n");
goto leave_blobmsg_parse;
}
if (!tb[LANGUAGE_NAME])
goto leave_null_argument;
memset(language_name, 0, sizeof(language_name));
strncpy(language_name, blobmsg_get_string(tb[LANGUAGE_NAME]), 127);
printf("Input language name is: %s\n", language_name);
response = mobile_set_language(language_name);
if (!response->data)
goto leave_response;
//return print_to_ubus(response, ctx, req);
leave_response:
return UBUS_STATUS_NO_DATA;
leave_null_argument:
return UBUS_STATUS_INVALID_ARGUMENT;
leave_blobmsg_parse:
return UBUS_STATUS_INVALID_ARGUMENT;
}
int
get_language(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
system("echo file_status called > /dev/console");
struct write_result *response;
char *result;
response = mobile_get_language();
printf("mobile_set_language response: %s\n", response->data);
result = xml_parser(response, "//CurrentLanguage");
blob_buf_init(&blob_buffer, 0);
blobmsg_add_string(&blob_buffer, "langauge", result);
ubus_send_reply(ctx, req, blob_buffer.head);
return 0;
}
struct ubus_method language_object_methods[] = {
UBUS_METHOD("set_language", set_language, set_language_policy),
UBUS_METHOD_NOARG("get_language", get_language),
};
struct ubus_object_type language_object_type = UBUS_OBJECT_TYPE("dongle", language_object_methods);
struct ubus_object langauge_object = {
.name = "dongle.langauge",
.type = &language_object_type,
.methods = language_object_methods,
.n_methods = ARRAY_SIZE(language_object_methods),
};
int
dongle_add_object(struct ubus_object *obj)
{
int ret = ubus_add_object(ctx, obj);
if (ret != 0)
{
fprintf(stderr, "Failed to publish object (%s)\n", obj->name);
return 1;
}
return 0;
}
#define DYNAMIC_OBJ_NAME_SIZE 50
int
dongle_ubus_init()
......@@ -132,12 +29,7 @@ dongle_ubus_destroy()
ubus_free(ctx);
}
#define DYNAMIC_OBJ_NAME_SIZE 50
struct ubus_method dynamic_object_methods[] = {
//
};
struct ubus_method dynamic_object_methods[] = {};
struct ubus_object_type dynamic_object_type = UBUS_OBJECT_TYPE("dongle", dynamic_object_methods);
......@@ -159,36 +51,33 @@ struct ubus_object *dongle_create_dynamic_object()
printf("dynamic_dongle_name: %s\n", dynamic_dongle_name);
//create ubus object instance..
dynamic_dongle_object = (struct ubus_object *)calloc(1, sizeof(dynamic_dongle_object));
printf("calloc intialize : dynamic_dongle_object\n");
dynamic_dongle_object = (struct ubus_object *)calloc(1, sizeof(struct ubus_object));
if (!dynamic_dongle_object) {
perror("dynamic_dongle_object");
goto fail_calloc_obj;
}
printf("calloc done: dynamic_dongle_object\n");
//name..
dynamic_dongle_object->name = dynamic_dongle_name;
dynamic_dongle_object->name = strndup(dynamic_dongle_name, DYNAMIC_OBJ_NAME_SIZE);
printf("object name %s\n", dynamic_dongle_object->name);
//type..
type = calloc(1, sizeof(dynamic_object_type));
if (!type) {
perror("type");
goto fail_calloc_type;
}
memcpy(type, &dynamic_object_type, sizeof(dynamic_object_type));
dynamic_dongle_object->type = type;
dynamic_dongle_object->type = &dynamic_object_type;
//methods..
dynamic_dongle_object->methods = type->methods;
dynamic_dongle_object->methods = dynamic_object_methods;
//method size..
dynamic_dongle_object->n_methods = ARRAY_SIZE(dynamic_object_methods);
return dynamic_dongle_object;
fail_dev_instance:
fail_calloc_obj:
fail_calloc_type:
free(dynamic_dongle_object);
fail_calloc_obj:
fail_dev_instance:
return NULL;
}
......@@ -213,7 +102,7 @@ int publish_ubus_object(struct ubus_context *ctx, struct ubus_object *obj)
int ret;
ret = ubus_add_object(ctx, obj);
if (!ret) {
if (ret != 0) {
printf("Failed to publish object: %s\n", obj->name);
printf("Failed to publish object error: %s\n", ubus_strerror(ret));
goto leave;
......@@ -250,12 +139,15 @@ int expose_infrastructure_object(struct ubus_context *ctx)
struct ubus_object *uobj;
uobj = dongle_create_dynamic_object();
if (uobj) {
printf("failed to create dynamic ubus obj");
if (!uobj) {
printf("failed to create dynamic ubus obj\n");
return 1;
}
if (publish_ubus_object(ctx, uobj)) {
printf("publish_ubus_object failed");
rv = publish_ubus_object(ctx, uobj);
printf("ret val: %d\n", rv);
if (rv) {
printf("publish_ubus_object failed\n");
return 1;
}
......@@ -282,8 +174,8 @@ main()
return EXIT_FAILURE;
}
expose_infrastructure_object(ctx);
//dongle_add_object(&langauge_object);
rv = expose_infrastructure_object(ctx);
printf("rv val at end: %d\n", rv);
uloop_run();
return EXIT_SUCCESS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment