/[dgee]/dgee/cslib/DotGNU/DGEE/Protocols/ProtocolService.cs
ViewVC logotype

Diff of /dgee/cslib/DotGNU/DGEE/Protocols/ProtocolService.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by npg, Tue Jul 29 01:42:03 2003 UTC revision 1.2 by csmith, Sun Sep 21 10:55:47 2003 UTC
# Line 0  Line 1 
1    /*
2     * DotGNU DGEE Protocol Service
3     *
4     * Copyright (C) 2003 netFluid Technology Limited
5     * Copyright (C) 2003 Free Software Foundation, Inc.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20     *
21     * $Revision$  $Date$
22     *
23     * --------------------------------------------------------------------------
24     *
25     * Authors:
26     *   Nicolai P Guba
27     */
28    using System;
29    using System.IO;
30    using System.Reflection;
31    using DotGNU.XmlRpc;
32    using DotGNU.DGEE.Protocols.XmlRpc;
33    
34    namespace DotGNU.DGEE.Protocols
35    {
36    public abstract  class ProtocolService
37    {
38      static protected IProtocolHandler handler;
39      static protected bool dgeeDebug = false;    
40    
41    
42      /// this method is the entry point for the pnetvm
43      public static String DGEE_run( String []args )
44      {
45        if( args.Length < 3 ) {
46          //
47          // TODO:  plug in generic exception handling
48          //        via the IProtocolsException handler interface.
49          throw new
50            Exception( "Not enough arguments passed to DGEE request handler" );
51        }
52    
53        String assembly = args[0];
54        String type     = args[1];
55        String method   = args[2];
56    
57        if( dgeeDebug ) {
58          Console.WriteLine( "DLL   : {0}", assembly );
59          Console.WriteLine( "Class : {0}", type );
60          Console.WriteLine( "Method: {0}", (method != null) ? method : "UNSET" );
61        }
62                                                                          
63        MemoryStream stream = new MemoryStream();
64        StreamWriter writer = new StreamWriter( stream );
65        StreamReader reader = new StreamReader( stream );
66    
67        // handler is constructed by the ServiceHandler that derives from this
68        // base class.
69        //
70        if( handler == null ) {
71          throw new Exception ( "ERROR: No protocol handler registered" );
72        }
73          
74        // Write the request sting to the stream
75        // TODO - Can we make this get the request from memory instead of a
76        //        String passed in as args????
77        //
78        writer.Write( args[3] );
79        writer.Flush();
80        stream.Seek( 0, 0 );
81          
82        // The request hanlder now deserializes the incoming stream into
83        // a method representing the method to be invoked.
84        //
85        Object rMethod = handler.Request( reader );
86        long pos = stream.Position;
87    
88        // At this stage we have an object from the protocol request
89        // handler which represents the method to be invoked
90        //
91        AssemblyContainer ac = new AssemblyContainer( assembly );
92        MethodInfo minfo;
93    
94        // Use the DGMX derived method name, or the one pulled out of the
95        // request.
96        //
97        // FIXME - This is hardcoaded as an XmlRpcMethod object
98        //         (yep, for now it is --for simplicity's sake ;) [npg]
99        //
100            RequestProc rproc = new RequestProc();
101    
102        Type svcType = rproc.ResolveType( type );
103        minfo = rproc.ResolveMethod( svcType, (method != null) ? method : ((XmlRpcMethod)rMethod).Name);
104    
105        // Create an instance of the webservice to invoke
106            //
107            Object webservice = Activator.CreateInstance( svcType );
108    
109        Object result = minfo.Invoke(webservice, ((XmlRpcMethod)rMethod).ToArray());
110          
111        // Send reply back via the Protocol's response handler
112        // implementation
113        handler.Response( writer, result );
114        stream.Seek( pos, 0 );
115    
116        reader = new StreamReader( stream );
117        String outputString = reader.ReadToEnd();
118    
119        // return the resources
120        writer.Close();
121        reader.Close();
122        stream.Close();
123    
124        return outputString;
125      }
126     }
127    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26