~ubuntu-branches/ubuntu/trusty/osptoolkit/trusty

« back to all changes in this revision

Viewing changes to src/ospmsginfo.c

  • Committer: Bazaar Package Importer
  • Author(s): TransNexus, Inc.
  • Date: 2007-12-30 20:37:26 UTC
  • Revision ID: james.westby@ubuntu.com-20071230203726-dysah2e93yqd3vbp
Tags: upstream-3.4.2
ImportĀ upstreamĀ versionĀ 3.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
*** COPYRIGHT (c) 2002 by TransNexus, Inc.                              ***
 
3
***                                                                     ***
 
4
*** This software is property of TransNexus, Inc.                       ***
 
5
*** This software is freely available under license from TransNexus.    ***
 
6
*** The license terms and conditions for free use of this software by   ***
 
7
*** third parties are defined in the OSP Toolkit Software License       ***
 
8
*** Agreement (LICENSE.txt).  Any use of this software by third         ***
 
9
*** parties, which does not comply with the terms and conditions of the ***
 
10
*** OSP Toolkit Software License Agreement is prohibited without        ***
 
11
*** the prior, express, written consent of TransNexus, Inc.             ***
 
12
***                                                                     ***
 
13
*** Thank you for using the OSP ToolKit(TM).  Please report any bugs,   ***
 
14
*** suggestions or feedback to support@transnexus.com                   ***
 
15
***                                                                     ***
 
16
**************************************************************************/
 
17
 
 
18
 
 
19
 
 
20
 
 
21
 
 
22
 
 
23
 
 
24
 
 
25
/*
 
26
 * ospmsginfo.c
 
27
 */
 
28
#include "osp/osp.h"
 
29
#include "osp/ospmsginfo.h"
 
30
 
 
31
static
 
32
int
 
33
osppMsgInfoInitSync(
 
34
    OSPTMSGINFO *ospvMsgInfo)
 
35
{
 
36
    int errorcode = OSPC_ERR_NO_ERROR,
 
37
        tmperror  = OSPC_ERR_NO_ERROR;
 
38
 
 
39
    OSPM_DBGENTER(("ENTER: osppMsgInfoInitSync()\n"));
 
40
    OSPM_MUTEX_INIT(ospvMsgInfo->Mutex, NULL, errorcode);
 
41
    if (errorcode == OSPC_ERR_NO_ERROR)
 
42
    {
 
43
        OSPM_CONDVAR_INIT(ospvMsgInfo->CondVar, NULL, errorcode);
 
44
        if (errorcode != OSPC_ERR_NO_ERROR)
 
45
        {
 
46
            OSPM_MUTEX_DESTROY(ospvMsgInfo->Mutex, tmperror);
 
47
        }
 
48
    }
 
49
    OSPM_DBGEXIT(("EXIT : osppMsgInfoInitSync()\n"));
 
50
    return errorcode;
 
51
}
 
52
 
 
53
int
 
54
OSPPMsgInfoNew(
 
55
    OSPTMSGINFO **ospvMsgInfo)
 
56
{
 
57
    int errorcode = OSPC_ERR_NO_ERROR;
 
58
 
 
59
    OSPM_DBGENTER(("ENTER: OSPPMsgInfoNew()\n"));
 
60
    OSPM_MALLOC(*ospvMsgInfo, OSPTMSGINFO, sizeof(OSPTMSGINFO));
 
61
    if (*ospvMsgInfo != (OSPTMSGINFO *)OSPC_OSNULL)
 
62
    {
 
63
        OSPM_MEMSET(*ospvMsgInfo, 0, sizeof(OSPTMSGINFO));
 
64
 
 
65
        errorcode = osppMsgInfoInitSync(*ospvMsgInfo);
 
66
        if (errorcode != OSPC_ERR_NO_ERROR)
 
67
        {
 
68
            OSPM_FREE(*ospvMsgInfo);
 
69
            *ospvMsgInfo = (OSPTMSGINFO *)OSPC_OSNULL;
 
70
        }
 
71
    }
 
72
    OSPM_DBGEXIT(("EXIT : OSPPMsgInfoNew()\n"));
 
73
    return errorcode;
 
74
}
 
75
 
 
76
void
 
77
OSPPMsgInfoDelete(
 
78
    OSPTMSGINFO **ospvMsgInfo)
 
