Added commands for sending shutdown and startup admin requests via the admin ES.
authorian <ian>
Thu, 16 Mar 2000 13:55:49 +0000 (13:55 +0000)
committerian <ian>
Thu, 16 Mar 2000 13:55:49 +0000 (13:55 +0000)
client/admin.c
client/admin.h
client/client.c

index 93574a8..9022950 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * $Log: admin.c,v $
 /*
  * $Log: admin.c,v $
- * Revision 1.3  2000-03-14 15:23:17  ian
+ * Revision 1.4  2000-03-16 13:55:49  ian
+ * Added commands for sending shutdown and startup admin requests via the admin ES.
+ *
+ * Revision 1.3  2000/03/14 15:23:17  ian
  * Removed unwanted ifdef and include of zes-admin.h
  *
  * Revision 1.2  2000/03/14 14:06:04  ian
  * Removed unwanted ifdef and include of zes-admin.h
  *
  * Revision 1.2  2000/03/14 14:06:04  ian
@@ -36,7 +39,7 @@ void send_apdu(Z_APDU *a);
 
 
 
 
 
 
-int sendAdminES(int type, char* dbname)
+int sendAdminES(int type, char* dbname, char* param1)
 {
     ODR out = getODROutputStream();
 
 {
     ODR out = getODROutputStream();
 
@@ -73,40 +76,58 @@ int sendAdminES(int type, char* dbname)
     toKeep = r->u.adminService->u.esRequest->toKeep = (Z_ESAdminOriginPartToKeep *) 
                      odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->toKeep));
 
     toKeep = r->u.adminService->u.esRequest->toKeep = (Z_ESAdminOriginPartToKeep *) 
                      odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->toKeep));
 
+    toKeep->which=type;
+
     switch ( type )
     {
     switch ( type )
     {
-        case 1:
-            toKeep->which=Z_ESAdminOriginPartToKeep_reIndex;
+        case Z_ESAdminOriginPartToKeep_reIndex:
            toKeep->u.reIndex=odr_nullval();
            toKeep->u.reIndex=odr_nullval();
+            toKeep->databaseName = dbname;
            break;
            break;
-       case 2:
-            toKeep->which=Z_ESAdminOriginPartToKeep_truncate;
+
+       case Z_ESAdminOriginPartToKeep_truncate:
            toKeep->u.truncate=odr_nullval();
            toKeep->u.truncate=odr_nullval();
+            toKeep->databaseName = dbname;
            break;
            break;
-       case 3:
-            toKeep->which=Z_ESAdminOriginPartToKeep_delete;
+
+       case Z_ESAdminOriginPartToKeep_delete:
            toKeep->u.delete=odr_nullval();
            toKeep->u.delete=odr_nullval();
+            toKeep->databaseName = dbname;
            break;
            break;
-       case 4:
-            toKeep->which=Z_ESAdminOriginPartToKeep_create;
+
+       case Z_ESAdminOriginPartToKeep_create:
            toKeep->u.create=odr_nullval();
            toKeep->u.create=odr_nullval();
+            toKeep->databaseName = dbname;
            break;
            break;
-        case 5:
-            toKeep->which=Z_ESAdminOriginPartToKeep_import;
-           toKeep->u.import=odr_nullval();
+
+        case Z_ESAdminOriginPartToKeep_import:
+           toKeep->u.import = (Z_ImportParameters*)odr_malloc(out, sizeof(*toKeep->u.import));
+           toKeep->u.import->recordType=param1;
+            toKeep->databaseName = dbname;
+           /* Need to add additional setup of records here */
            break;
            break;
-        case 6:
-            toKeep->which=Z_ESAdminOriginPartToKeep_refresh;
+
+        case Z_ESAdminOriginPartToKeep_refresh:
            toKeep->u.refresh=odr_nullval();
            toKeep->u.refresh=odr_nullval();
+            toKeep->databaseName = dbname;
            break;
            break;
-        case 7:
-            toKeep->which=Z_ESAdminOriginPartToKeep_commit;
+
+        case Z_ESAdminOriginPartToKeep_commit:
            toKeep->u.commit=odr_nullval();
            break;
            toKeep->u.commit=odr_nullval();
            break;
