[C-MPI-commits] SF.net SVN: c-mpi:[154]
Status: Pre-Alpha
Brought to you by:
jmwozniak
|
From: <jmw...@us...> - 2010-06-07 19:30:51
|
Revision: 154
http://c-mpi.svn.sourceforge.net/c-mpi/?rev=154&view=rev
Author: jmwozniak
Date: 2010-06-07 19:30:44 +0000 (Mon, 07 Jun 2010)
Log Message:
-----------
Improving accessor interface
Modified Paths:
--------------
Makefile.in
include/accessor.h
include/cmpi-cp.h
include/cmpi-types.h
src/cmpi/accessor.c
src/cmpi/driver.c
src/cmpi/module.mk.in
src/cmpi-cp/cmpi-cp.c
src/cmpi-db/cmpi-db-fifo-quit.c
src/dense-1/dense.c
test/driver/test-cmd-get.c
test/driver/test-cmd-put.c
test/driver/test-cmd-quit.c
test/driver/test-cmd-sleep.c
test/driver/test-cmd.c
Modified: Makefile.in
===================================================================
--- Makefile.in 2010-06-07 19:18:15 UTC (rev 153)
+++ Makefile.in 2010-06-07 19:30:44 UTC (rev 154)
@@ -337,6 +337,7 @@
#LIBOBJS := $(patsubst %.c,%.o, $(filter %.c,$(LIBSRC)))
#DISKSIM_OBJS := $(patsubst %.c,%.o, $(filter %.c,$(DISKSIM_SRC)))
+
CMPI_OBJS := $(TABLE_OBJS) $(MPIRPC_OBJS) $(CMPI_OBJS)
# $(DISKSIM_OBJS)
@@ -492,7 +493,7 @@
$(E)rm -fv $(CMPI_DEPS) $(TEST_DEPS) \
$(MPIRPC) $(CMPI) \
$(ADTS_OBJS) $(MPIRPC_OBJS) $(CMPI_OBJS) \
- $(KDA_OBJS) $(CMPI_IO) $(CMPI_OBJS) $(TABLE_OBJS) \
+ $(KDA_OBJS) $(CMPI_IO) \
hex unhex hexord unpublish node driver \
$(TEST_OUTPUT) $(TEST_PROGS) $(TEST_OBJS) \
$(PROGS) $(CMPICP_OBJS) $(CMPIDB_OBJS) splint.out
@@ -506,10 +507,6 @@
# $(E)find . -name "*.avg" -exec rm -fv \{\} \;
# $(E)find . -name "*.per" -exec rm -fv \{\} \;
-#ifndef DIST_RELEASE
-# $(E)rm -fv $(STATECOMPGEN)
-#endif
-
# Allow quick (cached) reconfiguration: regeneration of Makefile
# some stuff that is cleaned in both distclean and dist targets
cleaner: clean
Modified: include/accessor.h
===================================================================
--- include/accessor.h 2010-06-07 19:18:15 UTC (rev 153)
+++ include/accessor.h 2010-06-07 19:30:44 UTC (rev 154)
@@ -1,12 +1,21 @@
+#ifndef ACCESSOR_H
+#define ACCESSOR_H
+
#include <stdbool.h>
#include <stdio.h>
-FILE* to_cmpi;
-FILE* from_cmpi;
+#include <cmpi-types.h>
-void driver_access_fifo_setup(char* dir);
+extern FILE* to_cmpi;
+extern FILE* from_cmpi;
-bool driver_access_fifo(void);
+void accessor_fifo_setup(char* dir);
-void driver_access_fifo_close(void);
+bool accessor_fifo_init(void);
+
+void accessor_fifo_close(void);
+
+CMPI_RETURN accessor_put(char* key, void* data, int length);
+
+#endif
Modified: include/cmpi-cp.h
===================================================================
--- include/cmpi-cp.h 2010-06-07 19:18:15 UTC (rev 153)
+++ include/cmpi-cp.h 2010-06-07 19:30:44 UTC (rev 154)
@@ -6,18 +6,7 @@
* We do not compile with MPICC or any of our libs.
* */
-#include <accessor.h>
-#include <getopt.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <io_tools.h>
-
-// #define CMPI_CP_CHUNK CMPI_VALUE_LENGTH
-
-#define CMPI_CP_CHUNK 1024
-
typedef enum
{
CMPI_CP_KEY,
Modified: include/cmpi-types.h
===================================================================
--- include/cmpi-types.h 2010-06-07 19:18:15 UTC (rev 153)
+++ include/cmpi-types.h 2010-06-07 19:30:44 UTC (rev 154)
@@ -1,4 +1,7 @@
+#ifndef CMPI_TYPES_H
+#define CMPI_TYPES_H
+
#define CMPI_KEY_LENGTH 64
#define CMPI_VALUE_LENGTH (64*1024)
@@ -37,3 +40,5 @@
*/
CMPI_ERROR_NEIGHBORS = 5
} CMPI_RETURN;
+
+#endif
Modified: src/cmpi/accessor.c
===================================================================
--- src/cmpi/accessor.c 2010-06-07 19:18:15 UTC (rev 153)
+++ src/cmpi/accessor.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -5,12 +5,20 @@
#include <string.h>
#include <accessor.h>
+#include <io_tools.h>
char* fifo_in = NULL;
char* fifo_out = NULL;
+FILE* to_cmpi;
+FILE* from_cmpi;
+
+#define CHECK_ERROR \
+ if (error != CMPI_SUCCESS) \
+ return error;
+
void
-driver_access_fifo_setup(char* dir)
+accessor_fifo_setup(char* dir)
{
if (!dir)
dir = "/tmp";
@@ -35,7 +43,7 @@
@return True iff successfully access to fifos is made.
*/
bool
-driver_access_fifo()
+accessor_fifo_init()
{
assert(fifo_in);
@@ -77,8 +85,49 @@
*/
void
-driver_access_fifo_close()
+accessor_fifo_close()
{
fclose(to_cmpi);
fclose(from_cmpi);
}
+
+/**
+ @param buffer with length 32 or greater.
+*/
+CMPI_RETURN
+read_ok(char* buffer, FILE* file)
+{
+ buffer[0] = '\0';
+ fgets(buffer, 32, file);
+
+ if (strncmp(buffer, "ok", 2) != 0)
+ {
+ printf("did not get ok\n");
+ fflush(stdout);
+ printf("got: %s\n", buffer);
+ return CMPI_ERROR_UNKNOWN;
+ }
+
+ return CMPI_SUCCESS;
+}
+
+CMPI_RETURN
+accessor_put(char* key, void* data, int length)
+{
+ char buffer[32];
+ CMPI_RETURN error;
+
+ fprintf(to_cmpi, "put %s %i\n", key, length);
+ fflush(to_cmpi);
+
+ error = read_ok(buffer, from_cmpi);
+ CHECK_ERROR;
+
+ buffer_to_stream(data, length, to_cmpi);
+ fflush(to_cmpi);
+
+ read_ok(buffer, from_cmpi);
+ CHECK_ERROR;
+
+ return CMPI_SUCCESS;
+}
Modified: src/cmpi/driver.c
===================================================================
--- src/cmpi/driver.c 2010-06-07 19:18:15 UTC (rev 153)
+++ src/cmpi/driver.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -82,10 +82,6 @@
if (!fifo_in)
driver_setup_fifo_names();
- // This was a bad idea:
- // unlink(fifo_in);
- // unlink(fifo_out);
-
int error = mkfifo(fifo_in, S_IRUSR|S_IWUSR);
if (error != 0 &&
errno != EEXIST)
@@ -140,8 +136,11 @@
NOTE("got buffer");
cmpi_put(key, value, length);
- int error = fprintf(driver->sink, "ok got: put-data\n");
- assert(error >= 0);
+ NOTE("put complete\n");
+
+ int error = fprintf(driver->sink, "ok\n");
+ if (error == -1)
+ printf("driver_put result error!\n");
fflush(driver->sink);
}
@@ -281,6 +280,7 @@
char* s = strchr(driver->command, '\n');
*s = '\0';
driver_execute(driver);
+ NOTE("cmd complete");
}
NOTE("Closing driver...");
fclose(driver->source);
Modified: src/cmpi/module.mk.in
===================================================================
--- src/cmpi/module.mk.in 2010-06-07 19:18:15 UTC (rev 153)
+++ src/cmpi/module.mk.in 2010-06-07 19:30:44 UTC (rev 154)
@@ -42,7 +42,7 @@
CMPI_SRC += $(DIR)/cmpi_disk_void.c
endif
-CMPI_OBJS = $(patsubst %.c, %.o, $(CMPI_SRC))
+CMPI_OBJS += $(patsubst %.c, %.o, $(CMPI_SRC))
CMPI_OBJS += $(MPIRPC_OBJS)
CMPI = lib/libcmpi.a
Modified: src/cmpi-cp/cmpi-cp.c
===================================================================
--- src/cmpi-cp/cmpi-cp.c 2010-06-07 19:18:15 UTC (rev 153)
+++ src/cmpi-cp/cmpi-cp.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -1,12 +1,19 @@
#include <assert.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <cmpi-cp.h>
+#include <io_tools.h>
+#include <accessor.h>
+#define CMPI_CP_CHUNK 1024
+
#include <cmpi-types.h>
+#include <cmpi-cp.h>
+
#ifdef DMALLOC
#include <dmalloc.h>
void setup_dmalloc()
@@ -99,14 +106,8 @@
{
char key[CMPI_KEY_LENGTH+16];
char data[value_size];
- char msg[128];
int count = 0;
- int total = 0;
- char* result;
- int i;
-
- dbg("cmpi_cmp_put()...");
-
+ int total;
while (! feof(file))
{
total = 0;
@@ -121,72 +122,14 @@
if (total == 0)
break;
- dbg("read file");
-
- sprintf(key, "%s[%i]", object, count++);
- fprintf(to_cmpi, "put %s %i\n", key, total);
- fflush(to_cmpi);
- fflush(stdout);
- result = NULL;
- i = 0;
- while ((result = fgets(msg, 64, from_cmpi)) == NULL)
- {
- printf("cmpi-cp: put(): received: NULL\n");
- if (i++ == 3)
- return CMPI_ERROR_UNKNOWN;
- sleep(1);
- }
- if (strcmp(msg, "ok got: put-command\n"))
- {
- printf("cmpi-cp: put(): received: %s %i\n", msg, strlen(msg));
- return CMPI_ERROR_UNKNOWN;
- }
- buffer_to_stream(data, total, to_cmpi);
- fflush(to_cmpi);
-
- result = fgets(msg, 64, from_cmpi);
- if (!result)
- {
- printf("cmpi-cp: put(): received after data post: NULL\n");
- return CMPI_ERROR_UNKNOWN;
- }
- if (strcmp(msg, "ok got: put-data\n"))
- {
- printf("cmpi-cp: put(): received after data post: %s %i\n");
- return CMPI_ERROR_UNKNOWN;
- }
+ sprintf(key, "%s[%i]", object, count);
+ accessor_put(key, data, total);
+ count++;
}
- dbg("sent chunks");
+ total = sprintf(data, "DHT: %i", count)+1;
+ accessor_put(object, data, total);
- sprintf(data, "DHT: %i", count);
- total = (int) strlen(data)+1;
- fprintf(to_cmpi, "put %s %i\n", object, total);
- fflush(to_cmpi);
- result = NULL;
- i = 0;
- while ((result = fgets(msg, 64, from_cmpi)) == NULL)
- {
- printf("cmpi-cp: put(): received after metadata post: NULL\n");
- if (i++ == 3)
- return CMPI_ERROR_UNKNOWN;
- sleep(1);
- }
- if (strcmp(msg, "ok got: put-command\n"))
- {
- printf("got bad response after metadata put: %s\n", msg);
- return CMPI_ERROR_UNKNOWN;
- }
- buffer_to_stream(data, total, to_cmpi);
- fflush(to_cmpi);
-
- fgets(msg, 64, from_cmpi);
- if (strcmp(result, "ok got: put-data\n"))
- {
- printf("got bad response after metadata post: %s\n");
- return CMPI_ERROR_UNKNOWN;
- }
-
// printf("put() complete\n");
return CMPI_SUCCESS;
}
@@ -213,7 +156,6 @@
printf("cmpi-cp: get(): bad metadata length: NULL\n");
if (i++ == 3)
return CMPI_ERROR_UNKNOWN;
- sleep(1);
}
n = sscanf(msg, "%i", &length);
@@ -352,9 +294,8 @@
target2_type == CMPI_CP_FILE)
finish("cmpi-cp: given two files!", 1);
- driver_access_fifo_setup(NULL);
- dbg("setup");
- driver_access_fifo();
+ accessor_fifo_setup(NULL);
+ accessor_fifo_init();
fifos_open = true;
dbg("access");
@@ -370,7 +311,7 @@
else if (result != CMPI_SUCCESS)
finish("error!\n", 1);
- driver_access_fifo_close();
+ accessor_fifo_close();
dbg("cmpi-cp: normal exit\n");
finish(NULL, 0);
Modified: src/cmpi-db/cmpi-db-fifo-quit.c
===================================================================
--- src/cmpi-db/cmpi-db-fifo-quit.c 2010-06-07 19:18:15 UTC (rev 153)
+++ src/cmpi-db/cmpi-db-fifo-quit.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -11,8 +11,8 @@
{
char msg[100];
- driver_access_fifo_setup(NULL);
- bool success = driver_access_fifo();
+ accessor_fifo_setup(NULL);
+ bool success = accessor_fifo_init();
assert(success);
fprintf(to_cmpi, "quit\n");
Modified: src/dense-1/dense.c
===================================================================
--- src/dense-1/dense.c 2010-06-07 19:18:15 UTC (rev 153)
+++ src/dense-1/dense.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -282,6 +282,7 @@
DEBUG(lru_table_printdata(cmpi_cache));
MPIRPC_Null(caller, unique);
+ DONE;
}
void
Modified: test/driver/test-cmd-get.c
===================================================================
--- test/driver/test-cmd-get.c 2010-06-07 19:18:15 UTC (rev 153)
+++ test/driver/test-cmd-get.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -14,7 +14,7 @@
crash(char* message)
{
printf("%s\n", message);
- driver_access_fifo_close();
+ accessor_fifo_close();
exit(1);
}
@@ -27,7 +27,7 @@
char* key = argv[optind];
- code = driver_access_fifo();
+ code = accessor_fifo_init();
assert(code);
fprintf(to_cmpi, "get %s\n", key);
Modified: test/driver/test-cmd-put.c
===================================================================
--- test/driver/test-cmd-put.c 2010-06-07 19:18:15 UTC (rev 153)
+++ test/driver/test-cmd-put.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -14,28 +14,16 @@
{
test_cmd_setup(argc, argv);
- driver_access_fifo();
+ accessor_fifo_init();
char* key = argv[optind];
- // printf("key: %s\n", key);
char* data = "hello";
char output[32];
int tmp;
- fprintf(to_cmpi, "put %s %i\n", key, (int) strlen(data)+1);
- fflush(to_cmpi);
- fgets(output, 128, from_cmpi);
- assert(!strncmp(output, "ok", 2));
- // printf("got ok\n");
+ accessor_put(key, data, strlen(data)+1);
- int i = fwrite(data, sizeof(char), strlen(data)+1, to_cmpi);
- // printf("wrote: %i\n", i);
- fflush(to_cmpi);
-
- fgets(output, 128, from_cmpi);
- assert(!strncmp(output, "ok", 2));
-
return 0;
}
Modified: test/driver/test-cmd-quit.c
===================================================================
--- test/driver/test-cmd-quit.c 2010-06-07 19:18:15 UTC (rev 153)
+++ test/driver/test-cmd-quit.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -14,7 +14,7 @@
test_cmd_setup(argc, argv);
- error = driver_access_fifo();
+ error = accessor_fifo_init();
assert(error);
fprintf(to_cmpi, "quit\n");
Modified: test/driver/test-cmd-sleep.c
===================================================================
--- test/driver/test-cmd-sleep.c 2010-06-07 19:18:15 UTC (rev 153)
+++ test/driver/test-cmd-sleep.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -15,7 +15,7 @@
test_cmd_setup(argc, argv);
- code = driver_access_fifo();
+ code = accessor_fifo_init();
assert(code);
fprintf(to_cmpi, "sleep %i\n", sleep_time);
Modified: test/driver/test-cmd.c
===================================================================
--- test/driver/test-cmd.c 2010-06-07 19:18:15 UTC (rev 153)
+++ test/driver/test-cmd.c 2010-06-07 19:30:44 UTC (rev 154)
@@ -53,5 +53,5 @@
// printf("cmd -d %s\n", dir);
- driver_access_fifo_setup(dir);
+ accessor_fifo_setup(dir);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|