Author: sandervanderburg
Date: Thu Oct 14 12:13:19 2010
New Revision: 24284
URL: https://svn.nixos.org/websvn/nix/?rev=24284&sc=1

Log:
Separated some operation code from the command-line interface code and doing 
some style/consistency fixes

Added:
   disnix/disnix/trunk/src/collect-garbage/collect-garbage.c
   disnix/disnix/trunk/src/collect-garbage/collect-garbage.h
   disnix/disnix/trunk/src/distribute/distribute.c
   disnix/disnix/trunk/src/distribute/distribute.h
   disnix/disnix/trunk/src/query/query-installed.c
   disnix/disnix/trunk/src/query/query-installed.h
   disnix/disnix/trunk/src/visualize/graph.c
   disnix/disnix/trunk/src/visualize/graph.h
Modified:
   disnix/disnix/trunk/src/collect-garbage/Makefile.am
   disnix/disnix/trunk/src/collect-garbage/main.c
   disnix/disnix/trunk/src/distribute/Makefile.am
   disnix/disnix/trunk/src/distribute/main.c
   disnix/disnix/trunk/src/query/Makefile.am
   disnix/disnix/trunk/src/query/main.c
   disnix/disnix/trunk/src/visualize/Makefile.am
   disnix/disnix/trunk/src/visualize/main.c

Modified: disnix/disnix/trunk/src/collect-garbage/Makefile.am
==============================================================================
--- disnix/disnix/trunk/src/collect-garbage/Makefile.am Thu Oct 14 12:12:27 
2010        (r24283)
+++ disnix/disnix/trunk/src/collect-garbage/Makefile.am Thu Oct 14 12:13:19 
2010        (r24284)
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -ggdb
 
 bin_PROGRAMS = disnix-collect-garbage
+noinst_HEADERS = collect-garbage.h
 
-disnix_collect_garbage_SOURCES = main.c
+disnix_collect_garbage_SOURCES = collect-garbage.c main.c
 disnix_collect_garbage_LDADD = ../libinfrastructure/libinfrastructure.la 
../libmain/libmain.la ../libinterface/libinterface.la
 disnix_collect_garbage_CFLAGS = $(LIBXML2_CFLAGS) $(LIBXSLT_CFLAGS) 
-I../libinfrastructure -I../libmain -I../libinterface

Added: disnix/disnix/trunk/src/collect-garbage/collect-garbage.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ disnix/disnix/trunk/src/collect-garbage/collect-garbage.c   Thu Oct 14 
12:13:19 2010        (r24284)
@@ -0,0 +1,75 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010  Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+
+#include "collect-garbage.h"
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <infrastructure.h>
+#include <client-interface.h> 
+
+int collect_garbage(gchar *interface, gchar *target_property, gchar 
*infrastructure_expr, gboolean delete_old)
+{
+    int exit_status = 0;
+    
+    /* Retrieve an array of all target machines from the infrastructure 
expression */
+    GArray *target_array = create_target_array(infrastructure_expr, 
target_property);
+       
+    if(target_array != NULL)
+    {
+        unsigned int i, running_processes = 0;     
+        int status;
+       
+        /* Spawn garbage collection processes */
+        for(i = 0; i < target_array->len; i++)
+        {    
+           gchar *target = g_array_index(target_array, gchar*, i);
+                               
+           g_printerr("Collecting garbage on: %s\n", target);
+           status = exec_collect_garbage(interface, target, delete_old);       
        
+       
+           /* If an operation failed, change the exit status */
+           if(status == -1)
+           {
+               g_printerr("Error executing garbage collection operation!\n");
+               exit_status = status;
+           }
+           else
+               running_processes++;
+       }
+                   
+       /* Check statusses of the running processes */      
+       for(i = 0; i < running_processes; i++)
+       {
+           /* Wait until a garbage collector processes is finished */
+           wait(&status);
+           
+           /* If one of the processes fail, change the exit status */
+           if(WEXITSTATUS(status) != 0)
+               exit_status = WEXITSTATUS(status);
+       }
+               
+       /* Delete the target array from memory */
+       delete_target_array(target_array);
+    }
+       
+    /* Return the exit status, which is 0 if everything succeeds */
+    return exit_status;
+}

