ctdbAddResource
Add a new resource to a table.
DECLARATION
CTDBRET ctdbDECL ctdbAddResource(CTHANDLE resource, cpVOID data, VRLEN size);
DESCRIPTION
ctdbAddResource() add a new resource to a table. When adding a Resource to a table, a special variable-length record is written to the table, containing the information from the Resource Data Block. This is done even if a data file uses fixed-length records. Every Resource is identified by a unique combination of a Resource Type and a Resource Number. The Resource Number can optionally be assigned by FairCom DB during the call to ctdbAddResource(). In addition, each Resource can be identified by a Resource Name. The Resource Name is not guaranteed to be unique.
The Resource Type must be a value greater than 65536. 0 through 65536 are reserved for FairCom use. If the Resource Number is a value of CTDB_ASSIGN_RESOURCE_NUMBER (0xffffffff), FairCom DB assigns this Resource the next available Resource Number for this Resource Type in the specified data file. The assigned number can be retrieved by calling ctdbGetResourceNumber() before the resource handle is released. The Resource Name is optional. Names starting with "FC!" or "RD!", are reserved for FairCom use.
Resource is a handle allocated by ctdbAllocResource(). Data is any collection of data that you wish to store as a Resource. It can be a character string, a structure, or any variable type. Size indicates the number of bytes occupied by data.
RETURN
ctdbAddResource() returns CTDBRET_OK on success.
EXAMPLE
/* return CTDB_ASSIGN_RESOURCE_NUMBER on error */
ULONG AddMyResource(CTHANDLE Handle, ULONG type, pTEXT name, cpVOID data, VRLEN size)
{
ULONG number = CTDB_ASSIGN_RESOURCE_NUMBER;
CTHANDLE hRes = ctdbAllocResource(Handle, type, number, name);
CTDBRET eRet;
/* check if resource handle was allocated */
if (!hRes)
{
printf("ctdbAllocResource failed with error %d\n", ctdbGetError(Handle));
return number;
}
/* Add the resource */
if ((eRet = ctdbAddResource(hRes, data, size)) != CTDBRET_OK)
{
printf("ctdbAddResource failed with error %d\n", eRet);
ctdbFreeResource(hRes);
return eRet;
}
/* retrieve the assigned resource number */
number = ctdbGetResourceNumber(hRes);
/* release the resource handle */
ctdbFreeResource(hRes);
return number;
}
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbAllocResource
Allocates a new resource handle.
DECLARATION
CTHANDLE ctdbDECL ctdbAllocResource(CTHANDLE Handle, ULONG type, ULONG number, cpTEXT name);
DESCRIPTION
Allocate a new resource handle. Before any operations can be performed on resources, you are required to allocate a resource handle. Resource handles are opaque handles whose contents are not available to the developer. You must use the set of functions provided by FairCom DB API to set and get properties and to perform operations.
- Handle is a FairCom DB API table handle.
- type is the resource type. If the resource type is unknown you may set this parameter to zero.
- number is the resource number. If the resource number is unknown you may set this parameter to zero.
- name is the resource name. If you do not know this value in advance, you can set this parameter with a NULL or empty string ("").
RETURN
ctdbAllocResource() returns the resource handle on success. Returns NULL if ctdbAllocResource() fails to allocate handle, in which case you should call ctdbGetError() passing the table Handle to obtain the error code.
EXAMPLE
CTDBRET DisplayAllResources(CTHANDLE hTable)
{
CTDBRET eRet;
CTHANDLE hRes = ctdbAllocResource(hTable, 0, 0, NULL);
/* check if resource was allocated */
if (!hRes)
return ctdbGetError(hTable);
/* get the first resource */
/* note that no resource locks are acquired since we are not changing the resources */
if ((eRet = ctdbFirstResource(hRes, false)) != CTDBRET_OK)
{
ctdbFreeResource(hRes);
return eRet;
}
/* get the other resources */
do
{
/* display resource type, number and name */
printf("Resource type: %u, number: %u", ctdbGetResourceType(hRes), ctdbGetResourceNumber(hRes));
if (ctdbGetResourceName(hRes) != NULL)
printf(", name: \"\"\n", ctdbGetResourceName(hRes));
else
printf(", name: NULL"\n");
}
while ((eRet = ctdbNextResource(hRes, false)) != CTDBRET_OK);
ctdbFreeResource(hRes);
return eRet;
}
SEE ALSO
ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbDeleteResource
Delete an existing resource from a table.
DECLARATION
CTDBRET ctdbDECL ctdbDeleteResource(CTHANDLE resource);
DESCRIPTION
ctdbDeleteResource() delete a resource from a table. Before a resource can be deleted, the table must be opened exclusive. The resource type and resource number that identify this resource must be passed to ctdbAllocResource(). Resource is a handle allocated by ctdbAllocResource().
RETURN
ctdbDeleteResource() returns CTDBRET_OK on success
EXAMPLE
/* delete a resource */
CTDBRET DelMyResource(CTHANDLE Handle, ULONG type, ULONG number, pTEXT name)
{
CTDBRET Retval;
CTHANDLE hRes = ctdbAllocResource(Handle, type, number, name);
if (hRes)
{
if ((Retval = ctdbDeleteResource(hRes)) != CTDBRET_OK)
printf("ctdbDeleteResource failed with error %d\n", Retval);
ctdbFreeResource(hRes);
}
else
{
printf("Failed to allocate resource handle\n");
Retval = CTDBRET_NOMEMORY;
}
return Retval;
}
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUpdateResource(), ctdbUnlockResource()
ctdbFindResource
Locate and retrieve a resource by type and number.
Declaration
CTDBRET ctdbDECL ctdbFindResource(CTHANDLE resource, ULONG type, ULONG number, CTBOOL lock)
Description
ctdbFindResource() locates and retrieves a resource in a table based on type and number. resource is a handle allocated with ctdbAllocHandle(). type and number identify the resource and lock is used to indicate if the resource should be locked, if it is found.
Return
ctdbFindResource() returns CTDBRET_OK on success. If the specified resource is not in the table, ctdbFindResource() returns RNOT_ERR (408).
Example
/* display a particular resource */
CTDBRET DisplayResource(CTHANDLE hTable, ULONG type, ULONG number)
{
CTDBRET eRet;
CTHANDLE hRes = ctdbAllocResource(hTable, 0, 0, NULL);
/* check if resource was allocated */
if (!hRes)
return ctdbGetError(hTable);
/* note that no resource locks are acquired since we are not changing the resources */
if ((eRet = ctdbFindResource(hRes, type, number, NO)) == CTDBRET_OK)
{
printf("Resource type: %u, number: %u", ctdbGetResourceType(hRes), ctdbGetResourceNumber(hRes));
if (ctdbGetResourceName(hRes) != NULL)
printf(", name: \"\"\n", ctdbGetResourceName(hRes));
else
printf(", name: NULL"\n");
}
ctdbFreeResource(hRes);
return eRet;
}
See also
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbFirstResource(), ctdbNextResource(), ctdbDeleteResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUpdateResource(), ctdbUnlockResource()
ctdbFindResourceByName
Locate and retrieve a resource by name.
Declaration
CTDBRET ctdbDECL ctdbFindResourceByName(CTHANDLE resource, pTEXT name, CTBOOL lock);
Description
ctdbFindResourceByName() locates and retrieves a resource by name. FairCom DB cannot guarantee unique resource names. resource is a handle allocated with ctdbAllocHandle(). name is the resource name and lock is used to indicate if the resource should locked, if it is found.
Return
ctdbFindResourceByName() returns CTDBRET_OK on success. If there are no resources for the table with the specified name, ctdbFindResourceByName() returns RNOT_ERR (408).
Example
/* display a particular resource */
CTDBRET DisplayResource(CTHANDLE hTable, pTEXT name)
{
CTDBRET eRet;
CTHANDLE hRes = ctdbAllocResource(hTable, 0, 0, NULL);
/* check if resource was allocated */
if (!hRes)
return ctdbGetError(hTable);
/* note that no resource locks are acquired since we are not changing the resources */
if ((eRet = ctdbFindResourceByName(hRes, name, NO)) == CTDBRET_OK)
{
printf("Resource type: %u, number: %u", ctdbGetResourceType(hRes), ctdbGetResourceNumber(hRes));
if (ctdbGetResourceName(hRes) != NULL)
printf(", name: \"\"\n", ctdbGetResourceName(hRes));
else
printf(", name: NULL"\n");
}
ctdbFreeResource(hRes);
return eRet;
}
See Also
ctdbAllocResource, ctdbFreeResource, ctdbAddResource, ctdbDeleteResource, ctdbUpdateResource, ctdbFirstResource, ctdbNextResource, ctdbFindResource, ctdbGetResourceType, ctdbSetResourceType, ctdbGetResourceNumber, ctdbSetResourceNumber, ctdbGetResourceName, ctdbSetResourceName, ctdbGetResourceDataLength, ctdbGetResourceData, ctdbSetResourceData, ctdbIsResourceLocked, ctdbUnlockResource
ctdbFirstResource (see Initialization)
ctdbFreeResource
Release memory and system resources allocated by ctdbAllocResource().
DECLARATION
CTDBRET ctdbDECL ctdbFreeResource(CTHANDLE resource)
DESCRIPTION
Release system resources allocated by ctdbAllocResource().
- resource is a resource handle allocated by ctdbAllocResource().
RETURN
ctdbFreeResource() returns CTDBRET_OK on success or CTDBRET_NOTRESOURCE error if the handle passed to ctdbFreeResource() was not allocated by ctdbAllocResource() or is invalid.
EXAMPLE
CTDBRET DisplayAllResources(CTHANDLE hTable)
{
CTDBRET eRet;
CTHANDLE hRes = ctdbAllocResource(hTable, 0, 0, NULL);
/* check if resource was allocated */
if (!hRes)
return ctdbGetError(hTable);
/* get the first resource */
/* note that no resource locks are acquired since we are not changing the resources */
if ((eRet = ctdbFirstResource(hRes, false)) != CTDBRET_OK)
{
ctdbFreeResource(hRes);
return eRet;
}
/* get the other resources */
do
{
/* display resource type, number and name */
printf("Resource type: %u, number: %u", ctdbGetResourceType(hRes), ctdbGetResourceNumber(hRes));
if (ctdbGetResourceName(hRes) != NULL)
printf(", name: \"\"\n", ctdbGetResourceName(hRes));
else
printf(", name: NULL"\n");
}
while ((eRet = ctdbNextResource(hRes, false)) != CTDBRET_OK);
ctdbFreeResource(hRes);
return eRet;
}
SEE ALSO
ctdbFirstResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbAllocResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbGetResourceData
Return a pointer to the resource data.
DECLARATION
pVOID ctdbDECL ctdbGetResourceData(CTHANDLE resource);
DESCRIPTION
Returns a pointer to the resource data. Call this function to retrieve the resource data pointer after a resource is read by one of ctdbFirstResource(), ctdbNextResource(), ctdbFindResource() or ctdbFindResourceByName().
- resource is a handle returned by ctdbAllocResource().
RETURN
Return a pointer to resource data
EXAMPLE
CTDBRET ReadMyResource(CTHANDLE Handle, ULONG type, ULONG number, ppVOID data, pVRLEN size)
{
CTDBRET eRet;
CTHANDLE hRes = ctdbAllocResource(Handle, type, number, NULL);
/* check the resource handle allocation */
if (hRes == NULL)
{
eRet = ctdbGetError(Handle);
goto Exit;
}
/* get the resource */
if ((eRet = ctdbFindResource(hRes, type, number, NO)) != CTDBRET_OK)
goto Exit;
/* allocate a buffer large enough for the resource data */
*size = ctdbGetResourceDataLength(hRes);
if (*size > 0)
{
*data = (pVOID)malloc(*size);
if (*data == NULL)
{
eRet = CTDBRET_NOMEMORY;
goto Exit;
}
memcpy(*data, ctdbGetResourceData(hRes), *size);
}
Exit:
if (hRes)
ctdbFreeResource(hRes);
return eRet;
}
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbGetResourceDataLength
Retrieves the resource data length.
DECLARATION
VRLEN ctdbDECL ctdbGetResourceDataLength(CTHANDLE resource);
DESCRIPTION
Retrieves the resource data length as the number of bytes occupied by the resource data.
- resource is a handle allocated by ctdbAllocResource().
RETURN
EXAMPLE
CTDBRET ReadMyResource(CTHANDLE Handle, ULONG type, ULONG number, ppVOID data, pVRLEN size)
{
CTDBRET eRet;
CTHANDLE hRes = ctdbAllocResource(Handle, type, number, NULL);
/* check the resource handle allocation */
if (hRes == NULL)
{
eRet = ctdbGetError(Handle);
goto Exit;
}
/* get the resource */
if ((eRet = ctdbFindResource(hRes, type, number, NO)) != CTDBRET_OK)
goto Exit;
/* allocate a buffer large enough for the resource data */
*size = ctdbGetResourceDataLength(hRes);
if (*size > 0)
{
*data = (pVOID)malloc(*size);
if (*data == NULL)
{
eRet = CTDBRET_NOMEMORY;
goto Exit;
}
memcpy(*data, ctdbGetResourceData(hRes), *size);
}
Exit:
if (hRes)
ctdbFreeResource(hRes);
return eRet;
}
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbUpdateResource(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbGetResourceName
Retrieve the resource name.
DECLARATION
pTEXT ctdbDECL ctdbGetResourceName(CTHANDLE resource);
DESCRIPTION
Retrieve the resource name. A NULL value may be returned to indicate that the resource name was not set.
RETURN
Returns a pointer to the resource name
EXAMPLE
if (ctdbGetResourceName(hRes) == NULL)
ctdbSetResourceName(hRes, "MyResource");
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbUpdateResource(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbGetResourceNumber
Retrieve the resource number.
DECLARATION
ULONG ctdbDECL ctdbGetResourceNumber(CTHANDLE resource);
DESCRIPTION
Retrieves the resource number. resource is a handle allocated by ctdbAllocResource().
RETURN
Return the resource number
EXAMPLE
if (ctdbGetResourceNumber(hRes) != number)
ctdbSetResourceNumber(hRes, number);
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbUpdateResource(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbGetResourceType
Retrieve the resource type.
DECLARATION
ULONG ctdbDECL ctdbGetResourceType(CTHANDLE resource);
DESCRIPTION
Retrieve the resource type. resource is a handle allocated by ctdbAllocResource().
RETURN
Returns the resource type.
EXAMPLE
if (ctdbGetResourceType(hRes) != type)
ctdbSetResourceType(hRes, type);
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbUpdateResource(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbIsResourceLocked
Indicate if a resource is locked.
DECLARATION
CTBOOL ctdbDECL ctdbIsResourceLocked(CTHANDLE resource);
DESCRIPTION
Retrieve indication if the resource is locked. resource is a handle allocated by ctdbAllocResource().
RETURN
Returns YES if resource is locked, or NO if resource is not locked.
EXAMPLE
if (ctdbIsResourceLocked(hRes))
ctdbUnlockResource(hRes);
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbNextResource
Locate and retrieve the next resource in a table.
Declaration
CTDBRET ctdbDECL ctdbNextResource(CTHANDLE resource, CTBOOL lock)
Description
ctdbNextResource() retrieve the next resource stored in a table. The resource parameter is a handle allocated with ctdbAllocHandle(). lock is used to indicate if the resource should be locked, if it is found. To retrieve all of the resources stored in a table, call ctdbNextResource() and then call this function until it returns RNOT_ERR (408). To retrieve all the resources stored in a table starting from a given resource type and number, allocate a resource handle, set the resource type and a resource number, and then call this function until it returns RNOT_ERR (408).
Return
ctdbNextResource() returns CTDBRET_OK on success. After the last resource has been retrieved from the table, ctdbNextResource() returns RNOT_ERR (408).
Example
/* read resources with type >= type and number > 0 */
CTDBRET DisplayResources(CTHANDLE hTable, ULONG type)
{
CTDBRET eRet;
CTHANDLE hRes = ctdbAllocResource(hTable, type, 0, NULL);
/* check if resource was allocated */
if (!hRes)
return ctdbGetError(hTable);
/* note that no resource locks are acquired since we are not changing the resources */
while ((eRet = ctdbNextResource(hRes)) == CTDBRET_OK)
{
/* display resource type, number and name */
printf("Resource type: %u, number: %u", ctdbGetResourceType(hRes), ctdbGetResourceNumber(hRes));
if (ctdbGetResourceName(hRes) != NULL)
printf(", name: \"\"\n", ctdbGetResourceName(hRes));
else
printf(", name: NULL"\n");
}
ctdbFreeResource(hRes);
return eRet;
}
See Also
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceType(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbSetResourceData
Set the resource data.
DECLARATION
CTDBRET ctdbDECL ctdbSetResourceData(CTHANDLE resource, cpVOID data, VRLEN size);
DESCRIPTION
Set the resource data. The internal resource buffer is resized and the resource data is copied. If the resource data parameter is NULL, the internal resource data buffer is released.
- resource is a handle allocated with ctdbAllocHandle().
- data is a pointer to resource data. If data is NULL the internal resource data buffer is cleared. size indicate the number of bytes pointed by data.
RETURN
ctdbSetResourceData() return CTDBRET_OK on success.
EXAMPLE
CTDBRET ReadMyResource(CTHANDLE Handle, ULONG type, ULONG number, ppVOID data, pVRLEN size)
{
CTDBRET eRet;
CTHANDLE hRes = ctdbAllocResource(Handle, type, number, NULL);
/* check the resource handle allocation */
if (hRes == NULL)
{
eRet = ctdbGetError(Handle);
goto Exit;
}
/* get the resource */
if ((eRet = ctdbFindResource(hRes, type, number, NO)) != CTDBRET_OK)
goto Exit;
/* allocate a buffer large enough for the resource data */
*size = ctdbGetResourceDataLength(hRes);
if (*size > 0)
{
*data = (pVOID)malloc(*size);
if (*data == NULL)
{
eRet = CTDBRET_NOMEMORY;
goto Exit;
}
memcpy(*data, ctdbGetResourceData(hRes), *size);
}
Exit:
if (hRes)
ctdbFreeResource(hRes);
return eRet;
}
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceType(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbSetResourceNumber
Set a resource number.
DECLARATION
CTDBRET ctdbDECL ctdbSetResourceNumber(CTHANDLE resource, ULONG number);
DESCRIPTION
Sets a resource number.
- resource is a handle allocated by ctdbAllocResource().
- number is a resource number value.
RETURN
ctdbSetResourceNumber() returns CTDBRET_OK on success.
EXAMPLE
if (ctdbGetResourceNumber(hRes) != number)
ctdbSetResourceNumber(hRes, number);
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceType(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbSetResourceType
Set the resource type.
DECLARATION
CTDBRET ctdbDECL ctdbSetResourceType(CTHANDLE resource, ULONG type);
DESCRIPTION
Set the resource type. resource is a handle allocated by ctdbAllocResource() and type is a number representing the resource type.
RETURN
ctdbSetResourceType() returns CTDBRET_OK on success.
EXAMPLE
if (ctdbGetResourceType(hRes) != type)
ctdbSetResourceType(hRes, type);
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()
ctdbUnlockResource
Release any locks held by resource.
DECLARATION
CTDBRET ctdbDECL ctdbUnlockResource(CTHANDLE resource);
DESCRIPTION
Unlocks a resource. The resource is only unlocked if it was previously locked by ctdbFirstResource(), ctdbNextResource(), ctdbFindResource() or ctdbFindResourceByName().
- resource is a handle allocated by ctdbAllocHandle().
RETURN
ctdbUlnlockResource() returns CTDBRET_OK on success.
EXAMPLE
if (ctdbIsResourceLocked(hRes))
ctdbUnlockResource(hRes);
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), Locking
ctdbUpdateResource
Update the contents of an existing resource.
DECLARATION
CTDBRET ctdbDECL ctdbUpdateResource(CTHANDLE resource, cpVOID data, VRLEN size);
DESCRIPTION
ctdbUpdateResource() update an existing resource. You must call ctdbAllocResource() with specific resource type and number that will uniquely identify the resource being updated. resource is a handle allocated by ctdbAllocResource(). The Resource data is any collection of data that you wish to store as a Resource. It can be a character string, a structure, or any variable type. size indicate the number of bytes occupied by data.
RETURN
ctdbUpdateResource() returns CTDBRET_OK on success.
EXAMPLE
CTDBRET UpdateMyResource(CTHANDLE Handle, ULONG type, ULONG number, pTEXT name, pVOID data, VRLEN size)
{
CTDBRET Retval;
CTHANDLE hRes = ctdbAllocResource(Handle, type, number, name);
if (hRes)
{
if ((Retval = ctdbUpdateResource(hRes, data, size)) != CTDBRET_OK)
printf("ctdbUpdateResource failed with error %d\n", Retval);
ctdbFreeResource(hRes);
}
else
{
printf("Failed to allocate resource handle\n");
Retval = CTDBRET_NOMEMORY;
}
return Retval;
}
SEE ALSO
ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource(), Locking