I've included my first (very rough) attempt at a POSIX wrapper. This is
more of an exploratory prototype than anything else. Its highly
unlikely that you'll find that it works correctly, let alone useful.
Regardless I wanted to get Paulo and the rest of the list's feelings on
it.
Issues:
o No test suite yet. I'm not sure if I should just test whether the
functions are invoked properly (they return and the runtime doesn't
crash) or some sanity checks on the output should be included. I
presume we're going to rely on the host vendor to make sure the
P/Invoked functions do the write thing. I have included a quick hack at
what they might look at based on TemplateTest.cs.
o Things like uid_t, pid_t, time_t, etc. are aliased to System.Int32.
It's my understanding that these are usually kernel specific items.
Should we attempt to generate a file that defines these properly on a
per-platform basis?
o Should said types be thrown into a separate PosixTypes.cs file?
o Is the implementation of utsname and tms the right way to go when a
function returns a struct? Since classes are reference types, I presume
the caller can pass in an object to be filled in, just as a C caller
would do.
o Should all the directly-mapped POSIX functions be thrown into one
POSIX.POSIX class or should they be broken out as I've started to do
here?
o The only place I could find info on what is in POSIX and what's not is
http://j4p.sourceforge.net/. I checked the POSIX man page and it has
stuff like cos and asin which I wouldn't think are in the POSIX
standards. So, I need some canonical source from which I can determine
which functions to include.
I think that pretty much covers my thoughts at the time.
Looking forward to feedback,
--
AKK~
http://trmk.org/~adam/blog
//
// Posix.cs
//
// Author:
// Adam Keys ([EMAIL PROTECTED])
//
// (C) 2002 Adam Keys
//
using System.Runtime.InteropServices;
namespace POSIX {
class POSIX {
[DllImport ("libc.so.6", EntryPoint="getpid")]
public static extern int getpid();
[DllImport ("libc.so.6", EntryPoint="getppid")]
public static extern int getppid();
[DllImport ("libc.so.6", EntryPoint="chown")]
public static extern int chown (string path, int owner, int group);
[DllImport ("libc.so.6", EntryPoint="execv")]
public static extern int execv (string path, string[] argv);
}
}
// this is a template for making NUnit tests. Text enclosed in square
// brackets (and the brackets themselves) should be replaced by appropiate
// code.
// PosixProcessTest.cs - NUnit Test Cases for PosixProcess
//
// Adam Keys ([EMAIL PROTECTED])
//
// (C) Adam K. Keys
//
// these are the standard namespaces you will need. You may need to add more
// depending on your tests.
using NUnit.Framework;
using System;
using Posix;
// all test namespaces start with "MonoTests." Append the Namespace that
// contains the class you are testing, e.g. MonoTests.System.Collections
namespace MonoTests.[Namespace]
{
// the class name should end with "Test" and start with the name of the class
// you are testing, e.g. CollectionBaseTest
public class PosixProcessTest : TestCase {
// there should be two constructors for your class. The first one
// (without parameters) should set the name to something unique.
// Of course the name of the method is the same as the name of the
// class
public PosixProcessTest() : base ("POSIX.POSIX") {}
public PosixProcessTest(string name) : base(name) {}
// this method is run before each Test* method is called. You can put
// variable initialization, etc. here that is common to each test.
// Just leave the method empty if you don't need to use it.
protected override void SetUp() {}
// this method is run after each Test* method is called. You can put
// clean-up code, etc. here. Whatever needs to be done after each test.
// Just leave the method empty if you don't need to use it.
protected override void TearDown() {}
// this property is required. You need change the parameter for
// typeof() below to be your class.
public static ITest Suite {
get {
return new TestSuite(typeof(PosixProcessTest));
}
}
// this is just one of probably many test methods in your test class.
// each test method must start with "Test". All methods in your class
// which start with "Test" will be automagically called by the NUnit
// framework.
public void Test_getpid() {
int res;
res = POSIX.getpid();
Assert(res > 0);
}
}