-    }
 
 
-    toKeep->databaseName = dbname;
+       case Z_ESAdminOriginPartToKeep_shutdown:
+           toKeep->u.commit=odr_nullval();
+           break;
+           
+       case Z_ESAdminOriginPartToKeep_start:
+           toKeep->u.commit=odr_nullval();
+           break;
 
 
+        default:
+           /* Unknown admin service */
+           break;
+    }
 
     notToKeep = r->u.adminService->u.esRequest->notToKeep = (Z_ESAdminOriginPartNotToKeep *)
        odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->notToKeep));
 
     notToKeep = r->u.adminService->u.esRequest->notToKeep = (Z_ESAdminOriginPartNotToKeep *)
        odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->notToKeep));
@@ -115,14 +136,14 @@ int sendAdminES(int type, char* dbname)
     
     send_apdu(apdu);
 
     
     send_apdu(apdu);
 
-    return 2;
+    return 0;
 }
 
 /* cmd_adm_reindex <dbname>
    Ask the specified database to fully reindex itself */
 int cmd_adm_reindex(char* arg)
 {
 }
 
 /* cmd_adm_reindex <dbname>
    Ask the specified database to fully reindex itself */
 int cmd_adm_reindex(char* arg)
 {
-    sendAdminES(1,arg);
+    sendAdminES(Z_ESAdminOriginPartToKeep_reIndex,arg,NULL);
 }
 
 /* cmd_adm_truncate <dbname>
 }
 
 /* cmd_adm_truncate <dbname>
@@ -130,21 +151,24 @@ int cmd_adm_reindex(char* arg)
    the database & it's explain information intact ready for new records */
 int cmd_adm_truncate(char* arg)
 {
    the database & it's explain information intact ready for new records */
 int cmd_adm_truncate(char* arg)
 {
-    sendAdminES(2,arg);
+    if ( arg )
+        sendAdminES(Z_ESAdminOriginPartToKeep_truncate,arg,NULL);
 }
 
 /* cmd_adm_create <dbname>
    Create a new database */
 int cmd_adm_create(char* arg)
 {
 }
 
 /* cmd_adm_create <dbname>
    Create a new database */
 int cmd_adm_create(char* arg)
 {
-    sendAdminES(4,arg);
+    if ( arg )
+        sendAdminES(Z_ESAdminOriginPartToKeep_create,arg,NULL);
 }
 
 /* cmd_adm_delete <dbname>
    Delete a database */
 int cmd_adm_delete(char* arg)
 {
 }
 
 /* cmd_adm_delete <dbname>
    Delete a database */
 int cmd_adm_delete(char* arg)
 {
-    sendAdminES(3,arg);
+    if ( arg )
+        sendAdminES(Z_ESAdminOriginPartToKeep_delete,arg,NULL);
 }
 
 /* cmd_adm_import <dbname> <rectype> <sourcefile>
 }
 
 /* cmd_adm_import <dbname> <rectype> <sourcefile>
@@ -153,20 +177,88 @@ int cmd_adm_delete(char* arg)
    to existing records */
 int cmd_adm_import(char* arg)
 {
    to existing records */
 int cmd_adm_import(char* arg)
 {
-    sendAdminES(5,arg);
+    /* Size of chunks we wish to read from import file */
+    size_t chunk_size = 8192;
+
+    /* Buffer for reading chunks of data from import file */
+    char chunk_buffer[chunk_size];
+
+    if ( arg )
+    {
+        char dbname_buff[32];
+        char rectype_buff[32];
+        char filename_buff[32];
+       FILE* pImportFile = NULL;
+
+        if (sscanf (arg, "%s %s %s", dbname_buff, rectype_buff, filename_buff) != 3)
+       {
+           printf("Must specify database-name, record-type and filename for import\n");
+           return 0;
+       }
+
+        /* Attempt to open the file */
+
+       pImportFile = fopen(filename_buff,"r");
+
+        /* This chunk of code should move into client.c sometime soon for sending files via the update es */
+       /* This function will then refer to the standard client.c one for uploading a file using es update */
+       if ( pImportFile )
+       {
+           int iTotalWritten = 0;
+
+            /* We opened the import file without problems... So no we send the es request, ready to 
+              start sending fragments of the import file as segment messages */
+            sendAdminES(Z_ESAdminOriginPartToKeep_import,arg,rectype_buff);
+
+           while ( ! feof(pImportFile ) )
+           {
+               /* Read buffer_size bytes from the file */
+               size_t num_items = fread((void*)chunk_buffer, 1, sizeof(chunk_buffer),  pImportFile);
+
+               /* Write num_bytes of data to */
+
+               if ( feof(pImportFile ) )
+               {
+                   /* This is the last chunk... Write it as the last fragment */
+                   printf("Last segment of %d bytes\n", num_items);
+               }
+               else if ( iTotalWritten == 0 )
+               {
+                   printf("First segment of %d bytes\n",num_items);
+               }
+               else
+               {
+                   printf("Writing %d bytes\n", num_items);
+               }
+
+               iTotalWritten += num_items;
+           }
+       }
+    }
 }
 
 /* "Freshen" the specified database, by checking metadata records against the sources from which they were 
    generated, and creating a new record if the source has been touched since the last extraction */
 int cmd_adm_refresh(char* arg)
 {
 }
 
 /* "Freshen" the specified database, by checking metadata records against the sources from which they were 
    generated, and creating a new record if the source has been touched since the last extraction */
 int cmd_adm_refresh(char* arg)
 {
-    sendAdminES(6,arg);
+    if ( arg )
+        sendAdminES(Z_ESAdminOriginPartToKeep_refresh,arg,NULL);
 }
 
 /* cmd_adm_commit 
    Make imported records a permenant & visible to the live system */
 int cmd_adm_commit(char* arg)
 {
 }
 
 /* cmd_adm_commit 
    Make imported records a permenant & visible to the live system */
 int cmd_adm_commit(char* arg)
 {
-    sendAdminES(7,NULL);
+    sendAdminES(Z_ESAdminOriginPartToKeep_commit,NULL,NULL);
+}
+
+int cmd_adm_shutdown(char* arg)
+{
+    sendAdminES(Z_ESAdminOriginPartToKeep_shutdown,NULL,NULL);
+}
+
+int cmd_adm_startup(char* arg)
+{
+    sendAdminES(Z_ESAdminOriginPartToKeep_start,NULL,NULL);
 }
 
 }
 
index ac8faa2..06b3441 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * $Log: admin.h,v $
 /*
  * $Log: admin.h,v $
- * Revision 1.1  2000-03-14 09:27:07  ian
+ * Revision 1.2  2000-03-16 13:55:49  ian
+ * Added commands for sending shutdown and startup admin requests via the admin ES.
+ *
+ * Revision 1.1  2000/03/14 09:27:07  ian
  * Added code to enable sending of admin extended service requests
  *
  *
  * Added code to enable sending of admin extended service requests
  *
  *
@@ -13,3 +16,5 @@ int cmd_adm_delete(char* arg);
 int cmd_adm_import(char* arg);
 int cmd_adm_refresh(char* arg);
 int cmd_adm_commit(char* arg);
 int cmd_adm_import(char* arg);
 int cmd_adm_refresh(char* arg);
 int cmd_adm_commit(char* arg);
+int cmd_adm_shutdown(char* arg);
+int cmd_adm_startup(char* arg);
index 0e37a1f..f9350b8 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
- * Revision 1.97  2000-03-14 14:06:04  ian
+ * Revision 1.98  2000-03-16 13:55:49  ian
+ * Added commands for sending shutdown and startup admin requests via the admin ES.
+ *
+ * Revision 1.97  2000/03/14 14:06:04  ian
  * Minor change to order of debugging output for send_apdu,
  * fixed encoding of admin request.
  *
  * Minor change to order of debugging output for send_apdu,
  * fixed encoding of admin request.
  *
@@ -2273,6 +2276,8 @@ static int client(int wait)
        {"adm-import", cmd_adm_import, "<database-name> <record-type> <source-file-name>"},
        {"adm-refresh", cmd_adm_refresh, "<database-name>"},
        {"adm-commit", cmd_adm_commit, ""},
        {"adm-import", cmd_adm_import, "<database-name> <record-type> <source-file-name>"},
        {"adm-refresh", cmd_adm_refresh, "<database-name>"},
        {"adm-commit", cmd_adm_commit, ""},
+       {"adm-shutdown", cmd_adm_shutdown, ""},
+       {"adm-startup", cmd_adm_startup, ""},
         {0,0}
     };
     char *netbuffer= 0;
         {0,0}
     };
     char *netbuffer= 0;