コード例 #1
0
ファイル: parc_Buffer.c プロジェクト: isolis/Libparc
static inline PARCBuffer *
_parcBuffer_getInstance(void)
{
    PARCBuffer *result = parcObject_CreateInstance(PARCBuffer);

    return result;
}
コード例 #2
0
ファイル: parc_Log.c プロジェクト: isolis/Libparc
PARCLog *
parcLog_Create(const char *hostName, const char *applicationName, const char *processId, PARCLogReporter *reporter)
{
    if (applicationName == NULL) {
        applicationName = _nilvalue;
    }
    if (hostName == NULL) {
        hostName = _nilvalue;
    }
    if (processId == NULL) {
        processId = _nilvalue;
    }

    PARCLog *result = parcObject_CreateInstance(PARCLog);
    if (result == NULL) {
        trapOutOfMemory("Creating an instance of PARCLog.");
    }

    result->hostName = parcMemory_StringDuplicate(hostName, strlen(hostName));
    result->applicationName = parcMemory_StringDuplicate(applicationName, strlen(applicationName));
    result->processId = parcMemory_StringDuplicate(processId, strlen(processId));
    result->messageId = 0;
    result->level = PARCLogLevel_Off;
    result->reporter = parcLogReporter_Acquire(reporter);
    return result;
}
コード例 #3
0
RtaCommandCloseConnection *
rtaCommandCloseConnection_Create(int apiNotifierFd)
{
    RtaCommandCloseConnection *closeConnection = parcObject_CreateInstance(RtaCommandCloseConnection);
    closeConnection->apiNotifierFd = apiNotifierFd;
    return closeConnection;
}
コード例 #4
0
CCNxInterestPayloadId *
ccnxInterestPayloadId_CreateAsSHA256Hash(const PARCBuffer *data)
{
    CCNxInterestPayloadId *result = parcObject_CreateInstance(CCNxInterestPayloadId);

    PARCCryptoHasher *hasher = parcCryptoHasher_Create(PARCCryptoHashType_SHA256);
    parcCryptoHasher_Init(hasher);
    parcCryptoHasher_UpdateBuffer(hasher, data);
    PARCCryptoHash *hash = parcCryptoHasher_Finalize(hasher);
    parcCryptoHasher_Release(&hasher);

    PARCBuffer *hashData = parcCryptoHash_GetDigest(hash);
    PARCBuffer *codedHash = parcBuffer_Allocate(parcBuffer_Capacity(hashData) + 1);
    parcBuffer_PutUint8(codedHash, CCNxInterestPayloadId_TypeCode_RFC6920_SHA256);
    parcBuffer_PutBuffer(codedHash, hashData);
    parcBuffer_Flip(codedHash);

    result->nameSegment =
        ccnxNameSegment_CreateTypeValue(CCNxNameLabelType_PAYLOADID, codedHash);

    parcBuffer_Release(&codedHash);
    parcCryptoHash_Release(&hash);

    return result;
}
コード例 #5
0
ファイル: parc_JSONParser.c プロジェクト: isolis/Libparc
PARCJSONParser *
parcJSONParser_Create(PARCBuffer *buffer)
{
    PARCJSONParser *result = parcObject_CreateInstance(PARCJSONParser);
    result->ignore = " \t\n";
    result->buffer = parcBuffer_Acquire(buffer);
    return result;
}
コード例 #6
0
RtaCommandCreateProtocolStack *
rtaCommandCreateProtocolStack_Create(int stackId, CCNxStackConfig *config)
{
    RtaCommandCreateProtocolStack *createStack = parcObject_CreateInstance(RtaCommandCreateProtocolStack);
    createStack->stackId = stackId;
    createStack->config = ccnxStackConfig_Copy(config);
    return createStack;
}
コード例 #7
0
ファイル: parc_URISegment.c プロジェクト: isolis/Libparc
PARCURISegment *
parcURISegment_CreateFromBuffer(PARCBuffer *buffer)
{
    PARCURISegment *result = parcObject_CreateInstance(PARCURISegment);
    if (result != NULL) {
        result->buffer = parcBuffer_Acquire(buffer);
    }
    return result;
}
コード例 #8
0
ファイル: parc_SortedList.c プロジェクト: PARC/Libparc
PARCSortedList *
parcSortedList_Copy(const PARCSortedList *original)
{
    PARCSortedList *result = parcObject_CreateInstance(PARCSortedList);

    if (result != NULL) {
        result->list = parcLinkedList_Copy(original->list);
    }

    return result;
}
コード例 #9
0
CCNxNameSegment *
ccnxNameSegment_CreateLabelValue(const CCNxNameLabel *label, const PARCBuffer *value)
{
    CCNxNameSegment *result = parcObject_CreateInstance(CCNxNameSegment);
    if (result != NULL) {
        result->label = ccnxNameLabel_Acquire(label);
        result->type = ccnxNameLabel_GetType(label);
        result->value = parcBuffer_Acquire(value);
    }
    return result;
}
コード例 #10
0
ファイル: ccnx_Chunker.c プロジェクト: mword/Libccnx-common
CCNxChunker *
ccnxChunker_Create(void *instance, CCNxChunkerInterface *interface)
{
    CCNxChunker *chunker = parcObject_CreateInstance(CCNxChunker);

    if (chunker != NULL) {
        chunker->instance = instance;
        chunker->interface = interface;
    }

    return chunker;
}
コード例 #11
0
ファイル: parc_Chunker.c プロジェクト: rayyagar/Libparc
PARCChunker *
parcChunker_Create(PARCObject *instance, PARCChunkerInterface *interface)
{
    PARCChunker *chunker = parcObject_CreateInstance(PARCChunker);

    if (chunker != NULL) {
        chunker->instance = parcObject_Acquire(instance);
        chunker->interface = interface;
    }

    return chunker;
}
コード例 #12
0
ファイル: parc_ScheduledTask.c プロジェクト: PARC/Libparc
PARCScheduledTask *
parcScheduledTask_Create(PARCFutureTask *task, uint64_t executionTime)
{
    PARCScheduledTask *result = parcObject_CreateInstance(PARCScheduledTask);

    if (result != NULL) {
        result->task = parcFutureTask_Acquire(task);
        result->executionTime = executionTime;
    }

    return result;
}
コード例 #13
0
ファイル: parc_KeyStore.c プロジェクト: rayyagar/Libparc
PARCKeyStore *
parcKeyStore_Create(PARCObject *instance, const PARCKeyStoreInterface *interface)
{
    PARCKeyStore *keyStore = parcObject_CreateInstance(PARCKeyStore);

    if (keyStore != NULL) {
        keyStore->instance = parcObject_Acquire(instance);
        keyStore->interface = interface;
    }

    return keyStore;
}
コード例 #14
0
ファイル: parc_SortedList.c プロジェクト: PARC/Libparc
PARCSortedList *
parcSortedList_CreateCompare(PARCSortedListEntryCompareFunction compare)
{
    PARCSortedList *result = parcObject_CreateInstance(PARCSortedList);

    if (result != NULL) {
        result->list = parcLinkedList_Create();
        result->compare = compare;
    }

    return result;
}
コード例 #15
0
CCNxPortalAnchor *
ccnxPortalAnchor_Create(const CCNxName *name, time_t expireTime)
{
    CCNxPortalAnchor *result = parcObject_CreateInstance(CCNxPortalAnchor);

    if (result != NULL) {
        result->prefix = ccnxName_Acquire(name);
        result->expireTime = expireTime;
    }

    return result;
}
コード例 #16
0
ファイル: metis_GenericEther.c プロジェクト: isolis/Metis
MetisGenericEther *
metisGenericEther_Create(MetisForwarder *metis, const char *deviceName, uint16_t etherType)
{
    assertNotNull(metis, "Parameter metis must be non-null");

    // The Darwin generic ether allows a NULL device name, it is used in the unit tests.

    MetisGenericEther *ether = NULL;

    if (metisEthernet_IsValidEthertype(etherType)) {
        ether = parcObject_CreateInstance(MetisGenericEther);
        ether->ethertype = etherType;
        ether->logger = metisLogger_Acquire(metisForwarder_GetLogger(metis));
        ether->etherSocket = -1; // invalid valid
        ether->workBuffer = parcEventBuffer_Create();
        ether->macAddress = NULL;
        ether->mtu = metisSystem_InterfaceMtu(metis, deviceName);

        _darwinEthernet_SetInterfaceAddress(ether, deviceName);

        bool success = _darwinEthernet_SetupReceive(ether, deviceName);

        if (success) {
            if (metisLogger_IsLoggable(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Info)) {
                char *str = parcBuffer_ToHexString(ether->macAddress);
                metisLogger_Log(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Info, __func__,
                                "GenericEther %p created on device %s (%s) for ethertype 0x%04x fd %d bufferLength %u mtu %u",
                                (void *) ether, deviceName, str, etherType, ether->etherSocket, ether->etherBufferLength, ether->mtu);
                parcMemory_Deallocate((void **) &str);
            }
        } else {
            if (metisLogger_IsLoggable(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Error)) {
                metisLogger_Log(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Error, __func__,
                                "GenericEther failed to created on device %s for ethertype 0x%04x",
                                deviceName, etherType);
            }

            // this will also null ether
            metisGenericEther_Release(&ether);
        }

        assertTrue(ether->etherBufferLength < 65536, "Buffer length way too big, expected less than 65536 got %u", ether->etherBufferLength);
    } else {
        if (metisLogger_IsLoggable(metisForwarder_GetLogger(metis), MetisLoggerFacility_IO, PARCLogLevel_Error)) {
            metisLogger_Log(metisForwarder_GetLogger(metis), MetisLoggerFacility_IO, PARCLogLevel_Error, __func__,
                            "GenericEther failed to created on device %s for ethertype 0x%04x, invalid ethertype",
                            deviceName, etherType);
        }
    }

    return ether;
}
コード例 #17
0
ファイル: parc_HashMap.c プロジェクト: rayyagar/Libparc
static _PARCHashMapEntry *
_parcHashMapEntry_Create(const PARCObject *key, const PARCObject *value)
{
    parcObject_OptionalAssertValid(key);
    parcObject_OptionalAssertValid(value);

    _PARCHashMapEntry *result = parcObject_CreateInstance(_PARCHashMapEntry);

    result->key = parcObject_Copy(key);
    result->value = parcObject_Acquire(value);

    return result;
}
コード例 #18
0
ファイル: parc_Synchronizer.c プロジェクト: isolis/Libparc
PARCSynchronizer *
parcSynchronizer_Create(void)
{
    PARCSynchronizer *result = parcObject_CreateInstance(PARCSynchronizer);

#ifdef PARCLibrary_DISABLE_ATOMICS
    pthread_mutex_init(&result->mutex, NULL);
#else
    result->mutex = _PARCSynchronizer_Unlocked;
#endif

    return result;
}
コード例 #19
0
ファイル: parc_BufferChunker.c プロジェクト: isolis/Libparc
PARCBufferChunker *
parcBufferChunker_Create(PARCBuffer *data, size_t chunkSize)
{
    PARCBufferChunker *chunker = parcObject_CreateInstance(PARCBufferChunker);

    if (chunker != NULL) {
        chunker->chunkSize = chunkSize;
        chunker->data = parcBuffer_Acquire(data);
        chunker->currentElement = NULL;
    }

    return chunker;
}
コード例 #20
0
static CCNxInterestPayloadId *
_ccnxInterestPayloadId_CreateFromNameSegment(const CCNxNameSegment *nameSegment)
{
    ccnxNameSegment_AssertValid(nameSegment);
    assertTrue(ccnxNameSegment_GetType(nameSegment) == CCNxNameLabelType_PAYLOADID,
               "ccnxInterestPayloadId_CreateFromNameSegment: supplied nameSegment is not a PayloadId");
    if (ccnxNameSegment_GetType(nameSegment) != CCNxNameLabelType_PAYLOADID) {
        return NULL;
    }
    CCNxInterestPayloadId *result = parcObject_CreateInstance(CCNxInterestPayloadId);
    result->nameSegment = ccnxNameSegment_Acquire(nameSegment);

    return result;
}
コード例 #21
0
ファイル: parc_FileChunker.c プロジェクト: isolis/Libparc
PARCFileChunker *
parcFileChunker_Create(PARCFile *file, size_t chunkSize)
{
    PARCFileChunker *chunker = parcObject_CreateInstance(PARCFileChunker);

    if (chunker != NULL) {
        chunker->chunkSize = chunkSize;
        chunker->file = parcFile_Acquire(file);
        chunker->fhandle = parcRandomAccessFile_Open(chunker->file);
        chunker->currentElement = NULL;
    }

    return chunker;
}
コード例 #22
0
CCNxPortalAnchor *
ccnxPortalAnchor_CreateFromJSON(const PARCJSON *json)
{
    CCNxPortalAnchor *result = parcObject_CreateInstance(CCNxPortalAnchor);

    if (result != NULL) {
        result->prefix = ccnxName_CreateFromURI(parcBuffer_Overlay(parcJSONValue_GetString(parcJSON_GetByPath(json, "/namePrefix")), 0));
        result->expireTime = parcJSONValue_GetInteger(parcJSON_GetByPath(json, "/expireTime"));

       ccnxPortalAnchor_OptionalAssertValid(result);
    }

    return result;
}
コード例 #23
0
ファイル: parc_PublicKeySigner.c プロジェクト: PARC/Libparc
PARCPublicKeySigner *
parcPublicKeySigner_Create(PARCKeyStore *keyStore, PARCSigningAlgorithm signingAlgorithm, PARCCryptoHashType hashType)
{
    PARCPublicKeySigner *result = parcObject_CreateInstance(PARCPublicKeySigner);

    if (result != NULL) {
        result->keyStore = parcKeyStore_Acquire(keyStore);
        result->signingAlgorithm = signingAlgorithm;
        result->hashType = hashType;
        result->hasher = parcCryptoHasher_Create(hashType);
    }

    return result;
}
コード例 #24
0
ファイル: parc_Stopwatch.c プロジェクト: GlennCScott/Libparc
PARCStopwatch *
parcStopwatch_Create(void)
{
    PARCStopwatch *result = parcObject_CreateInstance(PARCStopwatch);

    if (result != NULL) {
        result->start.tv_sec = 0;
        result->start.tv_usec = 0;
        result->stop.tv_sec = 0;
        result->stop.tv_usec = 0;
    }

    return result;

}
コード例 #25
0
ファイル: parc_BasicStats.c プロジェクト: rayyagar/Libparc
PARCBasicStats *
parcBasicStats_Create(void)
{
    PARCBasicStats *result = parcObject_CreateInstance(PARCBasicStats);

    if (result != NULL) {
        result->count = 0;
        result->mean = 0;
        result->variance = 0;
        result->maximum = 0;
        result->minimum = 0;
    }

    return result;
}
コード例 #26
0
ファイル: parc_Timer.c プロジェクト: isolis/Libparc
PARCTimer *
parcTimer_Create(void)
{
    PARCTimer *result = parcObject_CreateInstance(PARCTimer);

    if (result != NULL) {
        result->start.tv_sec = 0;
        result->start.tv_usec = 0;
        result->stop.tv_sec = 0;
        result->stop.tv_usec = 0;
    }

    return result;

}
コード例 #27
0
ファイル: test_parc_Signer.c プロジェクト: PARC/Libparc
static _MockSigner *
_createSigner()
{
    _MockSigner *signer = parcObject_CreateInstance(_MockSigner);

    signer->hasher = parcCryptoHasher_Create(PARCCryptoHashType_SHA256);

    PARCPkcs12KeyStore *publicKeyStore = parcPkcs12KeyStore_Open("test_rsa.p12", "blueberry", PARCCryptoHashType_SHA256);
    assertNotNull(publicKeyStore, "Got null result from opening openssl pkcs12 file");

    signer->keyStore = parcKeyStore_Create(publicKeyStore, PARCPkcs12KeyStoreAsKeyStore);
    parcPkcs12KeyStore_Release(&publicKeyStore);

    return signer;
}
コード例 #28
0
ファイル: parc_Lock.c プロジェクト: rayyagar/Libparc
PARCLock *
parcLock_Create(void)
{
    PARCLock *result = parcObject_CreateInstance(PARCLock);

    pthread_mutexattr_init(&result->lockAttributes);
    pthread_mutexattr_settype(&result->lockAttributes, PTHREAD_MUTEX_ERRORCHECK);

    pthread_mutex_init(&result->lock, &result->lockAttributes);

    result->locked = false;
    pthread_cond_init(&result->notification, NULL);
    result->notified = false;
    return result;
}
コード例 #29
0
ファイル: parc_File.c プロジェクト: PARC/Libparc
PARCFile *
parcFile_CreateChild(const PARCFile *parent, char *fileName)
{
    PARCFile *result = NULL;

    PARCPathName *childPath = parcPathName_Append(parcPathName_Copy(parent->pathName), fileName);

    if (childPath != NULL) {
        result = parcObject_CreateInstance(PARCFile);
        if (result != NULL) {
            result->pathName = childPath;
        }
    }

    return result;
}
コード例 #30
0
ファイル: parc_RingBuffer_1x1.c プロジェクト: PARC/Libparc
static PARCRingBuffer1x1 *
_create(uint32_t elements, RingBufferEntryDestroyer *destroyer)
{
    PARCRingBuffer1x1 *ring = parcObject_CreateInstance(PARCRingBuffer1x1);
    assertNotNull(ring, "parcObject_Create returned NULL");

    ring->buffer = parcMemory_AllocateAndClear(sizeof(void *) * elements);
    assertNotNull((ring->buffer), "parcMemory_AllocateAndClear() failed to allocate array of %u pointers", elements);

    ring->writer_head = 0;
    ring->reader_tail = 0;
    ring->elements = elements;
    ring->destroyer = destroyer;
    ring->ring_mask = elements - 1;

    return ring;
}