7156248 rad best practices
authorStephen Talley <stephen.talley@oracle.com>
Fri, 23 Mar 2012 16:12:19 -0400
changeset 821 75115321d358
parent 820 654f8c0ddf84
child 822 73502b667ee9
7156248 rad best practices
usr/src/doc/rad-dev/c-client-python.xml
usr/src/doc/rad-dev/client-example-python-1.py
usr/src/doc/rad-dev/client-example-python-2.py
usr/src/doc/rad-dev/client-example-python-3.py
--- a/usr/src/doc/rad-dev/c-client-python.xml	Fri Mar 23 15:40:24 2012 -0400
+++ b/usr/src/doc/rad-dev/c-client-python.xml	Fri Mar 23 16:12:19 2012 -0400
@@ -18,145 +18,197 @@
 
 <section xmlns:xi="http://www.w3.org/2001/XInclude"><title>Python Client</title>
 
-    <!-- Modules -->
-    <section><title>Modules</title>
+  <!-- Modules -->
+  <section><title>Modules</title>
+    <para>
+      The RAD Python implementation provides the following
+      modules to facilitate client implementation.
+    </para>
+    <section><title>adaptor</title>
+      <para>
+        Provides classes which adapt the behaviour of low
+        level RAD instances to be more "Pythonesque" in
+        nature. For instance, RAD protocol errors are mapped
+        to Python exceptions.
+      </para>
+    </section>
+    <section><title>client</title>
+      <para>
+        Provides classes and methods which fully implement the RAD
+        protocol in Python.
+      </para>
+    </section>
+    <section><title>util</title>
+      <para>
+        Provides an Authentication class and utility methods for
+        connecting a Python client to RAD.
+      </para>
+      <para>
         <para>
-            The RAD Python implementation provides the following
-            modules to facilitate client implementation.
+        <ooclass>
+          <package>rad.util </package> <classname>RadAuth</classname>
+        </ooclass>
+        </para>
+        <para>
+          A class which fetches and caches a handle to an
+          authentication object along with some convenience
+          methods for manipulating it.
         </para>
