kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
blocking_noop.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 <ctype.h>
31 
32 #include <openssl/sha.h>
33 
34 static void do_noop(KineticSession *session) {
35  /* Send a NoOp command. */
36  KineticStatus status = KineticClient_NoOp(session);
37  printf("NoOp status: %s\n", Kinetic_GetStatusDescription(status));
38 
39  /* No cleanup necessary */
40 }
41 
42 int main(int argc, char** argv)
43 {
44  (void)argc;
45  (void)argv;
46 
47  // Initialize kinetic-c and configure sessions
48  KineticSession* session;
49  KineticClientConfig clientConfig = {
50  .logFile = "stdout",
51  .logLevel = 1,
52  };
53  KineticClient * client = KineticClient_Init(&clientConfig);
54  if (client == NULL) { return 1; }
55  const char HmacKeyString[] = "asdfasdf";
56  KineticSessionConfig sessionConfig = {
57  .host = "localhost",
58  .port = KINETIC_PORT,
59  .clusterVersion = 0,
60  .identity = 1,
61  .hmacKey = ByteArray_CreateWithCString(HmacKeyString),
62  };
63  KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session);
64  if (status != KINETIC_STATUS_SUCCESS) {
65  fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n",
67  exit(1);
68  }
69 
70  do_noop(session);
71 
72  // Shutdown client connection and cleanup
74  KineticClient_Shutdown(client);
75  return 0;
76 }
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.
KineticStatus KineticClient_NoOp(KineticSession *const session)
Executes a NOOP operation to test whether the Kinetic Device is operational.
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
int main(int argc, char **argv)
Definition: blocking_noop.c:42
#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.
static void do_noop(KineticSession *session)
Definition: blocking_noop.c:34
KineticStatus
Kinetic status codes.
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.
ByteArray ByteArray_CreateWithCString(const char *str)
Definition: byte_array.c:38