forked from Kinetic/kinetic-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_teardown.c
90 lines (82 loc) · 2.58 KB
/
setup_teardown.c
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
84
85
86
87
88
89
90
/**
* Copyright 2013-2015 Seagate Technology LLC.
*
* This Source Code Form is subject to the terms of the Mozilla
* Public License, v. 2.0. If a copy of the MPL was not
* distributed with this file, You can obtain one at
* https://mozilla.org/MP:/2.0/.
*
* This program is distributed in the hope that it will be useful,
* but is provided AS-IS, WITHOUT ANY WARRANTY; including without
* the implied warranty of MERCHANTABILITY, NON-INFRINGEMENT or
* FITNESS FOR A PARTICULAR PURPOSE. See the Mozilla Public
* License for more details.
*
* See www.openkinetic.org for more project information
*/
#include "kinetic_client.h"
#include "kinetic_types.h"
#include "byte_array.h"
#include <stdlib.h>
#include <getopt.h>
#include <stdio.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <getopt.h>
static char *kinetic_host = "localhost";
static long idle_seconds = 0;
static void usage(void) {
fprintf(stderr, "usage: setup_teardown [-h KINETIC_HOST] [-i IDLE_SECONDS]\n");
exit(1);
}
static void handle_args(int argc, char **argv) {
int fl = 0;
while ((fl = getopt(argc, argv, "i:h:")) != -1) {
switch (fl) {
case 'h': /* host */
kinetic_host = optarg;
break;
case 'i': /* idle seconds */
idle_seconds = strtol(optarg, NULL, 10);
break;
case '?':
default:
usage();
}
}
}
int main(int argc, char** argv)
{
handle_args(argc, argv);
// Initialize kinetic-c and configure sessions
KineticSession* session;
KineticClientConfig clientConfig = {
.logFile = "stdout",
.logLevel = 1,
};
KineticClient * client = KineticClient_Init(&clientConfig);
if (client == NULL) { return 1; }
const char HmacKeyString[] = "asdfasdf";
KineticSessionConfig sessionConfig = {
.host = "localhost",
.port = KINETIC_PORT,
.clusterVersion = 0,
.identity = 1,
.hmacKey = ByteArray_CreateWithCString(HmacKeyString),
};
KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session);
if (status != KINETIC_STATUS_SUCCESS) {
fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n",
Kinetic_GetStatusDescription(status));
exit(1);
}
if (idle_seconds > 0) {
printf(" -- Sleeping %ld seconds\n", idle_seconds);
sleep(idle_seconds);
}
// Shutdown client connection and cleanup
KineticClient_DestroySession(session);
KineticClient_Shutdown(client);
return 0;
}