-        <section><title>adaptor</title>
-            <para>
-                Provides classes which adapt the behaviour of low
-                level RAD instances to be more "Pythonesque" in
-                nature. For instance, RAD protocol errors are mapped
-                to Python exceptions.
-            </para>
-        </section>
-        <section><title>client</title>
-            <para>
-                Provides classes and methods which fully implement the RAD
-                protocol in Python.
-            </para>
-        </section>
-        <section><title>util</title>
-            <para>
-                Provides an Authentication class and utility methods for
-                connecting a Python client to RAD.
-            </para>
-            <para>
-                <para>
-                <ooclass>
-                    <package>rad.util </package> <classname>RadAuth</classname>
-                </ooclass>
-                </para>
-                <para>
-                    A class which fetches and caches a handle to an
-                    authentication object along with some convenience
-                    methods for manipulating it.
-                </para>
-                <para>
-                <ooclass>
-                    <package>rad.util </package> <classname>SocketLike</classname>
-                </ooclass>
-                </para>
-                <para>
-                    A utility class which can be used to wrap a pipe
-                    and make it behave like a socket.
-                </para>
-                <funcsynopsis>
-                    <funcprototype>
-                        <funcdef>
-                            <type>RadConnection</type>
-                            <function>connect_local</function>
-                        </funcdef>
-                        <paramdef>
-                            <type>string</type> <parameter>path</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>string</type> <parameter>locale</parameter>
-                        </paramdef>
-                    </funcprototype>
-                    <para>
-                        This can be used to connect to a local RAD
-                        instance. The path specifies a af_unix
-                        socket which was created by a RAD
-                        instance. locale is the locale to be used for
-                        this connection.
-                    </para>
-                    <funcprototype>
-                        <funcdef>
-                            <type>RadConnection</type>
-                            <function>connect_private</function>
-                        </funcdef>
-                        <paramdef>
-                            <type>string list</type> <parameter>modules</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>boolean</type> <parameter>debug</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>string map</type> <parameter>env</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>string</type> <parameter>root</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>string</type> <parameter>auxargs</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>string</type> <parameter>locale</parameter>
-                        </paramdef>
-                    </funcprototype>
-                    <funcprototype>
-                        <funcdef>
-                            <type>RadConnection</type>
-                            <function>connect_ssh</function>
-                        </funcdef>
-                        <paramdef>
-                            <type>string</type> <parameter>host</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>string</type> <parameter>user</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>string</type> <parameter>locale</parameter>
-                        </paramdef>
-                    </funcprototype>
-                    <funcprototype>
-                        <funcdef>
-                            <type>RadConnection</type>
-                            <function>connect_ssl</function>
-                        </funcdef>
-                        <paramdef>
-                            <type>string</type> <parameter>host</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>integer</type> <parameter>port</parameter>
-                        </paramdef>
-                        <paramdef>
-                            <type>string</type> <parameter>locale</parameter>
-                        </paramdef>
-                    </funcprototype>
-                </funcsynopsis>
-            </para>
-        </section>
+        <funcsynopsis>
+          <funcprototype>
+            <funcdef>
+              <type>RadConnection</type>
+              <function>connect_local</function>
+            </funcdef>
+            <paramdef>
+              <type>string</type> <parameter>path</parameter>
+            </paramdef>
+            <paramdef>
+              <type>string</type> <parameter>locale</parameter>
+            </paramdef>
+          </funcprototype>
+          <para>
+            This can be used to connect to a local RAD
+            instance. The path specifies a af_unix
+            socket which was created by a RAD
+            instance. locale is the locale to be used for
+            this connection.
+          </para>
+          <funcprototype>
+            <funcdef>
+              <type>RadConnection</type>
+              <function>connect_private</function>
+            </funcdef>
+            <paramdef>
+              <type>string list</type> <parameter>modules</parameter>
+            </paramdef>
+            <paramdef>
+              <type>boolean</type> <parameter>debug</parameter>
+            </paramdef>
+            <paramdef>
+              <type>string map</type> <parameter>env</parameter>
+            </paramdef>
+            <paramdef>
+              <type>string</type> <parameter>root</parameter>
+            </paramdef>
+            <paramdef>
+              <type>string</type> <parameter>auxargs</parameter>
+            </paramdef>
+            <paramdef>
+              <type>string</type> <parameter>locale</parameter>
+            </paramdef>
+          </funcprototype>
+          <funcprototype>
+            <funcdef>
+              <type>RadConnection</type>
+              <function>connect_ssh</function>
+            </funcdef>
+            <paramdef>
+              <type>string</type> <parameter>host</parameter>
+            </paramdef>
+            <paramdef>
+              <type>string</type> <parameter>user</parameter>
+            </paramdef>
+            <paramdef>
+              <type>string</type> <parameter>locale</parameter>
+            </paramdef>
+          </funcprototype>
+          <funcprototype>
+            <funcdef>
+              <type>RadConnection</type>
+              <function>connect_ssl</function>
+            </funcdef>
+            <paramdef>
+              <type>string</type> <parameter>host</parameter>
+            </paramdef>
+            <paramdef>
+              <type>integer</type> <parameter>port</parameter>
+            </paramdef>
+            <paramdef>
+              <type>string</type> <parameter>locale</parameter>
+            </paramdef>
+          </funcprototype>
+        </funcsynopsis>
+        <funcprototype>
+          <funcdef>
+            <type>RadConnection</type>
+            <function>connect_zone</function>
+          </funcdef>
+          <paramdef>
+            <type>RadConnection</type> <parameter>rc</parameter>
+          </paramdef>
+          <paramdef>
+            <type>string</type> <parameter>zone</parameter>
+          </paramdef>
+          <paramdef>
+            <type>string</type> <parameter>user</parameter>
+          </paramdef>
+          <paramdef>
+            <type>string</type> <parameter>locale</parameter>
+          </paramdef>
+        </funcprototype>
+      </para>
     </section>
-    <!-- Examples -->
-    <section>
-        <example><title>Method Invocation</title>
-        <programlisting>
-<xi:include parse="text" href="client-example-python-1.py" />
-        </programlisting>
-        </example>
-        <example><title>Attribute Access</title>
-        <programlisting>
-<xi:include parse="text" href="client-example-python-2.py" />
-        </programlisting>
-        </example>
-        <example><title>Event Subscription</title>
-        <programlisting>
-<xi:include parse="text" href="client-example-python-3.py" />
-        </programlisting>
-        </example>
-    </section>
+  </section>
+  <!-- Examples -->
+  <section>
+    <example><title>Method Invocation</title>
+    <programlisting>
+import rad.util
+import rad.adaptor
+
+# Connect to a local RAD instance.
+rc = rad.util.connect_local()
+
+# Obtain a remote reference to the desired target.
+rawobj= rc.get_object_s("com.example", [("type", "GrabBag")])
+obj = rad.adaptor.RawAdaptor(rawobj)
+
+# Invoke a method on the target.
+res = obj.parseString("a test string")
+
+# Print the result.
+print "length: " + str(res.length)
+    </programlisting>
+    </example>
+    <example><title>Attribute Access</title>
+    <programlisting>
+import rad.util
+import rad.adaptor
+
+# Connect to a local RAD instance.
+rc = rad.util.connect_local()
+
+# Obtain a remote reference to the desired target.
+rawobj= rc.get_object_s("com.example", [("type", "GrabBag")])
+obj = rad.adaptor.RawAdaptor(rawobj)
+
+# Print the object attribute.
+print "Mood: " + str(obj.mood)</programlisting>
+    </example>
+    <example><title>Event Subscription</title>
+    <programlisting>
+import rad.util
+import rad.adaptor
+
+# Connect to a local RAD instance.
+rc = rad.util.connect_local()
+
+# Obtain a remote reference to the desired target.
+rawobj= rc.get_object_s("com.example", [("type", "GrabBag")])
+obj = rad.adaptor.RawAdaptor(rawobj)
+
+# Subscribe to the "moodswings" event
+rc.subscribe(rawobj, "moodswings")
+
+type = rc.get_type(obj._object._typeid)
+while True:
+    # Perform a (blocking) read of an event
+    ev_obj = type.read_event()
+
+    print "Received Event:"
+    print "mood: " +str(ev_obj.mood)
+    print "changed: " +str(ev_obj.changed)</programlisting>
+    </example>
+  </section>
 </section>
