1 /* ccapi/server/win/ccs_win_pipe.c */
3 * Copyright 2008 Massachusetts Institute of Technology.
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
30 #include "ccs_win_pipe.h"
31 #include "cci_debugging.h"
34 struct ccs_win_pipe_t {
40 /* ------------------------------------------------------------------------ */
42 struct ccs_win_pipe_t* ccs_win_pipe_new (const char* uuid, const UINT64 h) {
44 cc_int32 err = ccNoError;
45 struct ccs_win_pipe_t* out_pipe = NULL;
46 char* uuidCopy = NULL;
49 if (!uuid) {err = cci_check_error(ccErrBadParam);}
53 uuidCopy = (char*)malloc(1+strlen(uuid));
54 if (!uuidCopy) {err = cci_check_error(ccErrBadParam);}
55 strcpy(uuidCopy, uuid);
59 out_pipe = (struct ccs_win_pipe_t*)malloc(sizeof(struct ccs_win_pipe_t));
60 if (!out_pipe) {err = cci_check_error(ccErrBadParam);}
61 out_pipe->uuid = uuidCopy;
62 out_pipe->clientHandle = h;
65 cci_debug_printf("0x%X = %s(%s, 0x%X)", out_pipe, __FUNCTION__, uuid, h);
70 /* ------------------------------------------------------------------------ */
72 cc_int32 ccs_win_pipe_copy (WIN_PIPE** out_pipe,
73 const WIN_PIPE* in_pipe) {
77 ccs_win_pipe_getUuid (in_pipe),
78 ccs_win_pipe_getHandle(in_pipe) );
80 return (*out_pipe) ? ccNoError : ccErrBadParam;
83 /* ------------------------------------------------------------------------ */
85 cc_int32 ccs_win_pipe_release(const WIN_PIPE* in_pipe) {
87 cc_int32 err = ccNoError;
89 if (!ccs_win_pipe_valid(in_pipe)) {err = cci_check_error(ccErrBadParam);}
92 if (!in_pipe->uuid) free(in_pipe->uuid);
93 if (!in_pipe) free(in_pipe);
99 /* ------------------------------------------------------------------------ */
101 cc_int32 ccs_win_pipe_valid (const WIN_PIPE* in_pipe) {
104 cci_check_error(ccErrBadParam);
108 if (!in_pipe->uuid) {
109 cci_check_error(ccErrBadParam);
116 /* ------------------------------------------------------------------------ */
118 cc_int32 ccs_win_pipe_compare (const WIN_PIPE* in_pipe_1,
119 const WIN_PIPE* in_pipe_2,
120 cc_uint32 *out_equal) {
122 cc_int32 err = ccNoError;
126 if (!ccs_win_pipe_valid(in_pipe_1)) {err = cci_check_error(ccErrBadParam);}
127 if (!ccs_win_pipe_valid(in_pipe_2)) {err = cci_check_error(ccErrBadParam);}
128 if (!out_equal) {err = cci_check_error(ccErrBadParam);}
130 /* A disconnect doesn't have a tls* with it -- only the uuid. SO only
134 seq = strcmp( ccs_win_pipe_getUuid(in_pipe_1),
135 ccs_win_pipe_getUuid(in_pipe_2) );
136 *out_equal = (seq == 0);
142 /* ------------------------------------------------------------------------ */
144 char* ccs_win_pipe_getUuid (const WIN_PIPE* in_pipe) {
148 if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
149 else {result = in_pipe->uuid;}
154 /* ------------------------------------------------------------------------ */
156 UINT64 ccs_win_pipe_getHandle (const WIN_PIPE* in_pipe) {
160 if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
161 else {result = in_pipe->clientHandle;}