1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*******************************************************************************
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <orchestration_client.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
#define SERVICE_NAME "chromium-renderer"
#define PACKAGE_NAME "org.chromium.chrome"
int get_ip_addr(char ipstr[40]) {
int fd;
struct ifreq ifr;
char *addr = {0, };
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd == -1) {
printf("socket failed");
exit(EXIT_FAILURE);
}
ifr.ifr_addr.sa_family = AF_INET;
/* I want IP address attached to "wlan0" */
strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ-1);
ioctl(fd, SIOCGIFADDR, &ifr);
close(fd);
addr = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
strncpy(ipstr, addr, MIN(strlen(addr), 40 - 1));
return 0;
}
void status_cb(orchestration_service_status_e staus, void* user_data)
{
}
int main() {
char exec_param[512] = {0, };
char params[256] = " --type=renderer --server-address=";
char ipstr[40] = {0, };
if (get_ip_addr(ipstr) != 0) {
printf("error from getting ip addr\n");
return 0;
}
strncat(params, ipstr, strlen(ipstr));
strncat(exec_param, PACKAGE_NAME, strlen(PACKAGE_NAME));
strncat(exec_param, params, strlen(params));
orchestration_service_info_s service_info;
service_info.count = 1;
service_info.services[0].exec_type = "android";
service_info.services[0].exec_parameter = exec_param;
printf("service_info.exec_parameter: %s\n", service_info.services[0].exec_parameter);
orchestration_request_service(SERVICE_NAME, service_info, status_cb, NULL);
return 0;
}
|