| /* |
| * All Rights Reserved |
| * |
| * MARVELL CONFIDENTIAL |
| * Copyright 2012-2014 Marvell International Ltd All Rights Reserved. |
| * The source code contained or described herein and all documents related to |
| * the source code ("Material") are owned by Marvell International Ltd or its |
| * suppliers or licensors. Title to the Material remains with Marvell International Ltd |
| * or its suppliers and licensors. The Material contains trade secrets and |
| * proprietary and confidential information of Marvell or its suppliers and |
| * licensors. The Material is protected by worldwide copyright and trade secret |
| * laws and treaty provisions. No part of the Material may be used, copied, |
| * reproduced, modified, published, uploaded, posted, transmitted, distributed, |
| * or disclosed in any way without Marvell's prior express written permission. |
| * |
| * No license under any patent, copyright, trade secret or other intellectual |
| * property right is granted to or conferred upon you by disclosure or delivery |
| * of the Materials, either expressly, by implication, inducement, estoppel or |
| * otherwise. Any license under such intellectual property rights must be |
| * express and approved by Marvell in writing. |
| * |
| */ |
| |
| #include <apather.h> |
| |
| PathCmd cmd; |
| PathsList paths_list; |
| CommandRet command_ret; |
| |
| static int client_socket = -1; |
| #define PATHSTATUS_MAX 2048 |
| char pathstatus[PATHSTATUS_MAX] = {0}; |
| |
| static int list_paths() { |
| int i = 0; |
| printf("Paths list:\n"); |
| for(i = 0; i < paths_list.num; i++) { |
| printf(" : %s\n", paths_list.path[i]); |
| } |
| return 0; |
| } |
| |
| static int init_socket() { |
| |
| struct sockaddr_in client_addr; |
| bzero(&client_addr, sizeof(client_addr)); |
| client_addr.sin_family = AF_INET; |
| client_addr.sin_addr.s_addr = htons(INADDR_ANY); |
| client_addr.sin_port = htons(0); |
| |
| client_socket = socket(AF_INET, SOCK_STREAM, 0); |
| if (client_socket < 0) { |
| printf("Failed to create socket ...\n"); |
| return -1; |
| } |
| |
| struct linger so_linger; |
| so_linger.l_onoff = 1; |
| so_linger.l_linger = 0; |
| |
| setsockopt(client_socket, SOL_SOCKET, SO_LINGER, &so_linger, sizeof(so_linger)); |
| |
| if (bind(client_socket, (struct sockaddr*)&client_addr, sizeof(client_addr))) { |
| printf("Failed to bind the socket ...\n"); |
| goto init_error; |
| } |
| |
| struct sockaddr_in server_addr; |
| bzero(&server_addr, sizeof(server_addr)); |
| server_addr.sin_family = AF_INET; |
| server_addr.sin_addr.s_addr = htons(INADDR_ANY); |
| server_addr.sin_port = htons(SERVER_PORT); |
| |
| socklen_t server_addr_length = sizeof(server_addr); |
| if (connect(client_socket, (struct sockaddr*)&server_addr, server_addr_length) < 0) { |
| printf("Failed to connect the socket ...\n"); |
| goto init_error; |
| } |
| |
| return 0; |
| |
| init_error: |
| close(client_socket); |
| return -1; |
| |
| } |
| |
| static int help() { |
| printf("Usage: apather <options> [command]\n"); |
| printf("\nAvailable options:\n"); |
| printf(" -h, --help show this help\n"); |
| printf(" -l, --list list all paths from xml\n"); |
| printf(" -e, --enable <path> path to enable\n"); |
| printf(" -d, --disable <path> path to disable\n"); |
| printf(" -s, --setvolume <path> path to setvolume\n"); |
| printf(" -m, --mute <path> path to mute/unmute\n"); |
| printf(" -v, --volume <value> volume in dec to set\n"); |
| printf(" -t, --status path status\n"); |
| printf(" -c, --camera camera to use back mic\n"); |
| return 0; |
| } |
| |
| int main(int argc, char *argv[]) { |
| int need_help = 0; |
| int op = 0; |
| char path[MAX_PATH] = "\0"; |
| unsigned int volume = 0; |
| int enable = -1; |
| int use_camera = 0; |
| memset(&cmd, 0, sizeof(cmd)); |
| |
| static const struct option long_options[] = |
| { |
| {"help", 0, NULL, 'h'}, |
| {"list", 0, NULL, 'l'}, |
| {"status", 0, NULL, 't'}, |
| {"enable", 1, NULL, 'e'}, |
| {"disable", 1, NULL, 'd'}, |
| {"setvolume", 1, NULL, 's'}, |
| {"mute", 1, NULL, 'm'}, |
| {"volume", 1, NULL, 'v'}, |
| {"camera", 1, NULL, 'c'}, |
| {NULL, 0, NULL, 0}, |
| }; |
| |
| if (argc < 2) { |
| help(); |
| return 0; |
| } |
| |
| while (1) { |
| int c; |
| if ((c = getopt_long(argc, argv, "hlte:d:s:m:v:c", long_options, NULL)) < 0) |
| break; |
| switch (c) { |
| case 'h': |
| help(); |
| return 0; |
| case 'l': |
| op = OP_LIST; |
| break; |
| case 't': |
| op = OP_STATUS; |
| break; |
| case 'e': |
| strncpy(path, optarg, MAX_PATH); |
| op = OP_ENABLE; |
| break; |
| case 'd': |
| strncpy(path, optarg, MAX_PATH); |
| op = OP_DISABLE; |
| break; |
| case 's': |
| strncpy(path, optarg, MAX_PATH); |
| op = OP_SETVOLUME; |
| break; |
| case 'm': |
| strncpy(path, optarg, MAX_PATH); |
| op = OP_MUTE; |
| break; |
| case 'v': |
| volume = atol(optarg); |
| break; |
| case 'c': |
| use_camera = 1; |
| break; |
| default: |
| fprintf(stderr, "Invalid argument.\n"); |
| need_help++; |
| } |
| if (need_help) { |
| help(); |
| return 1; |
| } |
| } |
| |
| memset(&command_ret, 0, sizeof(command_ret)); |
| command_ret.ret = -1; |
| |
| if (op != 0) { |
| strncpy(cmd.path, path, MAX_PATH); |
| //cmd.volume = volume ? volume : 0xFF; |
| cmd.volume = volume; |
| cmd.op = op; |
| cmd.camera = use_camera; |
| if (init_socket() < 0) { |
| return -1; |
| } |
| int ret = send(client_socket, &cmd, sizeof(cmd), 0); |
| if (ret < 0) { |
| printf("Failed to send data to server ...\n"); |
| goto socket_error; |
| } |
| if (op == OP_LIST) { |
| ret = recv(client_socket, &paths_list, sizeof(paths_list), 0); |
| if (ret < 0) { |
| printf("Failed to receive paths list from server ...\n"); |
| goto socket_error; |
| } |
| list_paths(); |
| } else if (op == OP_STATUS) { |
| ret = recv(client_socket, pathstatus, PATHSTATUS_MAX, 0); |
| if (ret < 0) { |
| printf("Failed to receive paths status from server ...\n"); |
| goto socket_error; |
| } |
| printf("%s", pathstatus); |
| } else { |
| ret = recv(client_socket, &command_ret, sizeof(command_ret), 0); |
| if (ret < 0) { |
| printf("Failed to receive command return from server ...\n"); |
| goto socket_error; |
| } |
| if (command_ret.ret != ACM_RC_OK) { |
| printf("Failed to run the command. ErrorCode: \"%s\"\n", RetErrorString[command_ret.ret].info); |
| } |
| printf("%s\n", command_ret.comment); |
| } |
| close(client_socket); |
| } |
| return 0; |
| |
| socket_error: |
| close(client_socket); |
| return -1; |
| } |