emuld: clean up prevent issues (removed warnings except vconf)
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Thu, 26 Sep 2013 04:04:09 +0000 (13:04 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Thu, 26 Sep 2013 04:08:09 +0000 (13:08 +0900)
include/emuld.h
packaging/emuld.spec
src/emuld.c
src/get_status.c

index 9a07b11abec4d8bd2405f77987c76433eed83d4e..aa1507793ff447e1b4dc180db752a6ff3c7d7ff4 100755 (executable)
@@ -90,7 +90,7 @@ void setting_location(char* databuf);
                log_print_out("[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); \
        } while (0)
 
-inline void log_print_out(char *fmt, ...)
+static inline void log_print_out(char *fmt, ...)
 {
 
 #ifdef EMD_DEBUG
index 974f5cacc2c2044a1f42dab5d4a96d109d38aa4f..39589f471ad8493c23b9cb817fb6d590ad06730d 100755 (executable)
@@ -1,6 +1,6 @@
 #git:/slp/pkgs/e/emulator-daemon
 Name: emuld
-Version: 0.2.40
+Version: 0.2.41
 Release: 1
 Summary: emuld is used for communication emulator between and ide.
 License: Apache
index f2719998351a24462fc4e13d0090f78a67303d54..19731d8080298179db2f67ee486210854cc4eb17 100755 (executable)
@@ -84,7 +84,7 @@ char SDpath[256];
 
 unsigned char ActionID = 0;
 char GetBuffer[256];
-void setting_device(); 
+void* setting_device();
 /*--------------------------------------------------------------*/
 /* FUNCTION PART 
    ---------------------------------------------------------------*/
@@ -177,6 +177,16 @@ void init_server0(int svr_port)
 } 
 /*------------------------------- end of function init_server0 */
 
+static void send_msg(int fd, const void* data, size_t len, int flag)
+{
+       size_t ret = 0;
+       ret = send(fd, data, len, flag);
+       if (ret < 0)
+       {
+               LOG("Sending data to fd %d failed.", fd);
+       }
+}
+
 void* init_vm_connect(void* data)
 {
        struct sockaddr_in vm_addr;
@@ -236,6 +246,17 @@ void* init_vm_connect(void* data)
        pthread_exit((void *) 0); 
 }
 
+void system_msg(const char* command)
+{
+       int ret = 0;
+
+       ret = system(command);
+       if (ret == -1)
+       {
+               LOG("system command (%s)failed.", command);
+       }
+}
+
 int is_mounted()
 {
        int ret = -1, i = 0;
@@ -287,7 +308,7 @@ void* mount_sdcard(void* data)
                                if(!S_ISBLK(buf.st_mode))
                                {
                                        sprintf(command, "rm -rf %s", file_name);
-                                       system(command);
+                                       system_msg(command);
                                }
                                else
                                        break;
@@ -307,13 +328,13 @@ void* mount_sdcard(void* data)
                                else
                                        packet->action = 5;     // failed
 
-                               send(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+                               send_msg(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
                                LOG("SDpath is %s", SDpath);
-                               send(g_sdcard_sockfd, SDpath, packet->length, 0);
+                               send_msg(g_sdcard_sockfd, SDpath, packet->length, 0);
 
                                if(ret == 0)
                                {
-                                       system("/usr/bin/sys_event mmcblk_add");
+                                       system_msg("/usr/bin/sys_event mmcblk_add");
                                }
                        }
                        break;
@@ -357,14 +378,14 @@ int umount_sdcard(void)
                                packet->group = 11;                             // sdcard
                                packet->action = 0;                             // unmounted
 
-                               send(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+                               send_msg(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
                                LOG("SDpath is %s", SDpath);
-                               send(g_sdcard_sockfd, SDpath, packet->length, 0);
+                               send_msg(g_sdcard_sockfd, SDpath, packet->length, 0);
                                
                                {
                                        memset(SDpath, '\0', sizeof(SDpath));
                                        sprintf(SDpath, "umounted");
-                                       system("/usr/bin/sys_event mmcblk_remove");
+                                       system_msg("/usr/bin/sys_event mmcblk_remove");
                                }
                        }
                        break;
@@ -623,11 +644,68 @@ int powerdown_by_force()
        return 1;
 }
 
+//sdcard event
+static void send_guest_server(char* databuf)
+{
+       if (!databuf)
+       {
+               LOG("invalid data buf");
+               return;
+       }
+
+       char buf[32];
+       struct sockaddr_in si_other;
+       int s, slen=sizeof(si_other);
+       FILE* fd;
+       char* ret = NULL;
+       char fbuf[16];
+       int port;
+       fd = fopen("/opt/home/sdb_port.txt", "r");
+       LOG("sdb_port.txt fopen fd is %d", fd);
+       if(!fd)
+       {
+               LOG("fopen /opt/home/sdb_port.txt fail");
+               port = 3581;
+       }
+       else
+       {
+               ret = fgets(fbuf, 16, fd);
+               if (ret == NULL)
+                       LOG("Failed to read sdb port");
+               fclose(fd);
+               port = atoi(fbuf) + 3;
+       }
+
+       if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
+       {
+               LOG("socket error!");
+               return;
+       }
+
+       memset((char *) &si_other, 0, sizeof(si_other));
+       si_other.sin_family = AF_INET;
+       si_other.sin_port = htons(port);
+       if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
+                 fprintf(stderr, "inet_aton() failed\n");
+       }
+
+       memset(buf, '\0', sizeof(buf));
+       snprintf(buf, sizeof(buf), "4\n%s", databuf);
+
+       LOG("sendGuestServer msg: %s", buf);
+       if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
+       {
+               LOG("sendto error!");
+       }
+
+       close(s);
+}
+
 void client_recv(int event_fd)
 {
        char* r_databuf = NULL;
        char tmpbuf[48];
-       int len = 0, recvd_size = 0, parse_len = 0;
+       int recvd_size = 0, parse_len = 0;
 
        if (event_fd == -1) {
                LOG("invalid event fd");
@@ -674,8 +752,8 @@ void client_recv(int event_fd)
 
                if(g_sdbd_sockfd != -1)
                {
-                       len = send(g_sdbd_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
-                       LOG("send_len: %d, next packet length: %d", len, packet->length);
+                       send_msg(g_sdbd_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+                       LOG("next packet length: %d", packet->length);
                }
 
                if (packet->length > 0)
@@ -686,8 +764,7 @@ void client_recv(int event_fd)
                                LOG("recv_len: %d, vmodem data recv buffer: %s", recvd_size, r_databuf);
                                if (recvd_size > 0)
                                {
-                                       len = send(g_sdbd_sockfd, r_databuf, packet->length, 0);
-                                       LOG("send_len: %d", len);
+                                       send_msg(g_sdbd_sockfd, r_databuf, packet->length, 0);
                                }
                        }
                        else
@@ -741,7 +818,7 @@ void client_recv(int event_fd)
                        }
 
                        recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
-                       len = send(g_vm_sockfd, r_databuf, HEADER_SIZE, 0);
+                       send_msg(g_vm_sockfd, r_databuf, HEADER_SIZE, 0);
 
                        memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
 
@@ -781,7 +858,7 @@ void client_recv(int event_fd)
                                LOG("Something may be added in the data end, but it does not matter.");
                                LOG("telephony data recv buffer: %s", r_databuf);
 
-                               len = send(g_vm_sockfd, r_databuf, packet->length, 0);
+                               send_msg(g_vm_sockfd, r_databuf, packet->length, 0);
                        }
                }
                else if(strncmp(tmpbuf, "sensor", 6) == 0)
@@ -911,7 +988,7 @@ void client_recv(int event_fd)
 
                        LOG("sync");
                        sync();
-                       system("/etc/rc.d/rc.shutdown &");
+                       system_msg("/etc/rc.d/rc.shutdown &");
                        gettimeofday(&tv_start_poweroff, NULL);
                        powerdown_by_force();
 
@@ -991,19 +1068,19 @@ void client_recv(int event_fd)
                                {
                                case 0:
                                        mntData->action = 2;                    // umounted status
-                                       send(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
+                                       send_msg(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
 
                                        LOG("SDpath is %s", SDpath);
-                                       send(g_sdcard_sockfd, SDpath, mntData->length, 0);
+                                       send_msg(g_sdcard_sockfd, SDpath, mntData->length, 0);
                                        memset(SDpath, '\0', sizeof(SDpath));
                                        sprintf(SDpath, "umounted");
                                        break;
                                case 1:
                                        mntData->action = 3;                    // mounted status
-                                       send(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
+                                       send_msg(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
 
                                        LOG("SDpath is %s", SDpath);
-                                       send(g_sdcard_sockfd, SDpath, mntData->length, 0);
+                                       send_msg(g_sdcard_sockfd, SDpath, mntData->length, 0);
                                        break;
                                default:
                                        break;
@@ -1103,7 +1180,7 @@ void end_server(int sig)
        exit(0);
 }
 
-void setting_device()
+void* setting_device()
 {
        pthread_detach(pthread_self());
 
@@ -1202,9 +1279,9 @@ void setting_device()
                        packet->group  = STATUS;
                        packet->action = ActionID;
                }
-               send(g_get_status_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+               send_msg(g_get_status_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
                if (packet->length != 0) {
-                       send(g_get_status_sockfd, msg, packet->length, 0);
+                       send_msg(g_get_status_sockfd, msg, packet->length, 0);
                }
        }
 
@@ -1242,18 +1319,18 @@ void setting_location(char* databuf)
                        break;
                }
                LOG("Location Command : %s", command);
-               system(command);
+               system_msg(command);
        } else {
                *s = '\0';
                int mode = atoi(databuf);
                if(mode == 1) { // NMEA MODE (LOG MODE)
                        sprintf(command, "vconftool set -t string db/location/replay/FileName \"%s\"", s+1);
                        LOG("%s", command);
-                       system(command);
+                       system_msg(command);
                        memset(command, 0, 256);
                        sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
                        LOG("%s", command);
-                       system(command);
+                       system_msg(command);
                } else if(mode == 2) {
                        memset(latitude,  0, 128);
                        memset(longitude, 0, 128);
@@ -1266,70 +1343,16 @@ void setting_location(char* databuf)
                        // Latitude
                        sprintf(command, "vconftool set -t double db/location/replay/ManualLatitude %s -f", latitude);
                        LOG("%s", command);
-                       system(command);
+                       system_msg(command);
 
                        // Longitude
                        sprintf(command, "vconftool set -t double db/location/replay/ManualLongitude %s -f", longitude);
                        LOG("%s", command);
-                       system(command);
+                       system_msg(command);
                }
        }
 }
 
-//sdcard event
-void send_guest_server(char* databuf)
-{
-       if (!databuf)
-       {
-               LOG("invalid data buf");
-               return;
-       }
-
-       char buf[32];
-       struct sockaddr_in si_other;
-       int s, slen=sizeof(si_other);
-       FILE* fd;
-       char fbuf[16];
-       int port;
-       fd = fopen("/opt/home/sdb_port.txt", "r");
-       LOG("sdb_port.txt fopen fd is %d", fd);
-       if(!fd)
-       {
-               LOG("fopen /opt/home/sdb_port.txt fail");
-               port = 3581;
-       }
-       else
-       {
-               fgets(fbuf, 16, fd);
-               fclose(fd);
-               port = atoi(fbuf) + 3;
-       }
-
-       if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
-       {
-               LOG("socket error!");
-               return;
-       }
-
-       memset((char *) &si_other, 0, sizeof(si_other));
-       si_other.sin_family = AF_INET;
-       si_other.sin_port = htons(port);
-       if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
-                 fprintf(stderr, "inet_aton() failed\n");
-       }
-
-       memset(buf, '\0', sizeof(buf));
-       snprintf(buf, sizeof(buf), "4\n%s", databuf);
-
-       LOG("sendGuestServer msg: %s", buf);
-       if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
-       {
-               LOG("sendto error!");
-       }
-
-       close(s);
-}
-
 int main( int argc , char *argv[])
 {
        int state;
@@ -1337,8 +1360,8 @@ int main( int argc , char *argv[])
        if(log_print == 1)
        {
                // for emuld log file
-               system("rm /opt/sensor/emuld.log");
-               system("touch /opt/sensor/emuld.log");
+               system_msg("rm /opt/sensor/emuld.log");
+               system_msg("touch /opt/sensor/emuld.log");
        }
 
        LOG("start");
@@ -1383,5 +1406,7 @@ int main( int argc , char *argv[])
        state = pthread_mutex_destroy(&mutex_vmconnect);
 
        fprintf(stderr, "emuld exit\n");
+
+       return 0;
 }
 
index fb033d19927c122631c5aad497b7ffdd42423e85..c0f3254d4db881c7ca5c15c95c54e3449d52e55e 100644 (file)
  */
 
 //#include <vconf.h>
+#include "emuld.h"
 #include "emuld_common.h"
 
+static int file_read(FILE* fd)
+{
+       int ret = 0;
+       int status = 0;
+       ret = fscanf(fd, "%d", &status);
+       if (ret < 0)
+               LOG("fscanf failed with fd: %d", fd);
+
+       return status;
+}
 
 char* message;
 char* get_usb_status(void* p)
@@ -38,8 +49,7 @@ char* get_usb_status(void* p)
                return 0;
        }
 
-       int status = 0;
-       fscanf(fd, "%d", &status);
+       int status = file_read(fd);
        fclose(fd);
 
        // int to byte
@@ -67,8 +77,7 @@ char* get_earjack_status(void* p)
                return 0;
        }
 
-       int status = 0;
-       fscanf(fd, "%d", &status);
+       int status = file_read(fd);
        fclose(fd);
 
        // int to byte
@@ -121,8 +130,7 @@ char* get_battery_level(void* p)
                return 0;
        }
 
-       int level = 0;
-       fscanf(fd, "%d", &level);
+       int level = file_read(fd);
        fclose(fd);
 
        // int to byte
@@ -150,12 +158,11 @@ char* get_battery_charger(void* p)
                return 0;
        }
 
