AzureSphere/AzureSphereSampleDevice/main.c
static int DeviceMethodCallback(const char *methodName, const unsigned char *payload,
                                size_t payloadSize, unsigned char **response, size_t *responseSize,
                                void *userContextCallback)
{
    int result;
    char *responseString;

    Log_Debug("Received Device Method callback: Method name %s.\n", methodName);

    if (strcmp("TriggerAlarm", methodName) == 0) {
        // Output alarm using Log_Debug
        Log_Debug("  ----- ALARM TRIGGERED! -----\n");
        responseString = "\"Alarm Triggered\""; // must be a JSON string (in quotes)
        result = 200;
    } else {
        // All other method names are ignored
        responseString = "{}";
        result = -1;
    }

    // if 'response' is non-NULL, the Azure IoT library frees it after use, so copy it to heap
    *responseSize = strlen(responseString);
    *response = malloc(*responseSize);
    memcpy(*response, responseString, *responseSize);
    return result;
}
/// <summary>
///     Callback invoked when a Direct Method is received from Azure IoT Hub.
/// </summary>

Callback invoked when a Direct Method is received from Azure IoT Hub.
Callback invoked when a Direct Method is received from Azure IoT Hub .
static int DeviceMethodCallback(const char *methodName, const unsigned char *payload,
                                size_t payloadSize, unsigned char **response, size_t *responseSize,
                                void *userContextCallback)
{
    int result;
    char *responseString;
    Log_Debug("Received Device Method callback: Method name %s.\n", methodName);
    if (strcmp("TriggerAlarm", methodName) == 0) {
        Log_Debug("  ----- ALARM TRIGGERED! -----\n");
        responseString = "\"Alarm Triggered\""; 
        result = 200;
    } else {
        responseString = "{}";
        result = -1;
    }
    *responseSize = strlen(responseString);
    *response = malloc(*responseSize);
    memcpy(*response, responseString, *responseSize);
    return result;
}
static int DeviceMethodCallback ( const char * methodName , const unsigned char * payload , size_t payloadSize , unsigned char * * response , size_t * responseSize , void * userContextCallback ) { int result ; char * responseString ; Log_Debug ( " \n " , methodName ) ; if ( strcmp ( " " , methodName ) == 0 ) { Log_Debug ( " \n " ) ; responseString = " \" \" " ; result = 200 ; } else { responseString = " " ; result = -1 ; } * responseSize = strlen ( responseString ) ; * response = malloc ( * responseSize ) ; memcpy ( * response , responseString , * responseSize ) ; return result ; }
<summary>
Callback invoked when a Direct Method is received from Azure IoT Hub.
<summary > Callback invoked when a Direct Method is received from Azure IoT Hub .
// Output alarm using Log_Debug // must be a JSON string (in quotes) // All other method names are ignored // if 'response' is non-NULL, the Azure IoT library frees it after use, so copy it to heap