Added: disnix/disnix/trunk/src/collect-garbage/collect-garbage.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ disnix/disnix/trunk/src/collect-garbage/collect-garbage.h   Thu Oct 14 
12:13:19 2010        (r24284)
@@ -0,0 +1,36 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010  Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+#ifndef __COLLECT_GARBAGE_H
+#define __COLLECT_GARBAGE_H
+#include <glib.h>
+
+/**
+ * Iterates over targets defined in an infrastructure Nix expression and
+ * performs the garbage collection operation on each target.
+ *
+ * @param interface Path to the client interface executable
+ * @param target_property Property in the infrastructure model which specifies
+ *                        how to connect to the Disnix service
+ * @param infrastructure_expr Path to the infrastructure expression
+ * @param delete_old Indicates whether to delete old profile generations
+ * @return 0 if everything succeeds, else a non-zero exit value
+ */
+int collect_garbage(gchar *interface, gchar *target_property, gchar 
*infrastructure_expr, gboolean delete_old);
+
+#endif

Modified: disnix/disnix/trunk/src/collect-garbage/main.c
==============================================================================
--- disnix/disnix/trunk/src/collect-garbage/main.c      Thu Oct 14 12:12:27 
2010        (r24283)
+++ disnix/disnix/trunk/src/collect-garbage/main.c      Thu Oct 14 12:13:19 
2010        (r24284)
@@ -18,15 +18,10 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <getopt.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <glib.h>
-#include <infrastructure.h>
+#define _GNU_SOURCE
 #include <defaultoptions.h>
-#include <client-interface.h>
+#include "collect-garbage.h"
 
 static void print_usage()
 {
@@ -82,46 +77,5 @@
        return 1;
     }
     else
-    {
-       GArray *target_array = create_target_array(argv[optind], 
target_property);
-       int exit_status = 0;
-       
-       if(target_array != NULL)
-       {
-           unsigned int i, running_processes = 0;          
-           int status;
-           
-           /* Spawn garbage collection processes */
-           for(i = 0; i < target_array->len; i++)
-           {
-               gchar *target = g_array_index(target_array, gchar*, i);
-                               
-               printf("Collecting garbage on: %s\n", target);
-               status = exec_collect_garbage(interface, target, delete_old);   
        
-               
-               if(status == -1)
-               {
-                   fprintf(stderr, "Error forking garbage collection 
process!\n");
-                   exit_status = -1;
-               }
-               else
-                   running_processes++;
-           }
-                   
-           /* Check statusses of the running processes */          
-           for(i = 0; i < running_processes; i++)
-           {
-               /* Wait until a garbage collector processes is finished */
-               wait(&status);
-           
-               /* If one of the processes fail, change the exit status */
-               if(WEXITSTATUS(status) != 0)
-                   exit_status = WEXITSTATUS(status);
-           }
-               
-           delete_target_array(target_array);
-       }
-       
-       return exit_status;
-    }
+       return collect_garbage(interface, target_property, argv[optind], 
delete_old); /* Execute garbage collection operation */
 }

Modified: disnix/disnix/trunk/src/distribute/Makefile.am
==============================================================================
--- disnix/disnix/trunk/src/distribute/Makefile.am      Thu Oct 14 12:12:27 
2010        (r24283)
+++ disnix/disnix/trunk/src/distribute/Makefile.am      Thu Oct 14 12:13:19 
2010        (r24284)
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -ggdb
 
 bin_PROGRAMS = disnix-distribute
+noinst_HEADERS = distribute.h
 
-disnix_distribute_SOURCES = main.c
+disnix_distribute_SOURCES = distribute.c main.c
 disnix_distribute_LDADD = ../libmanifest/libmanifest.la ../libmain/libmain.la 
../libinterface/libinterface.la
 disnix_distribute_CFLAGS = -I../libmanifest -I../libmain -I../libinterface