79
{
 
80
    int errorcode = OSPC_ERR_NO_ERROR;
 
81
 
 
82
    OSPM_DBGENTER(("ENTER: OSPPMsgInfoDelete()\n"));
 
83
    if (*ospvMsgInfo)
 
84
    {
 
85
        if ((*ospvMsgInfo)->ResponseMsg != (unsigned char *)OSPC_OSNULL)
 
86
            OSPM_FREE((*ospvMsgInfo)->ResponseMsg);
 
87
 
 
88
        if ((*ospvMsgInfo)->RequestMsg != (unsigned char *)OSPC_OSNULL)
 
89
            OSPM_FREE((*ospvMsgInfo)->RequestMsg);
 
90
 
 
91
        if ((*ospvMsgInfo)->ContentType != (unsigned char *)OSPC_OSNULL)
 
92
            OSPM_FREE((*ospvMsgInfo)->ContentType);
 
93
 
 
94
 
 
95
        OSPM_MUTEX_DESTROY((*ospvMsgInfo)->Mutex, errorcode);
 
96
 
 
97
        OSPM_CONDVAR_DESTROY((*ospvMsgInfo)->CondVar, errorcode);
 
98
 
 
99
        OSPM_FREE(*ospvMsgInfo);
 
100
        *ospvMsgInfo = (OSPTMSGINFO *)OSPC_OSNULL;
 
101
    }
 
102
    OSPM_DBGEXIT(("EXIT : OSPPMsgInfoDelete()\n"));
 
103
    return;
 
104
}
 
105
 
 
106
void
 
107
OSPPMsgInfoAssignRequestMsg(
 
108
    OSPTMSGINFO   *ospvMsgInfo,
 
109
    unsigned char *ospvRequestMsg,
 
110
    unsigned      ospvRequestSz)
 
111
{
 
112
    OSPM_DBGENTER(("ENTER: OSPPMsgInfoAssignRequestMsg()\n"));
 
113
    if (ospvMsgInfo != (OSPTMSGINFO *)OSPC_OSNULL) 
 
114
    {
 
115
 
 
116
        ospvMsgInfo->RequestMsg = ospvRequestMsg;
 
117
        ospvMsgInfo->RequestSz  = ospvRequestSz;
 
118
    }
 
119
    OSPM_DBGEXIT(("EXIT : OSPPMsgInfoAssignRequestMsg()\n"));
 
120
    return;
 
121
}
 
122
 
 
123
int
 
124
OSPPMsgInfoProcessResponse(
 
125
    OSPTMSGINFO *ospvMsgInfo)
 
126
{
 
127
    int errorcode  = OSPC_ERR_NO_ERROR,
 
128
        tmperrcode = OSPC_ERR_NO_ERROR;
 
129
 
 
130
    OSPM_DBGENTER(("ENTER: OSPPMsgInfoProcessResponse()\n"));
 
131
 
 
132
    if (ospvMsgInfo->IsNonBlocking == OSPC_FALSE)
 
133
    {
 
134
        /* 
 
135
         * once signalled, acquire the mutex for the individual
 
136
         * transaction.
 
137
         */
 
138
        OSPM_MUTEX_LOCK(ospvMsgInfo->Mutex, errorcode);
 
139
        if (errorcode == OSPC_ERR_NO_ERROR)
 
140
        {
 
141
            ospvMsgInfo->HasBeenProcessed = OSPC_TRUE;
 
142
            OSPM_CONDVAR_SIGNAL(ospvMsgInfo->CondVar, errorcode);
 
143
            OSPM_MUTEX_UNLOCK(ospvMsgInfo->Mutex, tmperrcode);
 
144
        }
 
145
    }
 
146
    else
 
147
    {
 
148
        OSPPMsgInfoDelete(&ospvMsgInfo);
 
149
    }
 
150
 
 
151
 
 
152
    OSPM_DBGEXIT(("EXIT : OSPPMsgInfoProcessResponse()\n"));
 
153
    return errorcode;
 
154
}
 
155
 
 
156
int
 
157
OSPPMsgInfoWaitForMsg(
 
158
    OSPTMSGINFO *ospvMsgInfo)
 
159
{
 
160
    int errorcode = OSPC_ERR_NO_ERROR;
 
161
 
 
162
    OSPM_DBGENTER(("ENTER: OSPPMsgInfoWaitForMsg()\n"));
 
163
 
 
164
    OSPM_MUTEX_LOCK(ospvMsgInfo->Mutex, errorcode);
 
165
    if (errorcode == OSPC_ERR_NO_ERROR)
 
166
    {
 
167
       while (ospvMsgInfo->HasBeenProcessed == OSPC_FALSE)
 
168
       {
 
169
           OSPM_CONDVAR_WAIT(ospvMsgInfo->CondVar, ospvMsgInfo->Mutex,
 
170
                    errorcode);
 
171
       }
 
172
 
 
173
            OSPM_MUTEX_UNLOCK(ospvMsgInfo->Mutex, errorcode);
 
174
    }
 
175
    OSPM_DBGEXIT(("EXIT : OSPPMsgInfoWaitForMsg()\n"));
 
176
    return errorcode;
 
177
}