changeset 19:2d91b4d2569c

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 05 May 2021 18:43:47 +0900
parents f3112bbff428
children 5b8d3386f939
files Paper/codes/wc/FileChrs.h Paper/codes/wc/FileImpl.h Paper/codes/wc/TopologyManager.h Paper/codes/wc/UnixChrisFileImpl.cpp Paper/codes/wc/UnixFileImpl.h Paper/codes/wc/WcChrsImpl.cbc Paper/codes/wc/WcResult.h Paper/codes/wc/main.cbc Paper/codes/wc/wcTarget.h Paper/images/wordCountDGM.graffle
diffstat 10 files changed, 143 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paper/codes/wc/FileChrs.h	Wed May 05 18:43:47 2021 +0900
@@ -0,0 +1,11 @@
+typedef struct FileChrs <Record> {
+  int mode; /* rw .. */
+  Key *key;
+  Ack *ack;
+  Record *record;
+  Output *reader;
+  Data *fileImpl ;
+  __code setOutput(Output *output,__code next(...)) ;
+  __code Open(Key *key, Output reader, __code next(...)) ;
+  __code Ack(Ack *ack, Output reader, __code next(...)) ;
+} FileChrs;
--- a/Paper/codes/wc/FileImpl.h	Wed May 05 15:38:07 2021 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-typedef struct UnixFileImpl <> ipml File {
-  int fd;    // unix file descriptor
-  int mode; 
-  Data *fileImpl ;
-  __code unixOpen(UnixFileImpl* file,Key *key, __code next(Block *block,...));
-  __code uniAck(UnixFileImpl* file,Ack *ack, __code next(Block *block,...));
-} File;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paper/codes/wc/TopologyManager.h	Wed May 05 18:43:47 2021 +0900
@@ -0,0 +1,13 @@
+// Topologymanger connect file impl and wc impl
+//    setput remote data Gear Manager
+
+run() {
+    foreach imple in (codeGearList) {
+       intf = create imple
+       imple->intf = im
+    }
+    foreach imple in (codeGearList) {
+       imple->intf->setOutput();
+    }
+    goto imple->intf->start();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paper/codes/wc/UnixChrisFileImpl.cpp	Wed May 05 18:43:47 2021 +0900
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#impl "Wc.h" as "WcChrsImpl.h"
+
+typedef struct UnixFileImpl <> ipml File {
+  int fd;    // unix file descriptor
+  int mode; 
+  Data *fileImpl ;
+  __code setOutput(UnixFileImpl* file, Output *output,__code next(...)) ;
+  __code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) ;
+  __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) ;
+} File;
+
+File* createUnixChrisFileImpl(struct Context* context) {
+    File *file = new File();
+    file->ChrisFileImpl = (union Data*)new ChrisFileImpl();
+    return file;
+}
+
+// Topology manageres determins input / output connection
+// 
+__code setOutput(Wc* wc, Output *output,__code next(...)) {
+   file->reader = output ;
+   goto next(...);
+}
+
+int
+putBlock(UnixFileImpl* file, Output *reader) {
+   Block *block = new Block();
+   int len = read(fd, BUFSIZE, block->data);
+   if (len <=0 ) {
+       block->eof |= BLOCK_FLAG_EOF;
+       return 0;
+   }
+   reader->put(block);
+   return 1 ;
+}
+
+__code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) {
+   file->fd = open(key->path,unix_mode(key->modde));
+   if (fd < 0) {
+       goto error("can't open");
+   }
+   if (putBlock(file,reader)) {
+      putBlock(file,reader);
+   }
+   goto next(file,...);
+}
+
+__code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) {
+   if (!ack->isOk) {
+      close(fd);
+      goto next(...);
+   }
+   putBlock(file,reader);
+   goto next(...);   // file is automaticaly put into local dataGearManger/input
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paper/codes/wc/UnixFileImpl.h	Wed May 05 18:43:47 2021 +0900
@@ -0,0 +1,7 @@
+typedef struct UnixFileImpl <> ipml File {
+  int fd;    // unix file descriptor
+  int mode; 
+  Data *fileImpl ;
+  __code unixOpen(UnixFileImpl* file,Key *key, __code next(Block *block,...));
+  __code uniAck(UnixFileImpl* file,Ack *ack, __code next(Block *block,...));
+} File;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paper/codes/wc/WcChrsImpl.cbc	Wed May 05 18:43:47 2021 +0900
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#impl "Wc.h" as "WcChrsImpl.h"
+
+Wc* createChrsWcImpl(struct Context* context) {
+    Wc *wc = new Wc();
+    wc->wc = (union Data*)new WcImpl();
+    wc->bytes = 0;
+    wc->words = 0;
+    wc->lines = 0;
+    return wc;
+}
+
+// Topology manageres determins input / output connection
+// 
+__code setOutput(Wc* wc, Output *output,__code next(...)) {
+   wc->output = output ;
+   goto next(...);
+}
+
+__code take(Impl* wc, Output *output,
+       Block *block,                                 // Input
+      __code next(...)) {           
+    if (isEof(block->eof )) {
+        result.buffer = new Buffer(1);
+        result.buffer->data = new Byte(BUSIZE);
+        result.size = 1;
+        result.buffer->size = 
+            snprintf(result.buffer[0]->data, "%d %d %d\n",wc->bytes,wc->words,wc->lines);
+        output->put(result);                        // goto finish(resut);  
+        goto next(...);
+    }
+    for(size_t i = 0 ; i<block->size; i++) {
+        if (block->data[i] == '\n') wc->lines++;
+        if (block->data[i] == ' ') {
+            wc->words++;
+            while(block->data[i] == ' ') {
+               if(i>=block->size) 
+                    goto next(ack,take);
+               i++;
+               wc->bytes++;
+            }
+        }
+        wc->bytes++;
+    }
+    // output1->put(ack);                               //  goto next(ack,take); 
+    output->put(ack);                               //  goto next(ack,take); 
+    goto next(...);
+}
+
--- a/Paper/codes/wc/WcResult.h	Wed May 05 15:38:07 2021 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-typedef struct WcResult <> {
-  int wordNum;
-  char* str;
-} WcResult;
--- a/Paper/codes/wc/main.cbc	Wed May 05 15:38:07 2021 +0900
+++ b/Paper/codes/wc/main.cbc	Wed May 05 18:43:47 2021 +0900
@@ -1,10 +1,15 @@
 #data "wcTarget.h"
 #interface "Wc.h"
 
+//
+// start file  and wc 
+//   connect continuation each other
+//
 
 __code startCode(struct GearsData* gearsData) {   
-  Wc* wc = createWcImpl(context, /* file name */ gearsData->args[1] );
-  goto wc->openFile(code2); 
+  File* file = createUnixFileImpl(context, /* file name */ gearsData->args[1] );
+  Wc* wc = createWcImpl(context);
+  goto file->openFile(asReader(wc)); // readerInterface
 }
 
 
--- a/Paper/codes/wc/wcTarget.h	Wed May 05 15:38:07 2021 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-typedef struct wcTarget <> {
-  char* filename;
-  char* keyword;
-} wcTarget;
-
Binary file Paper/images/wordCountDGM.graffle has changed