Added: disnix/disnix/trunk/src/distribute/distribute.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ disnix/disnix/trunk/src/distribute/distribute.c     Thu Oct 14 12:13:19 
2010        (r24284)
@@ -0,0 +1,60 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010  Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+
+#include "distribute.h"
+#include <distributionmapping.h>
+#include <client-interface.h>
+
+int distribute(gchar *interface, gchar *manifest_file)
+{
+    int exit_status = 0;
+    
+    /* Generate a distribution array from the manifest file */
+    GArray *distribution_array = generate_distribution_array(manifest_file);
+       
+    if(distribution_array != NULL)
+    {
+       unsigned int i;
+       
+        /* Iterate over the distribution array and distribute the profiles to 
the target machines */
+        for(i = 0; i < distribution_array->len; i++)
+        {
+           DistributionItem *item = g_array_index(distribution_array, 
DistributionItem*, i);
+           int status;
+           
+           /* Invoke copy closure operation */
+           g_printerr("Distributing intra-dependency closure of profile: %s to 
target: %s\n", item->profile, item->target);            
+           status = wait_to_finish(exec_copy_closure_to(interface, 
item->target, item->profile));
+               
+           /* On error stop the distribute process */
+           if(status != 0)
+           {
+               g_printerr("Distribution operation failed!\n");
+               exit_status = status;
+               break;
+           }
+       }
+       
+       /* Delete distribution array from memory */
+       delete_distribution_array(distribution_array);
+    }
+       
+    /* Return the exit status, which is 0 if everything succeeds */
+    return exit_status;
+}

Added: disnix/disnix/trunk/src/distribute/distribute.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ disnix/disnix/trunk/src/distribute/distribute.h     Thu Oct 14 12:13:19 
2010        (r24284)
@@ -0,0 +1,34 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010  Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+
+#ifndef __DISTRIBUTE_H
+#define __DISTRIBUTE_H
+#include <glib.h>
+
+/**
+ * Distributes all services defined in the manifest file to target machines
+ * in the network.
+ *
+ * @param interface Path to the client interface executable
+ * @param manifest_file Path to the manifest file which maps services to 
machines
+ * @return 0 if everything succeeds, else a non-zero exit status
+ */
+int distribute(gchar *interface, gchar *manifest_file);
+
+#endif

Modified: disnix/disnix/trunk/src/distribute/main.c
==============================================================================
--- disnix/disnix/trunk/src/distribute/main.c   Thu Oct 14 12:12:27 2010        
(r24283)
+++ disnix/disnix/trunk/src/distribute/main.c   Thu Oct 14 12:13:19 2010        
(r24284)
@@ -18,16 +18,9 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#define _GNU_SOURCE
 #include <getopt.h>
-#include <glib.h>
-#include <distributionmapping.h>
+#define _GNU_SOURCE
 #include <defaultoptions.h>
-#include <client-interface.h>
 
 static void print_usage()
 {
@@ -72,39 +65,5 @@
        return 1;
     }
     else
-    {
-       int exit_status = 0;
-       unsigned int i;
-       GArray *distribution_array;
-       
-       /* Generate a distribution array from the manifest file */
-       distribution_array = generate_distribution_array(argv[optind]);
-       
-       if(distribution_array == NULL)
-           exit_status = 1;
-       else
-       {
-           /* Iterate over the distribution array and distribute the profiles 
to the target machines */
-           for(i = 0; i < distribution_array->len; i++)
-           {
-               DistributionItem *item = g_array_index(distribution_array, 
DistributionItem*, i);
-               int status;
-           
-               fprintf(stderr, "Distributing intra-dependency closure of 
profile: %s to target: %s\n", item->profile, item->target);           
-               status = wait_to_finish(exec_copy_closure_to(interface, 
item->target, item->profile));
-               
-               /* On error stop the distribute process */
-               if(status != 0)
-               {
-                   exit_status = status;
-                   break;
-               }
-           }
-           
-           delete_distribution_array(distribution_array);
-       }
-       
-       /* Return the exit status, which is 0 if everything succeeds */
-       return exit_status;
-    }
+       return distribute(interface, argv[optind]); /* Execute distribute 
operation */
 }

Modified: disnix/disnix/trunk/src/query/Makefile.am
==============================================================================
--- disnix/disnix/trunk/src/query/Makefile.am   Thu Oct 14 12:12:27 2010        
(r24283)
+++ disnix/disnix/trunk/src/query/Makefile.am   Thu Oct 14 12:13:19 2010        
(r24284)
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -ggdb
 
 bin_PROGRAMS = disnix-query
+noinst_HEADERS = query-installed.h
 
-disnix_query_SOURCES = main.c
+disnix_query_SOURCES = query-installed.c main.c
 disnix_query_LDADD = ../libinfrastructure/libinfrastructure.la 
../libmain/libmain.la ../libinterface/libinterface.la
 disnix_query_CFLAGS = -I../libinfrastructure -I../libmain -I../libinterface

Modified: disnix/disnix/trunk/src/query/main.c
==============================================================================
--- disnix/disnix/trunk/src/query/main.c        Thu Oct 14 12:12:27 2010        
(r24283)
+++ disnix/disnix/trunk/src/query/main.c        Thu Oct 14 12:13:19 2010        
(r24284)
@@ -18,16 +18,10 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
 #include <getopt.h>
 #define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <glib.h>
-#include <infrastructure.h>
 #include <defaultoptions.h>
-#include <client-interface.h>
+#include "query-installed.h"
 
 static void print_usage()
 {
@@ -51,7 +45,6 @@
     char *interface = NULL;
     char *target_property = NULL;
     char *profile = NULL;
-    int exit_status = 0;
     
     /* Parse command-line options */
     while((c = getopt_long(argc, argv, "p:h", long_options, &option_index)) != 
-1)
@@ -85,29 +78,5 @@
        return 1;
     }
     else
-    {
-       GArray *target_array = create_target_array(argv[optind], 
target_property);
-       
-       if(target_array != NULL)
-       {
-           unsigned int i;
-           
-           for(i = 0; i < target_array->len; i++)
-           {
-               gchar *target = g_array_index(target_array, gchar*, i);
-               int status;
-               
-               printf("\nServices on: %s\n\n", target);
-               
-               status = wait_to_finish(exec_query_installed(interface, target, 
profile));
-                                               
-               if(status != 0)
-                   exit_status = status;
-           }
-           
-           delete_target_array(target_array);
-       }
-
-       return exit_status;
-    }
+       return query_installed(interface, target_property, argv[optind], 
profile); /* Execute query operation */
 }

