• Main Page
  • Modules
  • Data Structures
  • Files
  • File List

D:/Perso/dev/ocilib/ocilib/src/agent.c

00001 /*
00002     +-----------------------------------------------------------------------------------------+
00003     |                                                                                         |
00004     |                               OCILIB - C Driver for Oracle                              |
00005     |                                                                                         |
00006     |                                (C Wrapper for Oracle OCI)                               |
00007     |                                                                                         |
00008     |                              Website : http://www.ocilib.net                            |
00009     |                                                                                         |
00010     |             Copyright (c) 2007-2010 Vincent ROGIER <vince.rogier@ocilib.net>            |
00011     |                                                                                         |
00012     +-----------------------------------------------------------------------------------------+
00013     |                                                                                         |
00014     |             This library is free software; you can redistribute it and/or               |
00015     |             modify it under the terms of the GNU Lesser General Public                  |
00016     |             License as published by the Free Software Foundation; either                |
00017     |             version 2 of the License, or (at your option) any later version.            |
00018     |                                                                                         |
00019     |             This library is distributed in the hope that it will be useful,             |
00020     |             but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00021     |             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           |
00022     |             Lesser General Public License for more details.                             |
00023     |                                                                                         |
00024     |             You should have received a copy of the GNU Lesser General Public            |
00025     |             License along with this library; if not, write to the Free                  |
00026     |             Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.          |
00027     |                                                                                         |
00028     +-----------------------------------------------------------------------------------------+
00029 */
00030 
00031 /* --------------------------------------------------------------------------------------------- *
00032  * $Id: agent.c, v 3.8.1 2010-12-13 00:00 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ********************************************************************************************* *
00038  *                             PRIVATE FUNCTIONS
00039  * ********************************************************************************************* */
00040 
00041 /* --------------------------------------------------------------------------------------------- *
00042  * OCI_AgentInit
00043  * --------------------------------------------------------------------------------------------- */
00044 
00045 OCI_Agent * OCI_AgentInit
00046 (
00047     OCI_Connection *con,
00048     OCI_Agent     **pagent,
00049     OCIAQAgent     *handle,
00050     const mtext    *name,
00051     const mtext    *address
00052 )
00053 {
00054     OCI_Agent *agent = NULL;
00055     boolean res      = TRUE;
00056 
00057     OCI_CHECK(pagent == NULL, NULL);
00058 
00059     /* allocate agent structure */
00060 
00061     if (*pagent == NULL)
00062         *pagent = (OCI_Agent *) OCI_MemAlloc(OCI_IPC_AGENT, sizeof(*agent),
00063                                              (size_t) 1, TRUE);
00064 
00065     if (*pagent != NULL)
00066     {
00067         agent = *pagent;
00068 
00069         /* reinit */
00070 
00071         OCI_FREE(agent->name);
00072         OCI_FREE(agent->address);
00073 
00074         agent->con    = con;
00075         agent->handle = handle;
00076 
00077         if (handle == NULL)
00078         {
00079             agent->hstate = OCI_OBJECT_ALLOCATED;
00080 
00081             res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid * ) OCILib.env,
00082                                                       (dvoid **) &agent->handle,
00083                                                       OCI_DTYPE_AQAGENT,
00084                                                       (size_t) 0, (dvoid **) NULL));
00085         }
00086         else
00087             agent->hstate = OCI_OBJECT_FETCHED_CLEAN;
00088 
00089         /* set name attribute if provided */
00090 
00091         if ((res == TRUE) && (name != NULL) && (name[0] != 0))
00092         {
00093             res = OCI_AgentSetName(agent, name);
00094         }
00095 
00096         /* set address attribute if provided */
00097 
00098         if ((res == TRUE) && (address != NULL) && (address[0] != 0))
00099         {
00100             res = OCI_AgentSetAddress(agent, address);
00101         }
00102     }
00103     else
00104         res = FALSE;
00105 
00106     /* check for failure */
00107 
00108     if (res == FALSE)
00109     {
00110         OCI_AgentFree(agent);
00111         agent = NULL;
00112     }
00113 
00114     return agent;
00115 }
00116 
00117 /* ********************************************************************************************* *
00118  *                            PUBLIC FUNCTIONS
00119  * ********************************************************************************************* */
00120 
00121 /* --------------------------------------------------------------------------------------------- *
00122  * OCI_AgentCreate
00123  * --------------------------------------------------------------------------------------------- */
00124 
00125 OCI_Agent * OCI_API OCI_AgentCreate
00126 (
00127     OCI_Connection *con,
00128     const mtext    *name,
00129     const mtext    *address
00130 )
00131 {
00132     OCI_Agent *agent = NULL;
00133 
00134     OCI_CHECK_INITIALIZED(NULL);
00135 
00136     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
00137 
00138     agent = OCI_AgentInit(con, &agent, NULL, name, address);
00139 
00140     OCI_RESULT(agent != NULL);
00141 
00142     return agent;
00143 }
00144 
00145 /* --------------------------------------------------------------------------------------------- *
00146  * OCI_AgentFree
00147  * --------------------------------------------------------------------------------------------- */
00148 
00149 boolean OCI_API OCI_AgentFree
00150 (
00151     OCI_Agent *agent
00152 )
00153 {
00154     boolean res = TRUE;
00155 
00156     OCI_CHECK_PTR(OCI_IPC_AGENT, agent, FALSE);
00157 
00158     if (agent->hstate == OCI_OBJECT_ALLOCATED)
00159     {
00160         OCI_DescriptorFree((dvoid *) agent->handle, OCI_DTYPE_AQAGENT);
00161     }
00162 
00163     OCI_FREE(agent->address);
00164     OCI_FREE(agent->name);
00165 
00166     OCI_FREE(agent);
00167 
00168     OCI_RESULT(res);
00169 
00170     return res;
00171 }
00172 
00173 /* --------------------------------------------------------------------------------------------- *
00174  * OCI_AgentGetName
00175  * --------------------------------------------------------------------------------------------- */
00176 
00177 const mtext * OCI_API OCI_AgentGetName
00178 (
00179     OCI_Agent *agent
00180 )
00181 {
00182     boolean res = TRUE;
00183 
00184     OCI_CHECK_PTR(OCI_IPC_AGENT, agent, NULL);
00185 
00186     if (agent->name == NULL)
00187     {
00188         res = OCI_StringGetFromAttrHandle(agent->con,
00189                                           agent->handle,
00190                                           OCI_DTYPE_AQAGENT,
00191                                           OCI_ATTR_AGENT_NAME,
00192                                           &agent->name);
00193     }
00194 
00195     OCI_RESULT(res);
00196 
00197     return agent->name;
00198 }
00199 
00200 /* --------------------------------------------------------------------------------------------- *
00201  * OCI_AgentSetName
00202  * --------------------------------------------------------------------------------------------- */
00203 
00204 boolean OCI_API OCI_AgentSetName
00205 (
00206     OCI_Agent   *agent,
00207     const mtext *name
00208 )
00209 {
00210     boolean res = TRUE;
00211 
00212     OCI_CHECK_PTR(OCI_IPC_AGENT, agent, FALSE);
00213 
00214     res =  OCI_StringSetToAttrHandle(agent->con, agent->handle,
00215                                      OCI_DTYPE_AQAGENT, OCI_ATTR_AGENT_NAME,
00216                                      &agent->name, name);
00217 
00218     OCI_RESULT(res);
00219 
00220     return res;
00221 }
00222 
00223 /* --------------------------------------------------------------------------------------------- *
00224  * OCI_AgentGetAddress
00225  * --------------------------------------------------------------------------------------------- */
00226 
00227 const mtext * OCI_API OCI_AgentGetAddress
00228 (
00229     OCI_Agent *agent
00230 )
00231 {
00232     boolean res = TRUE;
00233 
00234     OCI_CHECK_PTR(OCI_IPC_AGENT, agent, NULL);
00235 
00236     if (agent->name == NULL)
00237     {
00238         res = OCI_StringGetFromAttrHandle(agent->con,
00239                                           agent->handle,
00240                                           OCI_DTYPE_AQAGENT,
00241                                           OCI_ATTR_AGENT_ADDRESS,
00242                                           &agent->address);
00243     }
00244 
00245     OCI_RESULT(res);
00246 
00247     return agent->address;
00248 }
00249 
00250 /* --------------------------------------------------------------------------------------------- *
00251  * OCI_AgentSetAddress
00252  * --------------------------------------------------------------------------------------------- */
00253 
00254 boolean OCI_API OCI_AgentSetAddress
00255 (
00256     OCI_Agent   *agent,
00257     const mtext *address
00258 )
00259 {
00260     boolean res = TRUE;
00261 
00262     OCI_CHECK_PTR(OCI_IPC_AGENT, agent, FALSE);
00263 
00264     res = OCI_StringSetToAttrHandle(agent->con, agent->handle,
00265                                     OCI_DTYPE_AQAGENT, OCI_ATTR_AGENT_ADDRESS,
00266                                     &agent->address, address);
00267 
00268     OCI_RESULT(res);
00269 
00270     return res;
00271 }

Generated on Mon Dec 13 2010 22:32:01 for OCILIB (C Driver for Oracle) by  doxygen 1.7.2