28f5d848de5b66593fc69e4b5d09582f6ea9a61d
[sfrench/samba-autobuild/.git] / source4 / lib / com / classes / simple.c
1 /*
2    Unix SMB/CIFS implementation.
3    Simple class
4    Copyright (C) 2004-2005 Jelmer Vernooij <jelmer@samba.org>
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22 #include "lib/com/com.h"
23 #include "librpc/gen_ndr/com_dcom.h"
24
25 NTSTATUS com_simple_init(TALLOC_CTX *);
26
27 static struct IClassFactory_vtable simple_classobject_vtable;
28 static struct IStream_vtable simple_IStream_vtable;
29
30 static WERROR simple_IUnknown_QueryInterface (struct IUnknown *d, TALLOC_CTX *mem_ctx, struct GUID *iid, struct IUnknown **iun)
31 {
32         *iun = d;
33         return WERR_OK;
34 }
35
36 static uint32_t simple_IUnknown_AddRef (struct IUnknown *d, TALLOC_CTX *mem_ctx)
37 {
38         return 1;
39 }
40
41 static uint32_t simple_IUnknown_Release (struct IUnknown *d, TALLOC_CTX *mem_ctx)
42 {
43         return 1;
44 }
45
46 static WERROR simple_IStream_Read (struct IStream *d, TALLOC_CTX *mem_ctx, uint8_t *pv, uint32_t num_requested, uint32_t *num_readx, uint32_t num_read)
47 {
48         printf("%d bytes are being read\n", num_read);
49         return WERR_OK;
50 }
51
52 static WERROR simple_IStream_Write (struct IStream *d, TALLOC_CTX *mem_ctx, uint8_t *data, uint32_t num_requested, uint32_t num_written)
53 {
54         printf("%d bytes are being written\n", num_requested);
55         return WERR_OK;
56 }
57
58 static WERROR simpleclass_IUnknown_QueryInterface (struct IUnknown *d, TALLOC_CTX *mem_ctx, struct GUID *iid, struct IUnknown **iun)
59 {
60         /* FIXME: Return WERR_IFACE_NOT_SUPPORTED if IID != IID_IUNKNOWN and IID != IID_CLASSFACTORY */
61         *iun = d;
62         return WERR_OK;
63 }
64
65 static WERROR simpleclass_IClassFactory_CreateInstance (struct IClassFactory *d, TALLOC_CTX *mem_ctx, struct IUnknown *iunk, struct GUID *iid, struct IUnknown **ppv)
66 {
67         struct IStream *ret;
68         /* FIXME: Check whether IID == ISTREAM_IID */
69         ret = talloc(mem_ctx, struct IStream);
70         ret->ctx = NULL;
71         ret->vtable = &simple_IStream_vtable;
72         ret->object_data = NULL;
73
74         *ppv = (struct IUnknown *)ret;
75         
76         return WERR_OK;
77 }
78
79 static uint32_t simpleclass_IUnknown_AddRef (struct IUnknown *d, TALLOC_CTX *mem_ctx)
80 {
81         return 1;
82 }
83
84 static uint32_t simpleclass_IUnknown_Release (struct IUnknown *d, TALLOC_CTX *mem_ctx)
85 {
86         return 1;
87 }
88
89 /* Everything below this line should be autogenerated later on */
90 static struct IClassFactory_vtable simple_classobject_vtable = {
91         { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
92         simpleclass_IUnknown_QueryInterface, 
93         simpleclass_IUnknown_AddRef, 
94         simpleclass_IUnknown_Release,
95         simpleclass_IClassFactory_CreateInstance,
96         NULL,
97         NULL,
98         NULL
99 };
100
101 static struct IStream_vtable simple_IStream_vtable = {
102         { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
103         simple_IUnknown_QueryInterface,
104         simple_IUnknown_AddRef, 
105         simple_IUnknown_Release,
106         simple_IStream_Read,
107         simple_IStream_Write
108 };
109
110 NTSTATUS com_simple_init(TALLOC_CTX *ctx)
111 {
112         struct GUID clsid;
113         struct IUnknown *class_object = talloc(talloc_autofree_context(), struct IUnknown);
114
115         class_object->ctx = NULL;
116         class_object->object_data = NULL;
117         class_object->vtable = (struct IUnknown_vtable *)&simple_classobject_vtable;
118
119         GUID_from_string(CLSID_SIMPLE, &clsid);
120         GUID_from_string(COM_ICLASSFACTORY_UUID, &simple_classobject_vtable.iid);
121         GUID_from_string(COM_ISTREAM_UUID, &simple_IStream_vtable.iid);
122
123         return com_register_running_class(&clsid, PROGID_SIMPLE, class_object);
124 }