Added: disnix/disnix/trunk/src/query/query-installed.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ disnix/disnix/trunk/src/query/query-installed.c     Thu Oct 14 12:13:19 
2010        (r24284)
@@ -0,0 +1,57 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010  Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+#include "query-installed.h"
+#include <infrastructure.h>
+#include <client-interface.h>
+
+int query_installed(gchar *interface, gchar *target_property, gchar 
*infrastructure_expr, gchar *profile)
+{
+    int exit_status;
+    
+    /* Retrieve an array of all target machines from the infrastructure 
expression */
+    GArray *target_array = create_target_array(infrastructure_expr, 
target_property);
+
+    if(target_array != NULL)
+    {
+        unsigned int i;
+           
+       /* For each target execute the query operation and display the results 
*/
+        for(i = 0; i < target_array->len; i++)
+        {
+           gchar *target = g_array_index(target_array, gchar*, i);
+           int status;
+               
+           g_print("\nServices on: %s\n\n", target);
+               
+           status = wait_to_finish(exec_query_installed(interface, target, 
profile));
+                                               
+           if(status != 0)
+           {
+               g_printerr("Failed executing the query operation!\n");
+               exit_status = status;
+           }
+       }
+       
+       /* Delete the target array from memory */
+       delete_target_array(target_array);
+    }
+
+    /* Return the exit status, which is 0 if everything succeeds */
+    return exit_status;
+}

