Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mdmngr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IOPSYS
mdmngr
Commits
76d3fd75
Commit
76d3fd75
authored
7 years ago
by
Arun Muthusamy
Browse files
Options
Downloads
Patches
Plain Diff
fix struct typecast
parent
b885ca05
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+10
-5
10 additions, 5 deletions
Makefile
dongle_dynamic.c
+290
-0
290 additions, 0 deletions
dongle_dynamic.c
dongle_dynamic.h
+15
-0
15 additions, 0 deletions
dongle_dynamic.h
with
315 additions
and
5 deletions
Makefile
+
10
−
5
View file @
76d3fd75
...
...
@@ -4,10 +4,11 @@ LIBS = -lcurl -lxml2 -ljson-c -lubox -lubus
TMTOBILE
=
libmobile_test
TDONGLE
=
dongle_language
TDDONGLE
=
dongle_dynamic
TMOBILE1
=
libmobile1
TMOBILE2
=
libmobile2
all
:
libmobile1 libmobile2 ${TMTOBILE} ${TDONGLE}
all
:
libmobile1 libmobile2 ${TMTOBILE} ${TDONGLE}
${TDDONGLE}
MOBJS
=
libmobile.o
...
...
@@ -28,14 +29,18 @@ ${TMTOBILE}: ${MTOBJS}
${
CC
}
-o
${
TMTOBILE
}
${
MTOBJS
}
${
LIBS
}
DOBJS
=
libmobile.o common.o dongle_language.o
D
L
OBJS
=
libmobile.o common.o dongle_language.o
${TDONGLE}
:
${DOBJS}
${
CC
}
-o
${
TDONGLE
}
${
DOBJS
}
${
LIBS
}
${TDONGLE}
:
${D
L
OBJS}
${
CC
}
-o
${
TDONGLE
}
${
D
L
OBJS
}
${
LIBS
}
#*.o:*.c
# ${CC} ${CFLAGS} -o $@ $^
DDOBJS
=
libmobile.o common.o dongle_dynamic.o
${TDDONGLE}
:
${DDOBJS}
${
CC
}
-o
${
TDDONGLE
}
${
DDOBJS
}
${
LIBS
}
clean
:
rm
-f
${
TMTOBILE
}
${
TDONGLE
}
*
.o
*
.so
rm
-f
${
TMTOBILE
}
${
TDONGLE
}
${
TDDONGLE
}
*
.o
*
.so
This diff is collapsed.
Click to expand it.
dongle_dynamic.c
0 → 100644
+
290
−
0
View file @
76d3fd75
#include
"dongle_language.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
;
}
int
dongle_ubus_init
()
{
char
*
ubus_socket
=
NULL
;
uloop_init
();
ctx
=
ubus_connect
(
ubus_socket
);
if
(
!
ctx
)
return
(
1
);
ubus_add_uloop
(
ctx
);
return
0
;
}
void
dongle_ubus_destroy
()
{
ubus_free
(
ctx
);
}
#define DYNAMIC_OBJ_NAME_SIZE 50
struct
ubus_method
dynamic_object_methods
[]
=
{
//
};
struct
ubus_object_type
dynamic_object_type
=
UBUS_OBJECT_TYPE
(
"dongle"
,
dynamic_object_methods
);
//free memory..
//struct ubus_object *dongle_create_dynamic_object(struct device *dev_instance)
struct
ubus_object
*
dongle_create_dynamic_object
()
{
// if (!dev_instance->ip && !dev_instance->usb.product_id)
// goto fail_dev_instance;
struct
ubus_object
*
dynamic_dongle_object
;
struct
ubus_method
*
methods
;
struct
ubus_object_type
*
type
;
char
dynamic_dongle_name
[
DYNAMIC_OBJ_NAME_SIZE
];
//create dynmaic object name..
//snprintf(dynamic_dongle_name, DYNAMIC_OBJ_NAME_SIZE, "dongle.%s", dev_instance->usb.product_id);
snprintf
(
dynamic_dongle_name
,
DYNAMIC_OBJ_NAME_SIZE
,
"dongle.%s"
,
"hilink"
);
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
));
if
(
!
dynamic_dongle_object
)
{
perror
(
"dynamic_dongle_object"
);
goto
fail_calloc_obj
;
}
//name..
dynamic_dongle_object
->
name
=
dynamic_dongle_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
;
//methods..
dynamic_dongle_object
->
methods
=
type
->
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
);
return
NULL
;
}
void
dongle_destroy_dynamic_object
(
struct
ubus_object
*
obj
)
{
if
(
!
obj
)
return
;
if
(
obj
->
name
)
{
free
(
obj
->
name
);
obj
->
name
=
NULL
;
}
if
(
obj
->
type
)
free
(
obj
->
type
);
if
(
obj
)
free
(
obj
);
}
int
publish_ubus_object
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
)
{
int
ret
;
ret
=
ubus_add_object
(
ctx
,
obj
);
if
(
!
ret
)
{
printf
(
"Failed to publish object: %s
\n
"
,
obj
->
name
);
printf
(
"Failed to publish object error: %s
\n
"
,
ubus_strerror
(
ret
));
goto
leave
;
}
return
0
;
leave:
return
1
;
}
int
unpublish_ubus_object
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
)
{
int
ret
;
ret
=
ubus_remove_object
(
ctx
,
obj
);
if
(
!
ret
)
{
printf
(
"Failed to unpublish object: %s
\n
"
,
obj
->
name
);
printf
(
"Failed to unpublish object error: %s
\n
"
,
ubus_strerror
(
ret
));
goto
leave
;
}
return
0
;
leave:
return
1
;
}
int
expose_infrastructure_object
(
struct
ubus_context
*
ctx
)
{
int
rv
;
struct
ubus_object
*
uobj
;
uobj
=
dongle_create_dynamic_object
();
if
(
uobj
)
{
printf
(
"failed to create dynamic ubus obj"
);
return
1
;
}
if
(
publish_ubus_object
(
ctx
,
uobj
))
{
printf
(
"publish_ubus_object failed"
);
return
1
;
}
/* if (unpublish_ubus_object(ctx, uobj)) {
printf("unpublish_ubus_object failed");
return 1;
}
dongle_destroy_dynamic_object(uobj);
*/
return
0
;
}
int
main
()
{
int
rv
;
rv
=
dongle_ubus_init
();
if
(
rv
)
{
perror
(
"dongle ubus init"
);
printf
(
"Failed to connect to ubus
\n
"
);
return
EXIT_FAILURE
;
}
expose_infrastructure_object
(
ctx
);
//dongle_add_object(&langauge_object);
uloop_run
();
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
dongle_dynamic.h
0 → 100644
+
15
−
0
View file @
76d3fd75
#ifndef DONGLE_DYNAMIC
#define DONGLE_DYNAMIC
#include
<libubox/blobmsg_json.h>
#include
<libubus.h>
#include
<unistd.h>
#include
<pthread.h>
#include
<stdbool.h>
#include
"libmobile.h"
#include
"common.h"
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment