RE: [Mono-list] Syslog Access

2004-08-17 Thread Jonathan Stowe
On Tue, 2004-08-17 at 06:06, Iain McCoy wrote:
 On Tue, 2004-08-17 at 14:35, Craig Dayton wrote:
  Perhaps exploring the possibility of using PerlNet a product marketed by
  ActiveState might be a cost effective solution.
  
  With PerlNet, one can define an Interface to any module on CPAN and compile
  it as a library or executable.  So from a developer's prospective, a
  programmer can leverage modules in CPAN and the .NET community all within a
  single executable.  Thanks to Mono this capability is now extended to the
  Unix world. No sense in reinventing the wheel is there?  
 Is it extended to the unix world? My understanding of PerlNet was that
 it worked by interfacing between the regular win32 perl interpreter and
 the MS CLR - not by compiling perl code to normal managed code. The MS
 CLR interfaces that it would use are not replicated by mono, so I
 suspect it doesn't work on a unix.

This is my understanding too.  However a solution for reusing CPAN
modules from within a .NET application on Unix would be to expose the
modules functionality in a SOAP server and access it via HTTP remoting
or a SOAP proxy, I am going to be giving a short talk in part on this
subject at YAPC::Europe next month and will post my slides sometime
afterwards if people are interested.  On Windows as an alternative for
reuse is to wrap the Perl module in a WIndows Script Component and
access it via COM Late binding in the .NET program.

Then there is perl-sharp by Rich Wareham  at
  
  http://charon.ucam.org/mason/software/perl-sharp.html

and PerlSharp by Joshua Tauberer at 

  http://taubz.for.net/code/perlsharp/

both of which are intended to enable accessing Perl code directly from
mono programs.

/J\


http://taubz.for.net/code/perlsharp/

___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


RE: [Mono-list] Syslog Access

2004-08-17 Thread Craig Dayton
Hi Iain,

You hit the nail on the head.  Sorry for getting others and myself excited
about the possibility of this working in Unix.

The quote below is from Jan Dubois who is one of the architects of PerlNet.

It would not work on Mono and Portable.NET without lots of changes as it
relies heavily on COM interop between .NET and Win32.

-Craig

