int CMSGetProtocolInfo(struct Upnp_Action_Request *actEvent) { char *source; char *sink; ZTrace(DBG_DMS_CMS, "Entering"); if ((source = DMSGetVariable(DMS_SERVICE_CMS, "SourceProtocolInfo")) == NULL) { ZError(DBG_DMS_CDS, "Unable to get SourceProtocolInfo Variable"); goto funcOut; } // No input parameters... Return protInfo in the action Result... // ActionResult has to be setup... // In case of errors, need to setup ErrCode and ErrStr.... actEvent->ErrCode = UPNP_E_SUCCESS; if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetProtocolInfo", dms.dmsServ[DMS_SERVICE_CMS].serviceType, "Source", source) != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set Source"); goto funcOut; } if ((sink = DMSGetVariable(DMS_SERVICE_CMS, "SinkProtocolInfo")) == NULL) { ZError(DBG_DMS_CDS, "Unable to get SinkProtocolInfo Variable"); goto funcOut; } if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetProtocolInfo", dms.dmsServ[DMS_SERVICE_CMS].serviceType, "Sink", sink) != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set Sink"); goto funcOut; } funcOut: if (actEvent->ErrCode != UPNP_E_SUCCESS) { actEvent->ActionResult = NULL; actEvent->ErrCode = UPNP_E_INTERNAL_ERROR; strcpy(actEvent->ErrStr, "Internal Error"); } ZTrace(DBG_DMS_CMS, "Exiting->%d", actEvent->ErrCode); return actEvent->ErrCode; }
int TvDevicePowerOn(IXML_Document * in,IXML_Document **out, const char **errorString) { (*out) = NULL; (*errorString) = NULL; char *value = NULL; // Debug, add action to this value = SampleUtil_GetFirstDocumentItem(in, "BinaryState"); if(NULL != value){ if(atoi(value)){ SampleUtil_Print("Luma Turned On!!\n"); } else{ SampleUtil_Print("Luma Turned Off!!\n"); } } if (TvDeviceSetPower(POWER_ON)) { /* create a response */ if (UpnpAddToActionResponse(out, "PowerOn", TvServiceType[TV_SERVICE_CONTROL], "Power", value) != UPNP_E_SUCCESS) { //"Power", "1") != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } return UPNP_E_SUCCESS; } else { (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } in = in; }
bool upnp_add_response (struct action_event_t *event, char *key, const char *value) { char *val; int res; if (!event || !event->status || !key || !value) return false; val = strdup (value); if (!val) return false; res = UpnpAddToActionResponse (&event->request->ActionResult, event->request->ActionName, event->service->type, key, val); if (res != UPNP_E_SUCCESS) { free (val); return false; } free (val); return true; }
/*! * \brief Increment the brightness. Read the current brightness from the state * table, add the increment, and then change the brightness. */ static int IncrementBrightness( /*! [in] The increment by which to change the brightness. */ int incr, /*! [in] action request document. */ IXML_Document * in, /*! [out] action result document. */ IXML_Document ** out, /*! [out] errorString (in case action was unsuccessful). */ const char **errorString) { int curbrightness; int newbrightness; const char *actionName = NULL; char value[TV_MAX_VAL_LEN]; if (incr > 0) { actionName = "IncreaseBrightness"; } else { actionName = "DecreaseBrightness"; } ithread_mutex_lock(&TVDevMutex); curbrightness = atoi(tv_service_table[TV_SERVICE_PICTURE].VariableStrVal [TV_PICTURE_BRIGHTNESS]); ithread_mutex_unlock(&TVDevMutex); newbrightness = curbrightness + incr; if (newbrightness < MIN_BRIGHTNESS || newbrightness > MAX_BRIGHTNESS) { SampleUtil_Print("error: can't change to brightness %d\n", newbrightness); (*errorString) = "Invalid Brightness"; return UPNP_E_INVALID_PARAM; } /* Vendor-specific code to set the channel goes here. */ sprintf(value, "%d", newbrightness); if (TvDeviceSetServiceTableVar(TV_SERVICE_PICTURE, TV_PICTURE_BRIGHTNESS, value)) { if (UpnpAddToActionResponse(out, actionName, TvServiceType[TV_SERVICE_PICTURE], "Brightness", value) != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } return UPNP_E_SUCCESS; } else { (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } in = in; }
/*! * \brief Increment the volume. Read the current volume from the state table, * add the increment, and then change the volume. */ static int IncrementVolume( /*! [in] The increment by which to change the volume. */ int incr, /*! [in] Action request document. */ IXML_Document * in, /*! [out] Action result document. */ IXML_Document ** out, /*! [out] Error string in case action was unsuccessful. */ const char **errorString) { int curvolume; int newvolume; const char *actionName = NULL; char value[TV_MAX_VAL_LEN]; if (incr > 0) { actionName = "IncreaseVolume"; } else { actionName = "DecreaseVolume"; } ithread_mutex_lock(&TVDevMutex); curvolume = atoi(tv_service_table[TV_SERVICE_CONTROL].VariableStrVal [TV_CONTROL_VOLUME]); ithread_mutex_unlock(&TVDevMutex); newvolume = curvolume + incr; if (newvolume < MIN_VOLUME || newvolume > MAX_VOLUME) { SampleUtil_Print("error: can't change to volume %d\n", newvolume); (*errorString) = "Invalid Volume"; return UPNP_E_INVALID_PARAM; } /* Vendor-specific code to set the volume goes here. */ sprintf(value, "%d", newvolume); if (TvDeviceSetServiceTableVar(TV_SERVICE_CONTROL, TV_CONTROL_VOLUME, value)) { if (UpnpAddToActionResponse(out, actionName, TvServiceType[TV_SERVICE_CONTROL], "Volume", value) != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } return UPNP_E_SUCCESS; } else { (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } in = in; }
int upnp_add_response(struct action_event *event, const char *key, const char *value) { int result = -1; char *val; #ifdef HAVE_LIBUPNP int rc; #endif //ENTER(); assert(event != NULL); assert(key != NULL); if (event->status) { goto out; } val = strdup(value); if (val == NULL) { /* report memory failure */ event->status = -1; #ifdef HAVE_LIBUPNP event->request->ActionResult = NULL; event->request->ErrCode = UPNP_SOAP_E_ACTION_FAILED; strcpy(event->request->ErrStr, strerror(errno)); #endif goto out; } #ifdef HAVE_LIBUPNP rc = UpnpAddToActionResponse(&event->request->ActionResult, event->request->ActionName, event->service->type, key, val); if (rc != UPNP_E_SUCCESS) { /* report custom error */ event->request->ActionResult = NULL; event->request->ErrCode = UPNP_SOAP_E_ACTION_FAILED; strcpy(event->request->ErrStr, UpnpGetErrorMessage(rc)); goto out; } result = 0; #endif out: if (val != NULL) { free(val); } //LEAVE(); return result; }
int IncrementChannel(int incr, IN IXML_Document * in, IXML_Document ** out, const char **errorString) { int curchannel; int newchannel; const char *actionName = NULL; char value[TV_MAX_VAL_LEN]; if (incr > 0) { actionName = "IncreaseChannel"; } else { actionName = "DecreaseChannel"; } ithread_mutex_lock(&TVDevMutex); curchannel = atoi(tv_service_table[TV_SERVICE_CONTROL].VariableStrVal [TV_CONTROL_CHANNEL]); ithread_mutex_unlock(&TVDevMutex); newchannel = curchannel + incr; if (newchannel < MIN_CHANNEL || newchannel > MAX_CHANNEL) { SampleUtil_Print("error: can't change to channel %d\n", newchannel); (*errorString) = "Invalid Channel"; return UPNP_E_INVALID_PARAM; } /* Vendor-specific code to set the channel goes here. */ sprintf(value, "%d", newchannel); if (TvDeviceSetServiceTableVar(TV_SERVICE_CONTROL, TV_CONTROL_CHANNEL, value)) { if (UpnpAddToActionResponse(out, actionName, TvServiceType[TV_SERVICE_CONTROL], "Channel", value) != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } return UPNP_E_SUCCESS; } else { (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } in = in; }
/****************************************************************************** * IncrementTint * * Description: * Increment the tint. Read the current tint from the state * table, add the increment, and then change the tint. * * Parameters: * incr -- The increment by which to change the tint. * * IXML_Document * in - action request document * IXML_Document **out - action result document * char **errorString - errorString (in case action was unsuccessful) *****************************************************************************/ int IncrementTint(IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT const char **errorString) { int curtint; int newtint; const char *actionName = NULL; char value[TV_MAX_VAL_LEN]; if (incr > 0) { actionName = "IncreaseTint"; } else { actionName = "DecreaseTint"; } ithread_mutex_lock(&TVDevMutex); curtint = atoi(tv_service_table[TV_SERVICE_PICTURE].VariableStrVal [TV_PICTURE_TINT]); ithread_mutex_unlock(&TVDevMutex); newtint = curtint + incr; if (newtint < MIN_TINT || newtint > MAX_TINT) { SampleUtil_Print("error: can't change to tint %d\n", newtint); (*errorString) = "Invalid Tint"; return UPNP_E_INVALID_PARAM; } /* Vendor-specific code to set the volume goes here. */ sprintf(value, "%d", newtint); if (TvDeviceSetServiceTableVar(TV_SERVICE_PICTURE, TV_PICTURE_TINT, value)) { if (UpnpAddToActionResponse(out, actionName, TvServiceType[TV_SERVICE_PICTURE], "Tint", value) != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } return UPNP_E_SUCCESS; } else { (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } in = in; }
/***************************************************************************** * TvDeviceSetContrast * * Description: * Change the contrast, update the TvDevice picture service * state table, and notify all subscribed control points of the * updated state. * * Parameters: * * IXML_Document * in - action request document * IXML_Document **out - action result document * char **errorString - errorString (in case action was unsuccessful) * ****************************************************************************/ int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT const char **errorString) { char *value = NULL; int contrast = -1; (*out) = NULL; (*errorString) = NULL; if (!(value = SampleUtil_GetFirstDocumentItem(in, "Contrast"))) { (*errorString) = "Invalid Contrast"; return UPNP_E_INVALID_PARAM; } contrast = atoi(value); if (contrast < MIN_CONTRAST || contrast > MAX_CONTRAST) { SampleUtil_Print("error: can't change to contrast %d\n", contrast); (*errorString) = "Invalid Contrast"; return UPNP_E_INVALID_PARAM; } /* Vendor-specific code to set the volume goes here. */ if (TvDeviceSetServiceTableVar(TV_SERVICE_PICTURE, TV_PICTURE_CONTRAST, value)) { if (UpnpAddToActionResponse(out, "SetContrast", TvServiceType[TV_SERVICE_PICTURE], "NewContrast", value) != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; free(value); return UPNP_E_INTERNAL_ERROR; } free(value); return UPNP_E_SUCCESS; } else { free(value); (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } }
int upnp_add_response(struct action_event *event, char *key, const char *value) { int rc = 0; char *val = NULL; int result = -1; ENTER(); if (event->status) { goto out; } val = strdup(value); if (val == NULL) { /* report memory failure */ event->status = -1; event->request->ActionResult = NULL; event->request->ErrCode = UPNP_SOAP_E_ACTION_FAILED; strcpy(event->request->ErrStr, strerror(errno)); goto out; } rc = UpnpAddToActionResponse(&event->request->ActionResult, event->request->ActionName, event->service->type, key, val); if (rc != UPNP_E_SUCCESS) { /* report custom error */ event->request->ActionResult = NULL; event->request->ErrCode = UPNP_SOAP_E_ACTION_FAILED; strcpy(event->request->ErrStr, UpnpGetErrorMessage(rc)); goto out; } result = 0; out: LEAVE(); free(val); return result; }
int TvDevicePowerOff(IXML_Document *in, IXML_Document **out, const char **errorString) { (*out) = NULL; (*errorString) = NULL; if (TvDeviceSetPower(POWER_OFF)) { /*create a response */ if (UpnpAddToActionResponse(out, "PowerOff", TvServiceType[TV_SERVICE_CONTROL], "Power", "0") != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } return UPNP_E_SUCCESS; } (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; in = in; }
int TvDeviceSetChannel(IXML_Document * in, IXML_Document ** out, const char **errorString) { char *value = NULL; int channel = 0; (*out) = NULL; (*errorString) = NULL; if (!(value = SampleUtil_GetFirstDocumentItem(in, "Channel"))) { (*errorString) = "Invalid Channel"; return UPNP_E_INVALID_PARAM; } channel = atoi(value); if (channel < MIN_CHANNEL || channel > MAX_CHANNEL) { free(value); SampleUtil_Print("error: can't change to channel %d\n", channel); (*errorString) = "Invalid Channel"; return UPNP_E_INVALID_PARAM; } /* Vendor-specific code to set the channel goes here. */ if (TvDeviceSetServiceTableVar(TV_SERVICE_CONTROL, TV_CONTROL_CHANNEL, value)) { if (UpnpAddToActionResponse(out, "SetChannel", TvServiceType[TV_SERVICE_CONTROL], "NewChannel", value) != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; free(value); return UPNP_E_INTERNAL_ERROR; } free(value); return UPNP_E_SUCCESS; } else { free(value); (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } }
int TvDeviceSetBrightness(IXML_Document * in, IXML_Document ** out, const char **errorString) { char *value = NULL; int brightness = -1; (*out) = NULL; (*errorString) = NULL; if (!(value = SampleUtil_GetFirstDocumentItem(in, "Brightness"))) { (*errorString) = "Invalid Brightness"; return UPNP_E_INVALID_PARAM; } brightness = atoi(value); if (brightness < MIN_BRIGHTNESS || brightness > MAX_BRIGHTNESS) { SampleUtil_Print("error: can't change to brightness %d\n", brightness); (*errorString) = "Invalid Brightness"; return UPNP_E_INVALID_PARAM; } /* Vendor-specific code to set the volume goes here. */ if (TvDeviceSetServiceTableVar(TV_SERVICE_PICTURE, TV_PICTURE_BRIGHTNESS, value)) { if (UpnpAddToActionResponse(out, "SetBrightness", TvServiceType[TV_SERVICE_PICTURE], "NewBrightness", value) != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; free(value); return UPNP_E_INTERNAL_ERROR; } free(value); return UPNP_E_SUCCESS; } else { free(value); (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } }
int TvDeviceSetVolume(IXML_Document * in, IXML_Document ** out, const char **errorString) { char *value = NULL; int volume = 0; (*out) = NULL; (*errorString) = NULL; if (!(value = SampleUtil_GetFirstDocumentItem(in, "Volume"))) { (*errorString) = "Invalid Volume"; return UPNP_E_INVALID_PARAM; } volume = atoi(value); if (volume < MIN_VOLUME || volume > MAX_VOLUME) { SampleUtil_Print("error: can't change to volume %d\n", volume); (*errorString) = "Invalid Volume"; return UPNP_E_INVALID_PARAM; } /* Vendor-specific code to set the volume goes here. */ if (TvDeviceSetServiceTableVar(TV_SERVICE_CONTROL, TV_CONTROL_VOLUME, value)) { if (UpnpAddToActionResponse(out, "SetVolume", TvServiceType[TV_SERVICE_CONTROL], "NewVolume", value) != UPNP_E_SUCCESS) { (*out) = NULL; (*errorString) = "Internal Error"; free(value); return UPNP_E_INTERNAL_ERROR; } free(value); return UPNP_E_SUCCESS; } else { free(value); (*errorString) = "Internal Error"; return UPNP_E_INTERNAL_ERROR; } }
int CMSGetCurrentConnectionIDs(struct Upnp_Action_Request *actEvent) { char *connId; PSERV_COMMON serv = &dms.dmsServ[DMS_SERVICE_CMS]; ZTrace(DBG_DMS_CMS, "Entering"); actEvent->ErrCode = UPNP_E_SUCCESS; if ((connId = DMSGetVariable(DMS_SERVICE_CMS, "CurrentConnectionIDs")) == NULL) { ZError(DBG_DMS_CDS, "Unable to get CurrentConnectionIDs Variable"); goto funcOut; } // Need to return only connectionID of zero as we don't support // prepareforConnection fn... if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetCurrentConnectionIDs", serv->serviceType, "ConnectionIDs", connId) != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set ConnectionIDs"); goto funcOut; } funcOut: if (actEvent->ErrCode != UPNP_E_SUCCESS) { actEvent->ActionResult = NULL; actEvent->ErrCode = UPNP_E_INTERNAL_ERROR; strcpy(actEvent->ErrStr, "Internal Error"); } ZTrace(DBG_DMS_CMS, "Exiting->%d", actEvent->ErrCode); return actEvent->ErrCode; }
int upnp_add_response(struct action_event *event, const char *key, const char *value) { assert(event != NULL); assert(key != NULL); assert(value != NULL); if (event->status) { return -1; } int rc; rc = UpnpAddToActionResponse(&event->request->ActionResult, event->request->ActionName, event->service->service_type, key, value); if (rc != UPNP_E_SUCCESS) { /* report custom error */ event->request->ActionResult = NULL; event->request->ErrCode = UPNP_SOAP_E_ACTION_FAILED; strcpy(event->request->ErrStr, UpnpGetErrorMessage(rc)); return -1; } return 0; }
int CMSGetCurrentConnectionInfo(struct Upnp_Action_Request *actEvent) { char *value = NULL; PSERV_COMMON serv = &dms.dmsServ[DMS_SERVICE_CMS]; ZTrace(DBG_DMS_CMS, "Entering"); actEvent->ErrCode = UPNP_E_SUCCESS; // From the request get the connection ID... if (!(value = ixmlGetFirstDocumentItem(actEvent->ActionRequest, "ConnectionID"))) { strcpy(actEvent->ErrStr, "Invalid Arguments"); actEvent->ErrCode = UPNP_SOAP_E_INVALID_ARGS; ZError(DBG_DMS_CMS, "ConnectionID Value not present"); goto funcOut; } // Make sure the value is zero... if (atoi(value) != 0) { strcpy(actEvent->ErrStr, "Invalid Connection Reference"); actEvent->ErrCode = UPNP_SOAP_E_INVALID_CONN_REF; ZError(DBG_DMS_CMS, "ConnectionID Value is not zero->%d", atoi(value)); goto funcOut; } // Return variables related to connection id... if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetCurrentConnectionInfo", serv->serviceType, "RcsID", "-1") != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set RcsID"); goto intError; } if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetCurrentConnectionInfo", serv->serviceType, "AVTransportID", "-1") != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set AVTransportID"); goto intError; } if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetCurrentConnectionInfo", serv->serviceType, "PeerConnectionManager", "") != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set PeerConnectionManager"); goto intError; } if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetCurrentConnectionInfo", serv->serviceType, "PeerConnectionID", "-1") != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set PeerConnectionID"); goto intError; } if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetCurrentConnectionInfo", serv->serviceType, "Direction", "Output") != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set Output"); goto intError; } if (UpnpAddToActionResponse(&actEvent->ActionResult, "GetCurrentConnectionIDs", serv->serviceType, "Status", "Unknown") != UPNP_E_SUCCESS) { ZError(DBG_DMS_CMS, "Unable to set Status"); goto intError; } goto funcOut; intError: actEvent->ActionResult = NULL; actEvent->ErrCode = UPNP_E_INTERNAL_ERROR; strcpy(actEvent->ErrStr, "Internal Error"); funcOut: ZTrace(DBG_DMS_CMS, "Exiting->%d", actEvent->ErrCode); if (value) { free(value); } return actEvent->ErrCode; }