blob: a933e9c20eff5f0343ac649ea11cfb10d9d77acb [file] [log] [blame]
xjd5ccac02022-04-02 15:41:13 +08001
2#include <stdio.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <string.h>
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <sys/un.h>
9#include <unistd.h>
10#include <dlfcn.h>
11
12#define LOG_TAG "libautosuspend"
13
14// #include <liblog/lynq_deflog.h>
15#include <log/log.h>
16
17#define SERVER_PATH "/tmp/autosuspend.server"
18// #define CLIENT_PATH "/tmp/autosuspend.client"
19
20
21static int send_cmd(char * value,int len)
22{
23 int client_sock, rc;
24 struct sockaddr_un server_sockaddr;
25 struct sockaddr_un client_sockaddr;
26
27
28
29 if(value == NULL)
30 {
31 return -1;
32 }
33
34 /**************************************/
35 /* Create a UNIX domain stream socket */
36 /**************************************/
37 client_sock = socket(AF_UNIX, SOCK_STREAM, 0);
38 if (client_sock == -1) {
39 ALOGI("SOCKET ERROR ");
40 return -5;
41 }
42
43 /***************************************/
44 /* Set up the UNIX sockaddr structure */
45 /* by using AF_UNIX for the family and */
46 /* giving it a filepath to bind to. */
47 /* */
48 /* Unlink the file so the bind will */
49 /* succeed, then bind to that file. */
50 /***************************************/
51 client_sockaddr.sun_family = AF_UNIX;
52 // strcpy(client_sockaddr.sun_path, CLIENT_PATH);
53 sprintf(client_sockaddr.sun_path,"/tmp/suspend.%d.client",(int)getpid());
54 len = sizeof(client_sockaddr);
55
56 unlink(client_sockaddr.sun_path);
57 rc = bind(client_sock, (struct sockaddr *) &client_sockaddr, len);
58 if (rc == -1){
59 ALOGI("BIND ERROR ");
60 close(client_sock);
61 return -4;
62 }
63
64 /***************************************/
65 /* Set up the UNIX sockaddr structure */
66 /* for the server socket and connect */
67 /* to it. */
68 /***************************************/
69 server_sockaddr.sun_family = AF_UNIX;
70 strcpy(server_sockaddr.sun_path, SERVER_PATH);
71 rc = connect(client_sock, (struct sockaddr *) &server_sockaddr, len);
72 if(rc == -1){
73 ALOGI("CONNECT ERROR ");
74 close(client_sock);
75 return -3;
76 }
77
78 /************************************/
79 /* Copy the data to the buffer and */
80 /* send it to the server socket. */
81 /************************************/
82 // strcpy(buf, DATA);
83 printf("Sending data...\n");
84 rc = send(client_sock, value, len, 0);
85 if (rc == -1) {
86 ALOGI("SEND ERROR ");
87 close(client_sock);
88 return -2;
89 }
90 else {
91 ALOGI("Data sent: %s\n",value);
92 }
93
94 close(client_sock);
95
96 return rc;
97
98}
99
100int lynq_autosleep_enable(void)
101{
102 char value[15]="enable";
103 int rc = send_cmd(value,strlen(value));
104 if(rc < 0)
105 {
106 ALOGI("libautosleep_enable ret %d\n",rc);
107 }
108 return rc;
109}
110
111int lynq_autosleep_disable(void)
112{
113 char value[15]="disable";
114 int rc = send_cmd(value,strlen(value));
115 if(rc < 0)
116 {
117 ALOGI("libautosleep_disable ret %d\n",rc);
118 }
119 return rc;
120
121}
122
123
124
125