Added: disnix/disnix/trunk/src/query/query-installed.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ disnix/disnix/trunk/src/query/query-installed.h     Thu Oct 14 12:13:19 
2010        (r24284)
@@ -0,0 +1,37 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010  Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+
+#ifndef __QUERY_INSTALLED_H
+#define __QUERY_INSTALLED_H
+#include <glib.h>
+
+/**
+ * Iterates over targets defined in an infrastructure Nix expression and
+ * performs the query-installed operation on each target.
+ *
+ * @param interface Path to the client interface executable
+ * @param target_property Property in the infrastructure model which specifies
+ *                        how to connect to the Disnix service
+ * @param infrastructure_expr Path to the infrastructure expression
+ * @param profile Name of the distributed profile
+ * @return 0 if all the operations succeed, else a non-zero value
+ */
+int query_installed(gchar *interface, gchar *target_property, gchar 
*infrastructure_expr, gchar *profile);
+
+#endif

Modified: disnix/disnix/trunk/src/visualize/Makefile.am
==============================================================================
--- disnix/disnix/trunk/src/visualize/Makefile.am       Thu Oct 14 12:12:27 
2010        (r24283)
+++ disnix/disnix/trunk/src/visualize/Makefile.am       Thu Oct 14 12:13:19 
2010        (r24284)
@@ -1,8 +1,8 @@
 AM_CPPFLAGS = -ggdb
 
 bin_PROGRAMS = disnix-visualize
-noinst_HEADERS = clustertable.h edgestable.h
+noinst_HEADERS = clustertable.h edgestable.h graph.h
 
-disnix_visualize_SOURCES = main.c clustertable.c edgestable.c
+disnix_visualize_SOURCES = main.c clustertable.c edgestable.c graph.c
 disnix_visualize_LDADD = ../libmanifest/libmanifest.la
 disnix_visualize_CFLAGS = -I../libmanifest

Added: disnix/disnix/trunk/src/visualize/graph.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ disnix/disnix/trunk/src/visualize/graph.c   Thu Oct 14 12:13:19 2010        
(r24284)
@@ -0,0 +1,89 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010  Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+
+#include "graph.h"
+#include "edgestable.h"
+#include "clustertable.h"
+#include <activationmapping.h>
+
+void generate_graph(gchar *manifest_file)
+{
+    /* Creates an array with activation items from the manifest */
+    GArray *activation_array = create_activation_array(manifest_file);
+    
+    /* Creates a table which maps each target onto a list of mappings */
+    GHashTable *cluster_table = generate_cluster_table(activation_array);
+    
+    /* Creates a table which associates each mapping to its dependencies */
+    GHashTable *edges_table = generate_edges_table(activation_array);
+    
+    GHashTableIter iter;
+    gpointer *key;
+    gpointer *value;    
+    int count = 0;
+
+    g_print("digraph G {\n");
+        
+    /* Generate clusters with nodes from the cluster table */
+        
+    g_hash_table_iter_init(&iter, cluster_table);
+    while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value)) 
+    {
+       unsigned int i;
+       GArray *cluster_array = (GArray*)value;
+       gchar *target = (gchar*)key;
+       
+       g_print("subgraph cluster_%d {\n", count);
+       g_print("style=filled;\n");
+       g_print("node [style=filled,fillcolor=white,color=black];\n");
+       
+       for(i = 0; i < cluster_array->len; i++) 
+       {
+           gchar *service = g_array_index(cluster_array, gchar*, i);
+           g_print("\"%s:%s\" [ label = \"%s\" ];\n", service, target, 
service+44);        
+       }
+       
+       g_print("label = \"%s\"\n", target);
+       g_print("}\n");
+       
+       count++;
+    }
+    
+    /* Generate edges from the edges table */
+    
+    g_hash_table_iter_init(&iter, edges_table);
+    while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value)) 
+    {
+       unsigned int i;
+       GArray *dependency_array = (GArray*)value;
+       
+       for(i = 0; i < dependency_array->len; i++)
+       {
+           gchar *dep = g_array_index(dependency_array, gchar*, i);
+           g_print("\"%s\" -> \"%s\"\n", (gchar*)key, dep);
+       }
+    }
+    
+    g_print("}\n");
+    
+    /* Cleanup */
+    destroy_cluster_table(cluster_table);
+    destroy_edges_table(edges_table);
+    delete_activation_array(activation_array);
+}

