[Saga-devel] saga SVN commit 3252: /trunk/examples/misc/

amerzky at cct.lsu.edu amerzky at cct.lsu.edu
Fri Jan 9 06:12:08 CST 2009


User: amerzky
Date: 2009/01/09 06:12 AM

Added:
 /trunk/examples/misc/
  advert.cpp, context.cpp, dir.cpp, ssh_file.cpp, ssh_job.cpp

Log:
 some misc examples.  Feel free to change/remove/...
 A

File Changes:

Directory: /trunk/examples/misc/
================================

File [added]: advert.cpp
Delta lines: +55 -0
===================================================================
--- trunk/examples/misc/advert.cpp	2009-01-09 12:09:14 UTC (rev 3251)
+++ trunk/examples/misc/advert.cpp	2009-01-09 12:11:51 UTC (rev 3252)
@@ -0,0 +1,55 @@
+
+#include <sstream>
+
+#include <saga/saga.hpp>
+
+class my_cb : public saga::callback
+{
+  public:
+    bool cb (saga::monitorable o, 
+             saga::metric      m, 
+             saga::context     c)
+    {
+      std::cout << "cb was called\n";
+
+      return true;
+    }
+};
+
+int main()
+{
+  try
+  {
+    saga::advert::directory d ("/", saga::advert::ReadWrite);
+
+
+    saga::advert::entry ad = d.open ("/test",
+                                     saga::advert::Create    | 
+                                     saga::advert::ReadWrite );
+
+    my_cb cb;
+    ad.add_callback (saga::advert::metrics::advert_modified, cb);
+
+    int i = 0;
+    while ( i < 10 )
+    {
+      std::cout << "creating advert\n";
+      i++;
+
+      std::stringstream ss;
+      ss << i; 
+
+      ad.set_attribute (ss.str (), ss.str ());
+
+      ::getchar ();
+    }
+  }
+  catch ( saga::exception const & e )
+  {
+    std::cerr << "SAGA Exception: " << e.what ();
+    return -1;
+  }
+
+  return 0;
+}
+

