本文整理汇总了C++中OICCalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ OICCalloc函数的具体用法?C++ OICCalloc怎么用?C++ OICCalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OICCalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OICCalloc
ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
ProvStatus provStatus) {
ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
if (provInfo == NULL) {
OIC_LOG_V(ERROR, TAG, "Failed to allocate memory");
return NULL;
}
OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr));
if (devAddr == NULL) {
OIC_LOG_V(ERROR, TAG, "Failed to allocate memory");
return NULL;
}
strncpy(devAddr->addr, clientResponse->addr->addr, sizeof(devAddr->addr));
devAddr->port = clientResponse->addr->port;
provInfo->provDeviceInfo.addr = devAddr;
provInfo->provStatus = provStatus;
return provInfo;
}
示例2: CATimeoutCallback
static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uint32_t size)
{
OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint");
VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
CAEndpoint_t* ep = CACloneEndpoint(endpoint);
if (!ep)
{
OIC_LOG(ERROR, TAG, "clone failed");
return;
}
CAResponseInfo_t* resInfo = (CAResponseInfo_t*)OICCalloc(1, sizeof(CAResponseInfo_t));
if (!resInfo)
{
OIC_LOG(ERROR, TAG, "calloc failed");
CAFreeEndpoint(ep);
return;
}
resInfo->result = CA_RETRANSMIT_TIMEOUT;
resInfo->info.type = CAGetMessageTypeFromPduBinaryData(pdu, size);
resInfo->info.messageId = CAGetMessageIdFromPduBinaryData(pdu, size);
CAResult_t res = CAGetTokenFromPDU((const coap_hdr_t *) pdu, &(resInfo->info));
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "fail to get Token from retransmission list");
CADestroyResponseInfoInternal(resInfo);
CAFreeEndpoint(ep);
return;
}
CAData_t *cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
if (NULL == cadata)
{
OIC_LOG(ERROR, TAG, "memory allocation failed !");
CAFreeEndpoint(ep);
CADestroyResponseInfoInternal(resInfo);
return;
}
cadata->type = SEND_TYPE_UNICAST;
cadata->remoteEndpoint = ep;
cadata->requestInfo = NULL;
cadata->responseInfo = resInfo;
#ifdef SINGLE_THREAD
CAProcessReceivedData(cadata);
#else
CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
#endif
OIC_LOG(DEBUG, TAG, "OUT");
}
示例3: FindStringLLInMap
static CborError FindStringLLInMap(const CborValue *linksMap, char *tag, OCStringLL **links)
{
size_t len;
CborError cborFindResult;
CborValue rtArray;
cborFindResult = cbor_value_map_find_value(linksMap, tag, &rtArray);
if (CborNoError != cborFindResult)
{
return CborUnknownError;
}
CborValue rtVal;
cborFindResult = cbor_value_enter_container(&rtArray, &rtVal);
if (CborNoError != cborFindResult)
{
return CborUnknownError;
}
OCStringLL* llPtr = *links;
while (cbor_value_is_text_string(&rtVal))
{
if (llPtr == NULL)
{
llPtr = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
if (!llPtr)
{
return CborUnknownError;
}
*links = llPtr;
}
else if(llPtr)
{
while (llPtr->next)
{
llPtr = llPtr->next;
}
llPtr->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
if (!llPtr->next)
{
return CborUnknownError;
}
}
cborFindResult = cbor_value_dup_text_string(&rtVal, &(llPtr->value), &len, NULL);
if (CborNoError != cborFindResult)
{
return CborUnknownError;
}
cborFindResult = cbor_value_advance(&rtVal);
if (CborNoError != cborFindResult)
{
return CborUnknownError;
}
}
cborFindResult = cbor_value_leave_container(&rtArray, &rtVal);
return cborFindResult;
}
示例4: SetPlatformInfo
OCStackResult SetPlatformInfo()
{
static const OCPlatformInfo platformInfo =
{
.platformID = "IoTivityZigbeeID",
.manufacturerName = "IoTivity",
.manufacturerUrl = "http://iotivity.org",
.modelNumber = "T1000",
.dateOfManufacture = "January 14th, 2015",
.platformVersion = "0.9.2",
.operatingSystemVersion = "7",
.hardwareVersion = "0.5",
.firmwareVersion = "0",
.supportUrl = "http://iotivity.org",
.systemTime = ""
};
return OCSetPlatformInfo(platformInfo);
}
OCStackResult SetDeviceInfo()
{
static OCDeviceInfo deviceInfo =
{
.deviceName = "IoTivity/Zigbee Server Sample",
.specVersion = "IoTivity/Zigbee Device Spec Version",
};
char *dmv = OICStrdup("IoTivity/Zigbee Data Model Version");
deviceInfo.dataModelVersions = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
deviceInfo.dataModelVersions->value = dmv;
char *dup = OICStrdup("oic.wk.d");
deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
deviceInfo.types->value = dup;
return OCSetDeviceInfo(deviceInfo);
}
bool processSignal(bool set)
{
static sig_atomic_t signal = 0;
if (set)
{
signal = 1;
}
return signal == 1;
}
void processCancel(int signal)
{
if(signal == SIGINT)
{
processSignal(true);
}
}
示例5: createPdAcl
static OicSecPdAcl_t* createPdAcl(const int dev_num)
{
if(0>=dev_num || g_own_cnt<dev_num)
{
OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
return NULL; // not need to 'goto' |ERROR| before allocating |acl|
}
// allocate memory for |pdacl| struct
printf(" **** Create PDACL for the Selected Device[%d]\n", dev_num);
OicSecPdAcl_t* pdAcl = (OicSecPdAcl_t*) OICCalloc(1, sizeof(OicSecPdAcl_t));
if(!pdAcl)
{
OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
return NULL; // not need to 'goto' |ERROR| before allocating |acl|
}
// number of resources
char rsrc_in[][ACL_RESRC_MAX_LEN+1] = {"*", "/rsrc/*"};
pdAcl->resourcesLen = 1;
// resource
int num = pdAcl->resourcesLen;
pdAcl->resources = (char**) OICCalloc(num, sizeof(char*));
if(!pdAcl->resources)
{
OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
goto CRPDACL_ERROR;
}
for(int i=0; num>i; ++i)
{
size_t len = strlen(rsrc_in[i])+1; // '1' for null termination
char* rsrc = (char*) OICCalloc(len, sizeof(char));
if(!rsrc)
{
OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
goto CRPDACL_ERROR;
}
OICStrcpy(rsrc, len, rsrc_in[i]);
pdAcl->resources[i] = rsrc; // after here, |rsrc| points nothing
}
// permission
pdAcl->permission = PERMISSION_FULL_CONTROL;
return pdAcl;
CRPDACL_ERROR:
OCDeletePdAclList(pdAcl);
return NULL;
}
示例6: OCStringLLJoin
static char* OCStringLLJoin(OCStringLL* val)
{
OCStringLL* temp = val;
size_t size = strlen(temp->value);
while (temp->next)
{
++size;
temp = temp->next;
size += strlen(temp->value);
}
char* joinedStr = (char*)OICCalloc(sizeof(char), size + 1);
if (!joinedStr)
{
return NULL;
}
OICStrcat(joinedStr, size + 1, val->value);
while (val->next)
{
val = val->next;
OICStrcat(joinedStr, size + 1, " ");
OICStrcat(joinedStr, size + 1, val->value);
}
return joinedStr;
}
示例7: ConvertUuidToStr
OCStackResult ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid)
{
if(NULL == uuid || NULL == strUuid || NULL != *strUuid)
{
OIC_LOG(ERROR, TAG, "ConvertUuidToStr : Invalid param");
return OC_STACK_INVALID_PARAM;
}
size_t uuidIdx = 0;
size_t urnIdx = 0;
const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1;
char* convertedUrn = (char*)OICCalloc(urnBufSize, sizeof(char));
VERIFY_NON_NULL(TAG, convertedUrn, ERROR);
for(uuidIdx=0, urnIdx=0; uuidIdx < UUID_LENGTH && urnIdx < urnBufSize; uuidIdx++, urnIdx+=2)
{
// canonical format for UUID has '8-4-4-4-12'
if(uuidIdx==4 || uuidIdx==6 || uuidIdx==8 || uuidIdx==10)
{
snprintf(convertedUrn + urnIdx, 2, "%c", '-');
urnIdx++;
}
snprintf(convertedUrn + urnIdx, 3, "%02x", (uint8_t)(uuid->id[uuidIdx]));
}
convertedUrn[urnBufSize - 1] = '\0';
*strUuid = convertedUrn;
return OC_STACK_OK;
exit:
return OC_STACK_NO_MEMORY;
}
示例8: CATimeoutCallback
static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uint32_t size)
{
OIC_LOG(DEBUG, TAG, "IN");
CAEndpoint_t* ep = CACloneEndpoint(endpoint);
if (NULL == ep)
{
OIC_LOG(ERROR, TAG, "clone failed");
return;
}
CAResponseInfo_t* resInfo = (CAResponseInfo_t*) OICCalloc(1, sizeof(CAResponseInfo_t));
if (NULL == resInfo)
{
OIC_LOG(ERROR, TAG, "calloc failed");
CAFreeEndpoint(ep);
return;
}
resInfo->result = CA_RETRANSMIT_TIMEOUT;
resInfo->info.type = CAGetMessageTypeFromPduBinaryData(pdu, size);
resInfo->info.messageId = CAGetMessageIdFromPduBinaryData(pdu, size);
if (g_responseHandler)
{
g_responseHandler(ep, resInfo);
}
CAFreeEndpoint(ep);
OICFree(resInfo);
OIC_LOG(DEBUG, TAG, "OUT");
}
示例9: CADetachResponseMessage
CAResult_t CADetachResponseMessage(const CAEndpoint_t *object,
const CAResponseInfo_t *response)
{
OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL(object, TAG, "object");
VERIFY_NON_NULL(response, TAG, "response");
// allocate & initialize
CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
CA_MEMORY_ALLOC_CHECK(data);
// save data
data->type = SEND_TYPE_UNICAST;
data->remoteEndpoint = object;
data->requestInfo = NULL;
data->responseInfo = response;
CAProcessData(data);
OICFree(data);
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
// memory error label.
memory_error_exit:
OICFree(data);
OIC_LOG(DEBUG, TAG, "OUT");
return CA_MEMORY_ALLOC_FAILED;
}
示例10: CADetachRequestMessage
CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInfo_t *request)
{
OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL(object, TAG, "object");
VERIFY_NON_NULL(request, TAG, "request");
// If max retransmission queue is reached, then don't handle new request
if (CA_MAX_RT_ARRAY_SIZE == u_arraylist_length(g_retransmissionContext.dataList))
{
OIC_LOG(ERROR, TAG, "max RT queue size reached!");
return CA_SEND_FAILED;
}
// allocate & initialize
CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
CA_MEMORY_ALLOC_CHECK(data);
// save data
data->type = request->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
data->remoteEndpoint = object;
data->requestInfo = request;
data->responseInfo = NULL;
CAProcessData(data);
OICFree(data);
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
// memory error label.
memory_error_exit:
OICFree(data);
OIC_LOG(DEBUG, TAG, "OUT");
return CA_MEMORY_ALLOC_FAILED;
}
示例11: VERIFY_NON_NULL_RET
CATCPData *CACreateTCPData(const CAEndpoint_t *remoteEndpoint, const void *data,
size_t dataLength, bool isMulticast)
{
VERIFY_NON_NULL_RET(remoteEndpoint, TAG, "remoteEndpoint is NULL", NULL);
VERIFY_NON_NULL_RET(data, TAG, "data is NULL", NULL);
CATCPData *tcpData = (CATCPData *) OICCalloc(1, sizeof(*tcpData));
if (!tcpData)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed!");
return NULL;
}
tcpData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
tcpData->data = (void *) OICMalloc(dataLength);
if (!tcpData->data)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed!");
CAFreeTCPData(tcpData);
return NULL;
}
memcpy(tcpData->data, data, dataLength);
tcpData->dataLen = dataLength;
tcpData->isMulticast = isMulticast;
return tcpData;
}
示例12: TEST
TEST(MarshalingAndUnMarshalingTest, BinToPstatJSONAndJSONToPstatBin)
{
const char* id = "ZGV2aWNlaWQAAAAAABhanw==";
OicSecPstat_t pstat;
pstat.cm = NORMAL;
pstat.commitHash = 0;
uint32_t outLen = 0;
unsigned char base64Buff[sizeof(((OicUuid_t*) 0)->id)] = {};
EXPECT_EQ(B64_OK, b64Decode(id, strlen(id), base64Buff, sizeof(base64Buff), &outLen));
memcpy(pstat.deviceID.id, base64Buff, outLen);
pstat.isOp = true;
pstat.tm = NORMAL;
pstat.om = SINGLE_SERVICE_CLIENT_DRIVEN;
pstat.smLen = 2;
pstat.sm = (OicSecDpom_t*)OICCalloc(pstat.smLen, sizeof(OicSecDpom_t));
pstat.sm[0] = SINGLE_SERVICE_CLIENT_DRIVEN;
pstat.sm[1] = SINGLE_SERVICE_SERVER_DRIVEN;
char* jsonPstat = BinToPstatJSON(&pstat);
printf("BinToJSON Dump:\n%s\n\n", jsonPstat);
EXPECT_TRUE(jsonPstat != NULL);
OicSecPstat_t *pstat1 = JSONToPstatBin(jsonPstat);
EXPECT_TRUE(pstat1 != NULL);
OICFree(pstat1->sm);
OICFree(pstat1);
OICFree(jsonPstat);
OICFree(pstat.sm);
}
示例13: CAReceiveMessage
static void CAReceiveMessage(int fd)
{
// #1. get remote device information from file descriptor.
size_t index = 0;
CATCPSessionInfo_t *svritem = CAGetSessionInfoFromFD(fd, &index);
if (!svritem)
{
OIC_LOG(ERROR, TAG, "there is no connection information in list");
return;
}
// #2. get already allocated memory size.
size_t bufSize = (svritem->totalDataLen == 0) ? TCP_MAX_HEADER_LEN : svritem->totalDataLen;
if (!svritem->recvData)
{
svritem->recvData = (unsigned char *) OICCalloc(1, bufSize);
if (!svritem->recvData)
{
OIC_LOG(ERROR, TAG, "out of memory");
CADisconnectTCPSession(svritem, index);
return;
}
}
// #3. receive data from remote device.
ssize_t recvLen = recv(fd, svritem->recvData + svritem->recvDataLen,
bufSize - svritem->recvDataLen, 0);
if (recvLen <= 0)
{
if(EWOULDBLOCK != errno)
{
OIC_LOG_V(ERROR, TAG, "Recvfrom failed %s", strerror(errno));
CADisconnectTCPSession(svritem, index);
}
return;
}
svritem->recvDataLen += recvLen;
// #4. get actual data length from coap over tcp header.
if (!svritem->totalDataLen)
{
coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(
((unsigned char *) svritem->recvData)[0] >> 4);
size_t headerLen = coap_get_tcp_header_length_for_transport(transport);
if (svritem->recvDataLen >= headerLen)
{
svritem->totalDataLen = CAGetTotalLengthFromHeader(
(unsigned char *) svritem->recvData);
bufSize = svritem->totalDataLen;
unsigned char *newBuf = OICRealloc(svritem->recvData, bufSize);
if (!newBuf)
{
OIC_LOG(ERROR, TAG, "out of memory");
CADisconnectTCPSession(svritem, index);
return;
}
svritem->recvData = newBuf;
}
}
示例14: getDoubleValueFromString
OCEntityHandlerResult getDoubleValueFromString (const char *str, double *outDouble)
{
size_t hexOutValSize = strlen(HexPrepend) + strlen(str) + 1;
char * hexOutVal = (char *) OICCalloc(1, hexOutValSize);
if(!hexOutVal)
{
return OC_EH_ERROR;
}
OICStrcpy(hexOutVal, hexOutValSize, HexPrepend);
OICStrcat(hexOutVal, hexOutValSize, str);
char *endPtr = NULL;
errno = 0;
double value = strtod(hexOutVal, &endPtr);
if(errno != 0 || *endPtr != 0 || value == HUGE_VALF || value == HUGE_VALL)
{
OICFree(hexOutVal);
return OC_EH_ERROR;
}
OICFree(hexOutVal);
*outDouble = value;
return OC_EH_OK;
}
示例15: appendStringLL
static OCStackResult appendStringLL(OCStringLL **type, const unsigned char *value)
{
OCStringLL *temp= (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
if (!temp)
{
return OC_STACK_NO_MEMORY;
}
temp->value = OICStrdup((char *)value);
if (!temp->value)
{
return OC_STACK_NO_MEMORY;
}
temp->next = NULL;
if (!*type)
{
*type = temp;
}
else
{
OCStringLL *tmp = *type;
for (; tmp->next; tmp = tmp->next);
tmp->next = temp;
}
return OC_STACK_OK;
}