source: branches/samba-3.5.x/source4/lib/com/classes/simple.c

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 3.7 KB
Line 
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
25static struct IClassFactory_vtable simple_classobject_vtable;
26static struct IStream_vtable simple_IStream_vtable;
27
28static WERROR simple_IUnknown_QueryInterface (struct IUnknown *d, TALLOC_CTX *mem_ctx, struct GUID *iid, struct IUnknown **iun)
29{
30 *iun = d;
31 return WERR_OK;
32}
33
34static uint32_t simple_IUnknown_AddRef (struct IUnknown *d, TALLOC_CTX *mem_ctx)
35{
36 return 1;
37}
38
39static uint32_t simple_IUnknown_Release (struct IUnknown *d, TALLOC_CTX *mem_ctx)
40{
41 return 1;
42}
43
44static 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)
45{
46 printf("%d bytes are being read\n", num_read);
47 return WERR_OK;
48}
49
50static WERROR simple_IStream_Write (struct IStream *d, TALLOC_CTX *mem_ctx, uint8_t *data, uint32_t num_requested, uint32_t num_written)
51{
52 printf("%d bytes are being written\n", num_requested);
53 return WERR_OK;
54}
55
56static WERROR simpleclass_IUnknown_QueryInterface (struct IUnknown *d, TALLOC_CTX *mem_ctx, struct GUID *iid, struct IUnknown **iun)
57{
58 /* FIXME: Return WERR_IFACE_NOT_SUPPORTED if IID != IID_IUNKNOWN and IID != IID_CLASSFACTORY */
59 *iun = d;
60 return WERR_OK;
61}
62
63static WERROR simpleclass_IClassFactory_CreateInstance (struct IClassFactory *d, TALLOC_CTX *mem_ctx, struct IUnknown *iunk, struct GUID *iid, struct IUnknown **ppv)
64{
65 struct IStream *ret;
66 /* FIXME: Check whether IID == ISTREAM_IID */
67 ret = talloc(mem_ctx, struct IStream);
68 ret->ctx = NULL;
69 ret->vtable = &simple_IStream_vtable;
70 ret->object_data = NULL;
71
72 *ppv = (struct IUnknown *)ret;
73
74 return WERR_OK;
75}
76
77static uint32_t simpleclass_IUnknown_AddRef (struct IUnknown *d, TALLOC_CTX *mem_ctx)
78{
79 return 1;
80}
81
82static uint32_t simpleclass_IUnknown_Release (struct IUnknown *d, TALLOC_CTX *mem_ctx)
83{
84 return 1;
85}
86
87/* Everything below this line should be autogenerated later on */
88static struct IClassFactory_vtable simple_classobject_vtable = {
89 { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
90 simpleclass_IUnknown_QueryInterface,
91 simpleclass_IUnknown_AddRef,
92 simpleclass_IUnknown_Release,
93 simpleclass_IClassFactory_CreateInstance,
94 NULL,
95 NULL,
96 NULL
97};
98
99static struct IStream_vtable simple_IStream_vtable = {
100 { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
101 simple_IUnknown_QueryInterface,
102 simple_IUnknown_AddRef,
103 simple_IUnknown_Release,
104 simple_IStream_Read,
105 simple_IStream_Write
106};
107
108NTSTATUS com_simple_init(void)
109{
110 struct GUID clsid;
111 struct IUnknown *class_object = talloc(talloc_autofree_context(), struct IUnknown);
112
113 class_object->ctx = NULL;
114 class_object->object_data = NULL;
115 class_object->vtable = (struct IUnknown_vtable *)&simple_classobject_vtable;
116
117 GUID_from_string(CLSID_SIMPLE, &clsid);
118 GUID_from_string(COM_ICLASSFACTORY_UUID, &simple_classobject_vtable.iid);
119 GUID_from_string(COM_ISTREAM_UUID, &simple_IStream_vtable.iid);
120
121 return com_register_running_class(&clsid, PROGID_SIMPLE, class_object);
122}
Note: See TracBrowser for help on using the repository browser.