--- a/usr/src/doc/rad-dev/client-example-python-1.py	Fri Mar 23 15:40:24 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-#!/usr/bin/python2.6
-#
-# CDDL HEADER START
-#
-# The contents of this file are subject to the terms of the
-# Common Development and Distribution License (the "License").
-# You may not use this file except in compliance with the License.
-#
-# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-# or http://www.opensolaris.org/os/licensing.
-# See the License for the specific language governing permissions
-# and limitations under the License.
-#
-# When distributing Covered Code, include this CDDL HEADER in each
-# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-# If applicable, add the following below this CDDL HEADER, with the
-# fields enclosed by brackets "[]" replaced with your own identifying
-# information: Portions Copyright [yyyy] [name of copyright owner]
-#
-# CDDL HEADER END
-#
-# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
-#
-
-import rad.client as rad
-import rad.util as radutil
-import rad.adaptor as adapt
-
-##
-# - Connect to a local RAD instance.
-# - Obtain a remote reference to the desired target.
-# - Invoke a method on the target.
-# - Print the result.
-##
-
-rc = radutil.connect_local()
-
-rawobj= rc.get_object_s("com.example", [("type", "GrabBag")])
-
-obj = adapt.RawAdaptor(rawobj)
-
-res = obj.parseString("a test string")
-
-print "length: " + str(res.length)
-
-sys.exit(0)
--- a/usr/src/doc/rad-dev/client-example-python-2.py	Fri Mar 23 15:40:24 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-#!/usr/bin/python2.6
-#
-# CDDL HEADER START
-#
-# The contents of this file are subject to the terms of the
-# Common Development and Distribution License (the "License").
-# You may not use this file except in compliance with the License.
-#
-# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-# or http://www.opensolaris.org/os/licensing.
-# See the License for the specific language governing permissions
-# and limitations under the License.
-#
-# When distributing Covered Code, include this CDDL HEADER in each
-# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-# If applicable, add the following below this CDDL HEADER, with the
-# fields enclosed by brackets "[]" replaced with your own identifying
-# information: Portions Copyright [yyyy] [name of copyright owner]
-#
-# CDDL HEADER END
-#
-# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
-#
-
-import rad.client as rad
-import rad.util as radutil
-import rad.adaptor as adapt
-
-##
-# - Connect to a local RAD instance.
-# - Obtain a remote reference to the desired target.
-# - Print the object attribute.
-##
-
-rc = radutil.connect_local()
-
-rawobj= rc.get_object_s("com.example", [("type", "GrabBag")])
-
-obj = adapt.RawAdaptor(rawobj)
-
-print "Mood: " + str(obj.mood)
-
-sys.exit(0)
--- a/usr/src/doc/rad-dev/client-example-python-3.py	Fri Mar 23 15:40:24 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-#!/usr/bin/python2.6
-#
-# CDDL HEADER START
-#
-# The contents of this file are subject to the terms of the
-# Common Development and Distribution License (the "License").
-# You may not use this file except in compliance with the License.
-#
-# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-# or http://www.opensolaris.org/os/licensing.
-# See the License for the specific language governing permissions
-# and limitations under the License.
-#
-# When distributing Covered Code, include this CDDL HEADER in each
-# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-# If applicable, add the following below this CDDL HEADER, with the
-# fields enclosed by brackets "[]" replaced with your own identifying
-# information: Portions Copyright [yyyy] [name of copyright owner]
-#
-# CDDL HEADER END
-#
-# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
-#
-
-import rad.client as rad
-import rad.util as radutil
-import rad.adaptor as adapt
-
-##
-# - Connect to a local RAD instance.
-# - Obtain a remote reference to the desired target.
-# - Subscribe to the "moodswings" event
-# - Get the type of the remote reference
-# - Loop forever
-#	- Perform a (blocking) read of an event
-#	- Print the event details
-##
-
-rc = radutil.connect_local()
-
-rawobj= rc.get_object_s("com.example", [("type", "GrabBag")])
-
-rc.subscribe(rawobj, "moodswings")
-
-obj = adapt.RawAdaptor(rawobj)
-
-type = rc.get_type(obj._object._typeid)
-
-while True:
-	ev_obj = type.read_event()
-	print "Received Event:"
-	print "mood: " +str(ev_obj.mood)
-	print "changed: " +str(ev_obj.changed)
-
-sys.exit(0)