From 983d6f7f310ef567f3d4af87d19d69d5ccbf11d9 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Tue, 7 May 2013 02:42:36 -0600 Subject: [PATCH] added some extra interfaces for heap support, and the code structures defined in the IDL files necessitated some refinements to the PIDL parser and code generator --- idl/comrogue/allocator.idl | 23 ++++ idl/comrogue/connpoint.idl | 105 +++++++++++++++++++ idl/comrogue/object_types.idl | 12 +++ idl/comrogue/stream.idl | 74 +++++++++++++ include/comrogue/object_definition_macros.h | 7 +- include/comrogue/types.h | 1 + kernel/lib/lib_guids.c | 2 + tools/pidl/lib/Parse/Pidl/COMROGUE/Header.pm | 43 ++++++-- tools/pidl/lib/Parse/Pidl/Typelist.pm | 16 ++- 9 files changed, 271 insertions(+), 12 deletions(-) create mode 100644 idl/comrogue/connpoint.idl create mode 100644 idl/comrogue/stream.idl diff --git a/idl/comrogue/allocator.idl b/idl/comrogue/allocator.idl index e138c6f..4dcb637 100644 --- a/idl/comrogue/allocator.idl +++ b/idl/comrogue/allocator.idl @@ -17,3 +17,26 @@ interface IMalloc : IUnknown void HeapMinimize(void); } +/*---------------------- + * IMallocSpy interface + *---------------------- + */ + +[object, uuid(0000001d-0000-0000-C000-000000000046)] +interface IMallocSpy: IUnknown +{ + [unique] typedef IMallocSpy *PMALLOCSPY; + + SIZE_T PreAlloc([in] SIZE_T cbRequest); + PVOID PostAlloc([in] PVOID pActual); + PVOID PreFree([in] PVOID pRequest, [in] BOOL fSpyed); + void PostFree([in] BOOL fSpyed); + SIZE_T PreRealloc([in] PVOID pRequest, [in] SIZE_T cbRequest, [out] PVOID *ppNewRequest, [in] BOOL fSpyed); + PVOID PostRealloc([in] PVOID pActual, [in] BOOL fSpyed); + PVOID PreGetSize([in] PVOID pRequest, [in] BOOL fSpyed); + SIZE_T PostGetSize([in] SIZE_T cbActual, [in] BOOL fSpyed); + PVOID PreDidAlloc([in] PVOID pRequest, [in] BOOL fSpyed); + INT32 PostDidAlloc([in] PVOID pRequest, [in] BOOL fSpyed, [in] INT32 fActual); + void PreHeapMinimize(void); + void PostHeapMinimize(void); +} diff --git a/idl/comrogue/connpoint.idl b/idl/comrogue/connpoint.idl new file mode 100644 index 0000000..2c75e6a --- /dev/null +++ b/idl/comrogue/connpoint.idl @@ -0,0 +1,105 @@ +/* + * This file is part of the COMROGUE Operating System for Raspberry Pi + * + * Copyright (c) 2013, Eric J. Bowersox / Erbosoft Enterprises + * All rights reserved. + * + * This program is free for commercial and non-commercial use as long as the following conditions are + * adhered to. + * + * Copyright in this file remains Eric J. Bowersox and/or Erbosoft, and as such any copyright notices + * in the code are not to be removed. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * "Raspberry Pi" is a trademark of the Raspberry Pi Foundation. + */ +import "comrogue/object_types.idl"; +import "comrogue/objectbase.idl"; + +/*---------------------------- + * IEnumConnections interface + *---------------------------- + */ + +[object, uuid(B196B287-BAB4-101A-B69C-00AA00341D07), pointer_default(unique)] +interface IEnumConnections: IUnknown +{ + typedef IEnumConnections *PENUMCONNECTIONS; + + typedef struct tagCONNECTDATA { + IUnknown *pUnk; + UINT32 uiCookie; + } CONNECTDATA; + + typedef CONNECTDATA *PCONNECTDATA; + + HRESULT Next([in] UINT32 cConnections, [out, size_is(cConnections), length_is(*pcFetched)] PCONNECTDATA rgcd, + [out] UINT32 *pcFetched); + HRESULT Skip([in] UINT32 cConnections); + HRESULT Reset(void); + HRESULT Clone([out] IEnumConnections **ppEnum); +} + +/*---------------------------- + * IConnectionPoint interface + *---------------------------- + */ + +[object, uuid(B196B286-BAB4-101A-B69C-00AA00341D07), pointer_default(unique)] +interface IConnectionPoint: IUnknown +{ + typedef IConnectionPoint *PCONNECTIONPOINT; + + HRESULT GetConnectionInterface([out] IID *pIID); + HRESULT GetConnectionPointContainer([out] IConnectionPointContainer **ppCPC); + HRESULT Advise([in] IUnknown *punkSink, [out] UINT32 *puiCookie); + HRESULT Unadvise([in] UINT32 uiCookie); + HRESULT EnumConnections([out] IEnumConnections **ppEnum); +} + +/*--------------------------------- + * IEnumConnectionPoints interface + *--------------------------------- + */ + +[object, uuid(B196B285-BAB4-101A-B69C-00AA00341D07), pointer_default(unique)] +interface IEnumConnectionPoints: IUnknown +{ + typedef IEnumConnectionPoints *PENUMCONNECTIONPOINTS; + + HRESULT Next([in] UINT32 cConnections, [out, size_is(cConnections), length_is(*pcFetched)] PCONNECTIONPOINT *ppCP, + [out] UINT32 *pcFetched); + HRESULT Skip([in] UINT32 cConnections); + HRESULT Reset(void); + HRESULT Clone([out] IEnumConnectionPoints **ppEnum); +} + +/*------------------------------------- + * IConnectionPointContainer interface + *------------------------------------- + */ + +[object, uuid(B196B284-BAB4-101A-B69C-00AA00341D07), pointer_default(unique)] +interface IConnectionPointContainer: IUnknown +{ + typedef IConnectionPointContainer *PCONNECTIONPOINTCONTAINER; + + HRESULT EnumConnectionPoints([out] IEnumConnectionPoints **ppEnum); + HRESULT FindConnectionPoint([in] REFIID riid, [out] IConnectionPoint **ppCP); +} diff --git a/idl/comrogue/object_types.idl b/idl/comrogue/object_types.idl index 7d5ef6d..786ac15 100644 --- a/idl/comrogue/object_types.idl +++ b/idl/comrogue/object_types.idl @@ -69,12 +69,16 @@ interface ICOMROGUETypes typedef char CHAR; typedef uint8 UCHAR; typedef uint8 BYTE; + typedef wchar_t WCHAR; typedef CHAR *PCHAR; typedef const CHAR *PCCHAR; typedef UCHAR *PUCHAR; + typedef WCHAR *PWCHAR; [string] typedef CHAR *PSTR; [string] typedef const CHAR *PCSTR; + [string] typedef WCHAR *PWSTR; + [string] typedef const WCHAR *PCWSTR; /* Boolean type */ typedef int BOOL; @@ -83,6 +87,14 @@ interface ICOMROGUETypes typedef UINT32 SCODE; typedef SCODE HRESULT; + /* FILETIME typedef */ + typedef struct tagFILETIME + { + UINT32 uiLowDateTime; + UINT32 uiHighDateTime; + } FILETIME; + typedef FILETIME *PFILETIME; + /* GUID typedefs */ typedef struct tagGUID { UINT32 Data1; diff --git a/idl/comrogue/stream.idl b/idl/comrogue/stream.idl new file mode 100644 index 0000000..feb8ab0 --- /dev/null +++ b/idl/comrogue/stream.idl @@ -0,0 +1,74 @@ +import "comrogue/object_types.idl"; +import "comrogue/objectbase.idl"; + +/*----------------------------- + * ISequentialStream interface + *----------------------------- + */ + +[object, uuid(0c733a30-2a1c-11ce-ade5-00aa0044773d), pointer_default(unique)] +interface ISequentialStream: IUnknown +{ + typedef ISequentialStream *PSEQUENTIALSTREAM; + + HRESULT Read([out, size_is(cb), length_is(*pcbRead)] PVOID pv, [in] UINT32 cb, [out] UINT32 *pcbRead); + HRESULT Write([in, length_is(cb)] PCVOID pv, [in] UINT32 cb, [out] UINT32 *pcbWritten); +} + +/*------------------- + * IStream interface + *------------------- + */ + +[object, uuid(0000000c-0000-0000-C000-000000000046), pointer_default(unique)] +interface IStream: ISequentialStream +{ + typedef IStream *PSTREAM; + + typedef struct tagSTATSTG + { + PWSTR pwcsName; + UINT32 type; + UINT64 cbSize; + FILETIME mtime; + FILETIME ctime; + FILETIME atime; + UINT32 grfMode; + UINT32 grfLocksSupported; + CLSID clsid; + UINT32 grfStateBits; + UINT32 reserved; + } STATSTG; + + typedef enum tagSTGTY + { + STGTY_STORAGE = 1, + STGTY_STREAM = 2, + STGTY_LOCKBYTES = 3, + STGTY_PROPERTY = 4 + } STGTY; + + typedef enum tagSTREAM_SEEK + { + STREAM_SEEK_SET = 0, + STREAM_SEEK_CUR = 1, + STREAM_SEEK_END = 2 + } STREAM_SEEK; + + typedef enum tagLOCKTYPE + { + LOCK_WRITE = 1, + LOCK_EXCLUSIVE = 2, + LOCK_ONLYONCE = 4 + } LOCKTYPE; + + HRESULT Seek([in] INT64 dlibMove, [in] UINT32 uiOrigin, [out] UINT64 *plibNewPosition); + HRESULT SetSize([in] UINT64 libNewSize); + HRESULT CopyTo([in, unique] IStream *pstm, [in] UINT64 cb, [out] UINT64 *pcbRead, [out] UINT64 *pcbWritten); + HRESULT Commit([in] UINT32 grfCommitFlags); + HRESULT Revert(void); + HRESULT LockRegion([in] UINT64 libOffset, [in] UINT64 cb, [in] UINT32 uiLockType); + HRESULT UnlockRegion([in] UINT64 libOffset, [in] UINT64 cb, [in] UINT32 uiLockType); + HRESULT Stat([out] STATSTG *pstatstg, [in] UINT32 grfStatFlag); + HRESULT Clone([out] IStream **ppstm); +} diff --git a/include/comrogue/object_definition_macros.h b/include/comrogue/object_definition_macros.h index fb955f1..ce8ffd3 100644 --- a/include/comrogue/object_definition_macros.h +++ b/include/comrogue/object_definition_macros.h @@ -91,9 +91,10 @@ #define END_METHODS #define INHERIT_METHODS(sym) sym -#define BEGIN_INTERFACE(typ) \ +#define DECLARE_INTERFACE(typ) \ struct typ ## VTable; \ - typedef interface tagIf ## typ { const struct typ ## VTable *pVTable; } typ; \ + typedef interface tagIf ## typ { const struct typ ## VTable *pVTable; } typ; +#define BEGIN_INTERFACE(typ) \ struct typ ## VTable { #define BEGIN_INTERFACE_(typ, parent) BEGIN_INTERFACE(typ) #define END_INTERFACE(typ) }; @@ -108,6 +109,8 @@ #define END_METHODS #define INHERIT_METHODS(sym) +#define DECLARE_INTERFACE(typ) \ + interface typ; #define BEGIN_INTERFACE(typ) \ interface typ { #define BEGIN_INTERFACE_(typ, parent) \ diff --git a/include/comrogue/types.h b/include/comrogue/types.h index 30061a0..b9f84fc 100644 --- a/include/comrogue/types.h +++ b/include/comrogue/types.h @@ -78,6 +78,7 @@ typedef int int32_t; typedef unsigned int uint32_t; typedef long long int64_t; typedef unsigned long long uint64_t; +typedef unsigned short wchar_t; #include diff --git a/kernel/lib/lib_guids.c b/kernel/lib/lib_guids.c index 716c7c3..d9cd2d4 100644 --- a/kernel/lib/lib_guids.c +++ b/kernel/lib/lib_guids.c @@ -47,4 +47,6 @@ */ #include #include +#include +#include #include diff --git a/tools/pidl/lib/Parse/Pidl/COMROGUE/Header.pm b/tools/pidl/lib/Parse/Pidl/COMROGUE/Header.pm index caf4055..aceb9b4 100644 --- a/tools/pidl/lib/Parse/Pidl/COMROGUE/Header.pm +++ b/tools/pidl/lib/Parse/Pidl/COMROGUE/Header.pm @@ -4,7 +4,7 @@ package Parse::Pidl::COMROGUE::Header; -use Parse::Pidl::Typelist qw(mapTypeName maybeMapScalarType is_struct); +use Parse::Pidl::Typelist qw(mapTypeName maybeMapScalarType is_struct is_enum); use Parse::Pidl::Util qw(has_property is_constant); use vars qw($VERSION); @@ -140,7 +140,13 @@ sub ParseElement($$) my $element = shift; my $res = ""; - $res .= $prefix . maybeMapScalarType($element->{TYPE}) . " " . $element->{NAME}; + $res .= $prefix . maybeMapScalarType($element->{TYPE}) . " "; + my $l = $element->{POINTERS}; + $l-- if (Parse::Pidl::Typelist::scalar_is_reference($element->{TYPE})); + foreach my $i (1..$l) { + $res .= "*"; + } + $res .= $element->{NAME}; if (defined($element->{ARRAY_LEN})) { foreach my $l (@{$element->{ARRAY_LEN}}) { $res .= "[" . $l . "]"; @@ -166,6 +172,15 @@ sub ParseTypedef($) $res .= ParseElement("\t", $elt); } $res .= "} "; + } elsif (is_enum($def->{DATA})) { + $res .= mapTypeName($def->{DATA}) . " {"; + my $first = 1; + foreach my $elt (@{$def->{DATA}->{ELEMENTS}}) { + $res .= "," if $first == 0; + $first = 0; + $res .= "\n\t" . $elt; + } + $res .= "\n} "; } else { $res .= mapTypeName($def->{DATA}) . " "; } @@ -208,8 +223,12 @@ sub ParseInterface($) $res .= " *---------------------------------------------------------------\n"; $res .= " */\n\n"; + foreach $d (@{$if->{DATA}}) { + $res .= stripquotes($d->{DATA}) . "\n" if ($d->{TYPE} eq "CPP_QUOTE"); + $res .= ParseTypedef($d) if ($d->{TYPE} eq "TYPEDEF"); + } + $res .= MakeGUIDDef("IID", $if->{NAME}, $if->{PROPERTIES}->{uuid}); - $res .= MethodsDefinition($if); if (defined($if->{BASE})) { @@ -220,11 +239,6 @@ sub ParseInterface($) $res .= "\tMETHODS_" . $if->{NAME} . "\n"; $res .= "END_INTERFACE(" . $if->{NAME} . ")\n\n"; - foreach $d (@{$if->{DATA}}) { - $res .= stripquotes($d->{DATA}) . "\n" if ($d->{TYPE} eq "CPP_QUOTE"); - $res .= ParseTypedef($d) if ($d->{TYPE} eq "TYPEDEF"); - } - $res .= "\n#ifdef CINTERFACE\n\n"; foreach $d (@{$if->{DATA}}) { @@ -277,6 +291,19 @@ sub Parse($$$) "#ifndef __ASM__\n\n"; my $want_macro_headers = 1; + foreach (@{$idl}) + { + next unless ($_->{TYPE} eq "INTERFACE"); + next unless (has_property($_, "object")); + if ($want_macro_headers) { + $res .= "#include \n\n"; + $want_macro_headers = 0; + } + $res .= "DECLARE_INTERFACE(" . $_->{NAME} . ")\n"; + } + + $res .= "\n"; + foreach (@{$idl}) { if ($_->{TYPE} eq "CPP_QUOTE") { diff --git a/tools/pidl/lib/Parse/Pidl/Typelist.pm b/tools/pidl/lib/Parse/Pidl/Typelist.pm index 569924b..1f5a151 100644 --- a/tools/pidl/lib/Parse/Pidl/Typelist.pm +++ b/tools/pidl/lib/Parse/Pidl/Typelist.pm @@ -8,8 +8,8 @@ package Parse::Pidl::Typelist; require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(hasType getType resolveType mapTypeName scalar_is_reference expandAlias - mapScalarType maybeMapScalarType addType typeIs is_signed is_scalar is_struct enum_type_fn - bitmap_type_fn mapType typeHasBody is_fixed_size_scalar + mapScalarType maybeMapScalarType addType typeIs is_signed is_scalar is_struct is_enum + enum_type_fn bitmap_type_fn mapType typeHasBody is_fixed_size_scalar ); use vars qw($VERSION); $VERSION = '0.01'; @@ -34,6 +34,7 @@ my @non_fixed_size_scalars = ( my %scalars = ( "void" => "void", "char" => "char", + "wchar_t" => "wchar_t", "int8" => "int8_t", "uint8" => "uint8_t", "int16" => "int16_t", @@ -215,6 +216,17 @@ sub is_struct($) return 0; } +sub is_enum($) +{ + my $type = shift; + return 1 if (ref($type) eq "HASH" and $type->{TYPE} eq "ENUM"); + if (my $dt = getType($type)) { + return is_enum($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF"); + return 1 if ($dt->{TYPE} eq "ENUM"); + } + return 0; +} + sub is_fixed_size_scalar($) { my $name = shift;