-       int charge = 0;
-       fscanf(fd, "%d", &charge);
+       int charge = file_read(fd);
        fclose(fd);
+
        // int to byte
        message = (char*)malloc(5);
-
        message[3] = (char) (charge & 0xff);
        message[2] = (char) (charge >> 8 & 0xff);
        message[1] = (char) (charge >> 16 & 0xff);
@@ -179,9 +186,9 @@ char* get_proximity_status(void* p)
                return 0;
        }
 
-       int status = 0;
-       fscanf(fd, "%d", &status);
+       int status = file_read(fd);
        fclose(fd);
+
        // int to byte
        message = (char*)malloc(5);
 
@@ -208,8 +215,7 @@ char* get_light_level(void* p)
                return 0;
        }
 
-       int level = 0;
-       fscanf(fd, "%d", &level);
+       int level = file_read(fd);
        fclose(fd);
 
        // int to byte
@@ -231,6 +237,7 @@ char* get_light_level(void* p)
 
 char* get_acceleration_value(void* p)
 {
+       char* ret = NULL;
        FILE* fd = fopen("/opt/sensor/accel/xyz", "r");
        if(!fd)
        {
@@ -239,7 +246,10 @@ char* get_acceleration_value(void* p)
 
        message = (char*)malloc(128);
        //fscanf(fd, "%d, %d, %d", message);
-       fgets(message, 128, fd);
+       ret = fgets(message, 128, fd);
+       if (ret == NULL)
+               LOG("getting accel xyz value failed.");
+
        fclose(fd);
 
        LXT_MESSAGE* packet = p;
@@ -253,15 +263,12 @@ char* get_acceleration_value(void* p)
 
 char* get_gyroscope_value(void* p)
 {
-       int x;
-       int y;
-       int z;
        FILE* fd = fopen("/opt/sensor/gyro/gyro_x_raw", "r");
        if(!fd)
        {
                return 0;
        }
-       fscanf(fd, "%d", &x);
+       int x = file_read(fd);
        fclose(fd);
 
        fd = fopen("/opt/sensor/gyro/gyro_y_raw", "r");
@@ -269,7 +276,7 @@ char* get_gyroscope_value(void* p)
        {
                return 0;
        }
-       fscanf(fd, "%d", &y);
+       int y = file_read(fd);
        fclose(fd);
 
        fd = fopen("/opt/sensor/gyro/gyro_z_raw", "r");
@@ -277,7 +284,7 @@ char* get_gyroscope_value(void* p)
        {
                return 0;
        }
-       fscanf(fd, "%d", &z);
+       int z = file_read(fd);
        fclose(fd);
  
        message = (char*)malloc(128);
@@ -299,6 +306,7 @@ char* get_gyroscope_value(void* p)
 
 char* get_magnetic_value(void* p)
 {
+       char* ret = NULL;
        FILE* fd = fopen("/opt/sensor/geo/tesla", "r");
        if(!fd)
        {
@@ -306,7 +314,9 @@ char* get_magnetic_value(void* p)
        }
 
        message = (char*)malloc(128);
-       fgets(message, 128, fd);
+       ret = fgets(message, 128, fd);
+       if (ret == NULL)
+               LOG("getting tesla value failed.");
        fclose(fd);
 
        LXT_MESSAGE* packet = p;
@@ -377,6 +387,7 @@ char* get_location_status(void* p)
 
 char* get_nfc_status(void* p)
 {
+       int ret = 0;
        FILE* fd = fopen("/opt/nfc/sdkMsg", "r");
        if(!fd)
        {
@@ -384,7 +395,9 @@ char* get_nfc_status(void* p)
        }
 
        message = (char*)malloc(5000);
-       fscanf(fd, "%s\n", message);
+       ret = fscanf(fd, "%s\n", message);
+       if (ret < 0)
+               LOG("fscanf failed with fd: %d", fd);
        fclose(fd);
 
        LXT_MESSAGE* packet = p;