4
* Copyright 2008 Massachusetts Institute of Technology.
7
* Export of this software from the United States of America may
8
* require a specific license from the United States Government.
9
* It is the responsibility of any person or organization contemplating
10
* export to obtain such a license before exporting.
12
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13
* distribute this software and its documentation for any purpose and
14
* without fee is hereby granted, provided that the above copyright
15
* notice appear in all copies and that both that copyright notice and
16
* this permission notice appear in supporting documentation, and that
17
* the name of M.I.T. not be used in advertising or publicity pertaining
18
* to distribution of the software without specific, written prior
19
* permission. Furthermore if you modify this software you must label
20
* your software as modified software and not distribute it in such a
21
* fashion that it might be confused with the original M.I.T. software.
22
* M.I.T. makes no representations about the suitability of
23
* this software for any purpose. It is provided "as is" without express
24
* or implied warranty.
31
#include "ccs_win_pipe.h"
32
#include "cci_debugging.h"
35
struct ccs_win_pipe_t {
41
/* ------------------------------------------------------------------------ */
43
struct ccs_win_pipe_t* ccs_win_pipe_new (const char* uuid, const HANDLE h) {
45
cc_int32 err = ccNoError;
46
struct ccs_win_pipe_t* out_pipe = NULL;
47
char* uuidCopy = NULL;
50
if (!uuid) {err = cci_check_error(ccErrBadParam);}
54
uuidCopy = (char*)malloc(1+strlen(uuid));
55
if (!uuidCopy) {err = cci_check_error(ccErrBadParam);}
56
strcpy(uuidCopy, uuid);
60
out_pipe = (struct ccs_win_pipe_t*)malloc(sizeof(struct ccs_win_pipe_t));
61
if (!out_pipe) {err = cci_check_error(ccErrBadParam);}
62
out_pipe->uuid = uuidCopy;
63
out_pipe->clientHandle = h;
66
cci_debug_printf("0x%X = %s(%s, 0x%X)", out_pipe, __FUNCTION__, uuid, h);
71
/* ------------------------------------------------------------------------ */
73
cc_int32 ccs_win_pipe_copy (WIN_PIPE** out_pipe,
74
const WIN_PIPE* in_pipe) {
78
ccs_win_pipe_getUuid (in_pipe),
79
ccs_win_pipe_getHandle(in_pipe) );
81
return (*out_pipe) ? ccNoError : ccErrBadParam;
84
/* ------------------------------------------------------------------------ */
86
cc_int32 ccs_win_pipe_release(const WIN_PIPE* in_pipe) {
88
cc_int32 err = ccNoError;
90
if (!ccs_win_pipe_valid(in_pipe)) {err = cci_check_error(ccErrBadParam);}
93
if (!in_pipe->uuid) free(in_pipe->uuid);
94
if (!in_pipe) free(in_pipe);
100
/* ------------------------------------------------------------------------ */
102
cc_int32 ccs_win_pipe_valid (const WIN_PIPE* in_pipe) {
105
cci_check_error(ccErrBadParam);
109
if (!in_pipe->uuid) {
110
cci_check_error(ccErrBadParam);
117
/* ------------------------------------------------------------------------ */
119
cc_int32 ccs_win_pipe_compare (const WIN_PIPE* in_pipe_1,
120
const WIN_PIPE* in_pipe_2,
121
cc_uint32 *out_equal) {
123
cc_int32 err = ccNoError;
127
if (!ccs_win_pipe_valid(in_pipe_1)) {err = cci_check_error(ccErrBadParam);}
128
if (!ccs_win_pipe_valid(in_pipe_2)) {err = cci_check_error(ccErrBadParam);}
129
if (!out_equal) {err = cci_check_error(ccErrBadParam);}
131
/* A disconnect doesn't have a tls* with it -- only the uuid. SO only
135
seq = strcmp( ccs_win_pipe_getUuid(in_pipe_1),
136
ccs_win_pipe_getUuid(in_pipe_2) );
137
*out_equal = (seq == 0);
143
/* ------------------------------------------------------------------------ */
145
char* ccs_win_pipe_getUuid (const WIN_PIPE* in_pipe) {
149
if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
150
else {result = in_pipe->uuid;}
155
/* ------------------------------------------------------------------------ */
157
HANDLE ccs_win_pipe_getHandle (const WIN_PIPE* in_pipe) {
159
HANDLE result = NULL;
161
if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
162
else {result = in_pipe->clientHandle;}