Added: disnix/disnix/trunk/src/visualize/graph.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ disnix/disnix/trunk/src/visualize/graph.h   Thu Oct 14 12:13:19 2010        
(r24284)
@@ -0,0 +1,32 @@
+/*
+ * Disnix - A distributed application layer for Nix
+ * Copyright (C) 2008-2010  Sander van der Burg
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+
+#ifndef __GRAPH_H
+#define __GRAPH_H
+#include <glib.h>
+
+/**
+ * Prints a clustered graph in dot format from a manifest file to
+ * the standard output.
+ *
+ * @param manifest_file Manifest file to visualize
+ */
+void generate_graph(gchar *manifest_file);
+
+#endif

Modified: disnix/disnix/trunk/src/visualize/main.c
==============================================================================
--- disnix/disnix/trunk/src/visualize/main.c    Thu Oct 14 12:12:27 2010        
(r24283)
+++ disnix/disnix/trunk/src/visualize/main.c    Thu Oct 14 12:13:19 2010        
(r24284)
@@ -20,10 +20,7 @@
 #include <stdio.h>
 #define _GNU_SOURCE
 #include <getopt.h>
-#include <activationmapping.h>
-#include <glib.h>
-#include "clustertable.h"
-#include "edgestable.h"
+#include "graph.h"
 
 static void print_usage()
 {
@@ -32,78 +29,6 @@
     fprintf(stderr, "disnix-visualize {-h | --help}\n");
 }
 
-/**
- * Prints a clustered graph in dot format from a manifest file to
- * the standard output.
- *
- * @param manifest_file Manifest file to visualize
- */
-static void generate_graph(char *manifest_file)
-{
-    /* Creates an array with activation items from the manifest */
-    GArray *activation_array = create_activation_array(manifest_file);
-    
-    /* Creates a table which maps each target onto a list of mappings */
-    GHashTable *cluster_table = generate_cluster_table(activation_array);
-    
-    /* Creates a table which associates each mapping to its dependencies */
-    GHashTable *edges_table = generate_edges_table(activation_array);
-    
-    GHashTableIter iter;
-    gpointer *key;
-    gpointer *value;    
-    int count = 0;
-
-    g_print("digraph G {\n");
-        
-    /* Generate clusters with nodes from the cluster table */
-        
-    g_hash_table_iter_init(&iter, cluster_table);
-    while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value)) 
-    {
-       unsigned int i;
-       GArray *cluster_array = (GArray*)value;
-       gchar *target = (gchar*)key;
-       
-       g_print("subgraph cluster_%d {\n", count);
-       g_print("style=filled;\n");
-       g_print("node [style=filled,fillcolor=white,color=black];\n");
-       
-       for(i = 0; i < cluster_array->len; i++) 
-       {
-           gchar *service = g_array_index(cluster_array, gchar*, i);
-           g_print("\"%s:%s\" [ label = \"%s\" ];\n", service, target, 
service+44);        
-       }
-       
-       g_print("label = \"%s\"\n", target);
-       g_print("}\n");
-       
-       count++;
-    }
-    
-    /* Generate edges from the edges table */
-    
-    g_hash_table_iter_init(&iter, edges_table);
-    while(g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value)) 
-    {
-       unsigned int i;
-       GArray *dependency_array = (GArray*)value;
-       
-       for(i = 0; i < dependency_array->len; i++)
-       {
-           gchar *dep = g_array_index(dependency_array, gchar*, i);
-           g_print("\"%s\" -> \"%s\"\n", (gchar*)key, dep);
-       }
-    }
-    
-    g_print("}\n");
-    
-    /* Cleanup */
-    destroy_cluster_table(cluster_table);
-    destroy_edges_table(edges_table);
-    delete_activation_array(activation_array);
-}
-
 int main(int argc, char *argv[])
 {
     /* Declarations */
@@ -132,6 +57,7 @@
     }
     else
     {
+       /* Execute operation */
        generate_graph(argv[optind]);
        return 0;
     }
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits

Reply via email to