blob: 80c4d80ff6895c10bb2dd65633b87f31863f1068 [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <auto_header>
2 * <FILENAME>
3 *
4 * INTEL CONFIDENTIAL
5 * Copyright © 2011 Intel
6 * Corporation All Rights Reserved.
7 *
8 * The source code contained or described herein and all documents related to
9 * the source code ("Material") are owned by Intel Corporation or its suppliers
10 * or licensors. Title to the Material remains with Intel Corporation or its
11 * suppliers and licensors. The Material contains trade secrets and proprietary
12 * and confidential information of Intel or its suppliers and licensors. The
13 * Material is protected by worldwide copyright and trade secret laws and
14 * treaty provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed, or
16 * disclosed in any way without Intel’s prior express written permission.
17 *
18 * No license under any patent, copyright, trade secret or other intellectual
19 * property right is granted to or conferred upon you by disclosure or delivery
20 * of the Materials, either expressly, by implication, inducement, estoppel or
21 * otherwise. Any license under such intellectual property rights must be
22 * express and approved by Intel in writing.
23 *
24 * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
25 * CREATED: 2011-06-01
26 * UPDATED: 2011-07-27
27 *
28 *
29 * </auto_header>
30 */
31#include <iostream>
32#include <stdlib.h>
33#include "RequestMessage.h"
34#include "AnswerMessage.h"
35#include "ConnectionSocket.h"
36
37using namespace std;
38
39// <program> <target> <port> <cmd> <arg>*
40int main(int argc, char *argv[])
41{
42 // Enough args?
43 if (argc < 4) {
44
45 cerr << "Missing arguments" << endl;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020046 cerr << "Usage: " << argv[0] << " <target> <port> <cmd> <arg>*" << endl;
Patrick Benavoli68a91282011-08-31 11:23:23 +020047
48 return -1;
49 }
50 // Get port number
51 uint16_t uiPort = (uint16_t)strtoul(argv[2], NULL, 0);
52
53 // Connect to target
54 CConnectionSocket connectionSocket;
55
56 // Set timeout
57 connectionSocket.setTimeout(5000);
58
59 string strError;
60 // Connect
61 if (!connectionSocket.connect(argv[1], uiPort, strError)) {
62
63 cerr << strError << endl;
64
65 return -2;
66 }
67
68 // Create command message
69 CRequestMessage requestMessage(argv[3]);
70
71 // Add arguments
72 uint32_t uiArg;
73
74 for (uiArg = 4; uiArg < (uint32_t)argc; uiArg++) {
75
76 requestMessage.addArgument(argv[uiArg]);
77 }
78
79 ///// Send command
80 if (!requestMessage.serialize(&connectionSocket, true)) {
81
82 cerr << "Unable to send command to target" << endl;
83
84 return -3;
85 }
86
87 // Create answer message
88 CAnswerMessage answerMessage;
89
90 ///// Get answer
91 if (!answerMessage.serialize(&connectionSocket, false)) {
92
93 cerr << "No answer received from target" << endl;
94
95 return -4;
96 }
97
98 // Success?
99 if (!answerMessage.success()) {
100
101 // Display error answer
102 cerr << answerMessage.getAnswer() << endl;
103 } else {
104
105 // Display success answer
106 cout << answerMessage.getAnswer() << endl;
107 }
108
109 // Program status
110 return answerMessage.success() ? 0 : -5;
111}