kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
setup_teardown.c
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20 
21 #include "kinetic_client.h"
22 #include "kinetic_types.h"
23 #include "byte_array.h"
24 #include <stdlib.h>
25 #include <getopt.h>
26 #include <stdio.h>
27 #include <sys/param.h>
28 #include <sys/stat.h>
29 #include <sys/file.h>
30 #include <getopt.h>
31 
32 static char *kinetic_host = "localhost";
33 static long idle_seconds = 0;
34 
35 static void usage(void) {
36  fprintf(stderr, "usage: setup_teardown [-h KINETIC_HOST] [-i IDLE_SECONDS]\n");
37  exit(1);
38 }
39 
40 static void handle_args(int argc, char **argv) {
41  int fl = 0;
42  while ((fl = getopt(argc, argv, "i:h:")) != -1) {
43  switch (fl) {
44  case 'h': /* host */
45  kinetic_host = optarg;
46  break;
47  case 'i': /* idle seconds */
48  idle_seconds = strtol(optarg, NULL, 10);
49  break;
50  case '?':
51  default:
52  usage();
53  }
54  }
55 }
56 
57 int main(int argc, char** argv)
58 {
59  handle_args(argc, argv);
60 
61  // Initialize kinetic-c and configure sessions
62  KineticSession* session;
63  KineticClientConfig clientConfig = {
64  .logFile = "stdout",
65  .logLevel = 1,
66  };
67  KineticClient * client = KineticClient_Init(&clientConfig);
68  if (client == NULL) { return 1; }
69  const char HmacKeyString[] = "asdfasdf";
70  KineticSessionConfig sessionConfig = {
71  .host = "localhost",
72  .port = KINETIC_PORT,
73  .clusterVersion = 0,
74  .identity = 1,
75  .hmacKey = ByteArray_CreateWithCString(HmacKeyString),
76  };
77  KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session);
78  if (status != KINETIC_STATUS_SUCCESS) {
79  fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n",
81  exit(1);
82  }
83 
84  if (idle_seconds > 0) {
85  printf(" -- Sleeping %ld seconds\n", idle_seconds);
86  sleep(idle_seconds);
87  }
88 
89  // Shutdown client connection and cleanup
91  KineticClient_Shutdown(client);
92  return 0;
93 }
Operation successful.
KineticStatus KineticClient_CreateSession(KineticSessionConfig *const config, KineticClient *const client, KineticSession **session)
Creates a session with the Kinetic Device per specified configuration.
Structure used to specify the configuration for a session.
static void usage(void)
KineticStatus KineticClient_DestroySession(KineticSession *const session)
Closes the connection to a host.
char host[256]
Host name/IP address of Kinetic Device.
const char * Kinetic_GetStatusDescription(KineticStatus status)
Provides a string representation for a KineticStatus code.
Definition: kinetic_types.c:67
static char * kinetic_host
#define KINETIC_PORT
Default kinetic port.
Definition: kinetic_types.h:40
const char * logFile
Path to log file. Specify 'stdout' to log to STDOUT or NULL to disable logging.
int main(int argc, char **argv)
KineticStatus
Kinetic status codes.
static void handle_args(int argc, char **argv)
Configuration values for the KineticClient connection.
void KineticClient_Shutdown(KineticClient *const client)
Performs shutdown/cleanup of the kinetic-c client library.
KineticClient * KineticClient_Init(KineticClientConfig *config)
Initializes the Kinetic API and configures logging.
static long idle_seconds
ByteArray ByteArray_CreateWithCString(const char *str)
Definition: byte_array.c:38