File [added]: context.cpp
Delta lines: +69 -0
===================================================================
--- trunk/examples/misc/context.cpp	2009-01-09 12:09:14 UTC (rev 3251)
+++ trunk/examples/misc/context.cpp	2009-01-09 12:11:51 UTC (rev 3252)
@@ -0,0 +1,69 @@
+//  Copyright (c) 2005-2007 Andre Merzky <andre at merzky.net>
+//
+//  Distributed under the Boost Software License, Version 1.0.
+//  (See accompanying file LICENSE file or copy at
+//  http://www.boost.org/LICENSE_1_0.txt)
+
+#include <saga/saga.hpp>
+
+#define COUNT 100
+
+void dump_context (saga::context c)
+{
+  std::vector <std::string> attribs = c.list_attributes ();
+
+  std::cout << " ------------------------------ " << std::endl;
+
+  for ( int i = 0; i < attribs.size (); i++ )
+  {
+    std::cout << " " << attribs[i] << " \t: ";
+
+    if ( c.attribute_is_vector (attribs[i]) )
+    {
+      std::vector <std::string> vals = c.get_vector_attribute (attribs[i]);
+
+      for ( int j = 0; j < vals.size (); j++ )
+      {
+        std::cout << vals[j] << " ";
+      }
+    }
+    else
+    {
+      std::string val = c.get_attribute (attribs[i]);
+      std::cout << val << " ";
+    }
+
+    std::cout << std::endl;
+  }
+
+  std::cout << " ------------------------------ " << std::endl;
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+int main (int argc, char* argv[])
+{
+  std::string type = "";
+
+  if ( argc > 1 )
+  {
+    type = argv[1];
+  }
+
+  try {
+    saga::context c (type);
+
+    c.set_attribute ("UserID", "root");
+    c.set_defaults  ();
+
+    dump_context (c);
+
+  }
+  catch ( const saga::exception & e )
+  {
+    std::cerr << e.what () << std::endl;
+  }
+  
+  return 0; 
+}
+

File [added]: dir.cpp
Delta lines: +21 -0
===================================================================
--- trunk/examples/misc/dir.cpp	2009-01-09 12:09:14 UTC (rev 3251)
+++ trunk/examples/misc/dir.cpp	2009-01-09 12:11:51 UTC (rev 3252)
@@ -0,0 +1,21 @@
+
+#include <saga/saga.hpp>
+
+int main ()
+{
+  try 
+  {
+    saga::url u ("file://localhost//Users/merzky/.saga/adaptors/ssh/ssh_file/mnt/");
+
+    std::cout << " trying to create " << u << "\n";
+
+    saga::filesystem::directory d (u, 
+                                   saga::filesystem::Create |
+                                   saga::filesystem::CreateParents);
+  }
+  catch ( const saga::exception & e )
+  {
+    std::cerr << "cannot create directory\n";
+  }
+}
+

File [added]: ssh_file.cpp
Delta lines: +35 -0
===================================================================
--- trunk/examples/misc/ssh_file.cpp	2009-01-09 12:09:14 UTC (rev 3251)
+++ trunk/examples/misc/ssh_file.cpp	2009-01-09 12:11:51 UTC (rev 3252)
@@ -0,0 +1,35 @@
+
+#include <saga/saga.hpp>
+
+int main ()
+{
+  try 
+  {
+    saga::session s;
+    saga::context c ("ssh");
+
+    c.set_defaults ();
+    s.add_context  (c);
+
+    saga::filesystem::directory d1 (s, "ssh://qb.loni.org/home/merzky/");
+
+    std::cout << "d1: " << d1.get_url () << "\n";
+
+    saga::filesystem::directory d2 = d1.open_dir ("perl",
+                                                 saga::filesystem::Read);
+
+    std::cout << "d2: " << d2.get_url () << "\n";
+
+    saga::filesystem::file f = d2.open ("HTTP-Proxy-0.23.tar.gz",
+                                        saga::filesystem::Read);
+
+    size_t size = f.get_size ();
+
+    std::cout << f.get_url () << " : " << size << "\n";
+  }
+  catch ( const saga::exception & e )
+  {
+    std::cerr << e.what ();
+  }
+}
+

File [added]: ssh_job.cpp
Delta lines: +60 -0
===================================================================
--- trunk/examples/misc/ssh_job.cpp	2009-01-09 12:09:14 UTC (rev 3251)
+++ trunk/examples/misc/ssh_job.cpp	2009-01-09 12:11:51 UTC (rev 3252)
@@ -0,0 +1,60 @@
+
+#include <saga/saga.hpp>
+
+int main ()
+{
+  try 
+  {
+    saga::context c ("ssh");
+    c.set_attribute ("UserID", "merzky");
+    c.set_defaults  ();
+
+    saga::session s;
+    s.add_context (c);
+
+    std::string host;
+    
+//  host = "localhost"; 
+//  host = "172.16.216.130";
+    host = "qb.loni.org";
+
+    saga::job::service js (s, std::string ("ssh://") + host);
+    
+    saga::job::ostream in;
+    saga::job::istream out;
+    saga::job::istream err;
+
+    saga::job::job j = js.run_job ("/bin/uname -a", host, in, out, err);
+
+    while ( true )
+    {
+      char buffer[255];
+      out.read (buffer, sizeof (buffer));
+
+      if ( out.gcount () > 0 )
+        std::cout << std::string (buffer, out.gcount ());
+
+      if ( out.fail () )
+        break;
+    }
+
+    j.wait ();
+
+
+    if ( j.get_state () == saga::job::Done )
+    {
+      std::cout << "job done\n";
+    }
+    else
+    {
+      std::cout << "job failed\n";
+    }
+
+
+  }
+  catch ( const saga::exception & e )
+  {
+    std::cerr << e.what ();
+  }
+}
+



More information about the saga-devel mailing list