-Original Message-
From: Iain McCoy [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 16, 2004 22:06
To: Craig Dayton
Cc: [EMAIL PROTECTED]
Subject: RE: [Mono-list] Syslog Access


On Tue, 2004-08-17 at 14:35, Craig Dayton wrote:
 Perhaps exploring the possibility of using PerlNet a product 
marketed 
 by ActiveState might be a cost effective solution.
 
 With PerlNet, one can define an Interface to any module on CPAN and 
 compile it as a library or executable.  So from a developer's 
 prospective, a programmer can leverage modules in CPAN and the .NET 
 community all within a single executable.  Thanks to Mono this 
 capability is now extended to the Unix world. No sense in 
reinventing the wheel is there?
Is it extended to the unix world? My understanding of PerlNet 
was that it worked by interfacing between the regular win32 
perl interpreter and the MS CLR - not by compiling perl code 
to normal managed code. The MS CLR interfaces that it would 
use are not replicated by mono, so I suspect it doesn't work on a unix.
-- 
Iain McCoy [EMAIL PROTECTED]


___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Syslog Access

2004-08-17 Thread Ian MacLean
Iain McCoy wrote:
On Tue, 2004-08-17 at 14:35, Craig Dayton wrote:
 

Perhaps exploring the possibility of using PerlNet a product marketed by
ActiveState might be a cost effective solution.
With PerlNet, one can define an Interface to any module on CPAN and compile
it as a library or executable.  So from a developer's prospective, a
programmer can leverage modules in CPAN and the .NET community all within a
single executable.  Thanks to Mono this capability is now extended to the
Unix world. No sense in reinventing the wheel is there?  
   

Is it extended to the unix world? My understanding of PerlNet was that
it worked by interfacing between the regular win32 perl interpreter and
the MS CLR - not by compiling perl code to normal managed code. The MS
CLR interfaces that it would use are not replicated by mono, so I
suspect it doesn't work on a unix.
 

this is corrert. PerlNet does not compile to il. It basically creates a 
managed shim that marshalls between managed types and native perl. The 
marshalling level is currently win32 specific.

Ian
___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Syslog Access

2004-08-16 Thread Jonathan Pryor
On Mon, 2004-08-16 at 17:34, Clint Fairchild wrote:
 Is there a simple solution to access syslog with C#?  I'm attempting to
 write a daemon.

The answer should be System.Diagnostics.EventLog.  Alas, it isn't,
because no one has implemented a shim to make syslog look like a Windows
Event Log yet.  Sorry, it hasn't been a priority.

You'll have to P/Invoke syslog(3) directly.  Lucky you, I wrote a short
demo of Hello, world for syslog(3).  Unlucky you, I was lazy and used
the constant values in /usr/include/sys/syslog.h on Fedora Core 2.  This
should be good for Linux systems, but the constants will have different
values on other Unix platforms, so a real solution would mimic
Mono.Posix.

// syslog example:
using System;
using System.Runtime.InteropServices;

class Syslog_h {
[Flags]
public enum Option {
Pid= 0x01,
Console= 0x02,
Delay  = 0x04,
NoDelay= 0x08,
NoWait = 0x10,
PrintError = 0x20
}

[Flags]
public enum Facility {
Kernel   = 0  3,
User = 1  3,
Mail = 2  3,
Daemon   = 3  3,
Auth = 4  3,
Syslog   = 5  3,
Lpr  = 6  3,
News = 7  3,
Uucp = 8  3,
Cron = 8  3,
AuthPriv = 10  3,
Ftp  = 11  3,
Local0   = 16  3,
Local1   = 17  3,
Local2   = 18  3,
Local3   = 19  3,
Local4   = 20  3,
Local5   = 21  3,
Local6   = 22  3,
Local7   = 23  3,
}

[Flags]
public enum Level {
Emerg   = 0,
Alert   = 1,
Crit= 2,
Err = 3,
Warning = 4,
Notice  = 5,
Info= 6,
Debug   = 7
}

// Note that `ident' is an IntPtr, not a string;
// see Demo.Main() for why
[DllImport (libc)]
public static extern void openlog (IntPtr ident, 
Option option, Facility facility);

[DllImport (libc)]
public static extern void syslog (int priority, 
string message);

[DllImport (libc)]
public static extern void closelog ();
}

class Demo {
public static void Main (string[] args)
{
// Ident needs to be an IntPtr, not a string, 
// as syslog doesn't copy the string; it 
// assumes that the string won't change.  
// Since strings are garbage collected, the
// string will eventually be collected, causing
// syslog(3) to print garbage for the ident
// unless we make sure `ident' is allocated in
// unmanaged memory:
IntPtr ident = Marshal.StringToHGlobalAnsi (
this is my ident);
Syslog_h.openlog (ident,
Syslog_h.Option.Console | Syslog_h.Option.Pid |
Syslog_h.Option.PrintError,
Syslog_h.Facility.User);
Syslog_h.syslog ((int) Syslog_h.Facility.User | 
(int) Syslog_h.Level.Debug,
Hello, syslog!);
Syslog_h.closelog ();
Marshal.FreeHGlobal (ident);
}
}

 - Jon


___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


RE: [Mono-list] Syslog Access

2004-08-16 Thread Craig Dayton

Perhaps exploring the possibility of using PerlNet a product marketed by
ActiveState might be a cost effective solution.

With PerlNet, one can define an Interface to any module on CPAN and compile
it as a library or executable.  So from a developer's prospective, a
programmer can leverage modules in CPAN and the .NET community all within a
single executable.  Thanks to Mono this capability is now extended to the
Unix world. No sense in reinventing the wheel is there?  

-Craig

-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Jonathan Pryor
Sent: Monday, August 16, 2004 18:56
To: Clint Fairchild
Cc: [EMAIL PROTECTED]
Subject: Re: [Mono-list] Syslog Access


On Mon, 2004-08-16 at 17:34, Clint Fairchild wrote:
 Is there a simple solution to access syslog with C#?  I'm attempting 
 to write a daemon.

The answer should be System.Diagnostics.EventLog.  Alas, it 
isn't, because no one has implemented a shim to make syslog 
look like a Windows Event Log yet.  Sorry, it hasn't been a priority.

You'll have to P/Invoke syslog(3) directly.  Lucky you, I 
wrote a short demo of Hello, world for syslog(3).  Unlucky 
you, I was lazy and used the constant values in 
/usr/include/sys/syslog.h on Fedora Core 2.  This should be 
good for Linux systems, but the constants will have different 
values on other Unix platforms, so a real solution would 
mimic Mono.Posix.

   // syslog example:
   using System;
   using System.Runtime.InteropServices;

   class Syslog_h {
   [Flags]
   public enum Option {
   Pid= 0x01,
   Console= 0x02,
   Delay  = 0x04,
   NoDelay= 0x08,
   NoWait = 0x10,
   PrintError = 0x20
   }

   [Flags]
   public enum Facility {
   Kernel   = 0  3,
   User = 1  3,
   Mail = 2  3,
   Daemon   = 3  3,
   Auth = 4  3,
   Syslog   = 5  3,
   Lpr  = 6  3,
   News = 7  3,
   Uucp = 8  3,
   Cron = 8  3,
   AuthPriv = 10  3,
   Ftp  = 11  3,
   Local0   = 16  3,
   Local1   = 17  3,
   Local2   = 18  3,
   Local3   = 19  3,
   Local4   = 20  3,
   Local5   = 21  3,
   Local6   = 22  3,
   Local7   = 23  3,
   }

   [Flags]
   public enum Level {
   Emerg   = 0,
   Alert   = 1,
   Crit= 2,
   Err = 3,
   Warning = 4,
   Notice  = 5,
   Info= 6,
   Debug   = 7
   }

   // Note that `ident' is an IntPtr, not a string;
   // see Demo.Main() for why
   [DllImport (libc)]
   public static extern void openlog (IntPtr ident, 
   Option option, Facility facility);

   [DllImport (libc)]
   public static extern void syslog (int priority, 
   string message);

   [DllImport (libc)]
   public static extern void closelog ();
   }

   class Demo {
   public static void Main (string[] args)
   {
   // Ident needs to be an IntPtr, not a string, 
   // as syslog doesn't copy the string; it 
   // assumes that the string won't change.  
   // Since strings are garbage collected, the
   // string will eventually be collected, causing
   // syslog(3) to print garbage for the ident
   // unless we make sure `ident' is allocated in
   // unmanaged memory:
   IntPtr ident = Marshal.StringToHGlobalAnsi (
   this is my ident);
   Syslog_h.openlog (ident,
   Syslog_h.Option.Console | 
Syslog_h.Option.Pid |
   Syslog_h.Option.PrintError,
   Syslog_h.Facility.User);
   Syslog_h.syslog ((int) Syslog_h.Facility.User | 
   (int) Syslog_h.Level.Debug,
   Hello, syslog!);
   Syslog_h.closelog ();
   Marshal.FreeHGlobal (ident);
   }
   }

 - Jon


___
Mono-list maillist  -  [EMAIL PROTECTED

RE: [Mono-list] Syslog Access

2004-08-16 Thread Iain McCoy
On Tue, 2004-08-17 at 14:35, Craig Dayton wrote:
 Perhaps exploring the possibility of using PerlNet a product marketed by
 ActiveState might be a cost effective solution.
 
 With PerlNet, one can define an Interface to any module on CPAN and compile
 it as a library or executable.  So from a developer's prospective, a
 programmer can leverage modules in CPAN and the .NET community all within a
 single executable.  Thanks to Mono this capability is now extended to the
 Unix world. No sense in reinventing the wheel is there?  
Is it extended to the unix world? My understanding of PerlNet was that
it worked by interfacing between the regular win32 perl interpreter and
the MS CLR - not by compiling perl code to normal managed code. The MS
CLR interfaces that it would use are not replicated by mono, so I
suspect it doesn't work on a unix.
-- 
Iain McCoy [EMAIL PROTECTED]

___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list