Skip to content

Commit

Permalink
Platinum: allow some statevariables to reset to default value after s…
Browse files Browse the repository at this point in the history
…ending completed (needed for ContainerUpdateIDs usage)
  • Loading branch information
alcoheca committed Oct 9, 2012
1 parent 33ea386 commit b1a28da
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
11 changes: 9 additions & 2 deletions lib/libUPnP/Platinum/Source/Core/PltService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ PLT_Service::IsSubscribable()
| PLT_Service::SetStateVariable
+---------------------------------------------------------------------*/
NPT_Result
PLT_Service::SetStateVariable(const char* name, const char* value)
PLT_Service::SetStateVariable(const char* name, const char* value, const bool clearonsend /*=false*/)
{
PLT_StateVariable* stateVariable = NULL;
NPT_ContainerFind(m_StateVars, PLT_StateVariableNameFinder(name), stateVariable);
if (stateVariable == NULL)
return NPT_FAILURE;

return stateVariable->SetValue(value);
return stateVariable->SetValue(value, clearonsend);
}

/*----------------------------------------------------------------------
Expand Down Expand Up @@ -838,6 +838,13 @@ PLT_Service::NotifyChanged()
delete sub;
}

// some state variables must be cleared immediatly after sending
iter = vars_ready.GetFirstItem();
while (iter) {
PLT_StateVariable* var = *iter;
var->OnSendCompleted();
++iter;
}
return NPT_SUCCESS;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/libUPnP/Platinum/Source/Core/PltService.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ class PLT_Service
when necessary.
@param name state variable name
@param value new State Variable value.
@param clearonsend whether the State Variable should clear immediatly in ::OnSendingCompleted
*/
NPT_Result SetStateVariable(const char* name, const char* value);
NPT_Result SetStateVariable(const char* name, const char* value, const bool clearonsend = false);

/**
Certain state variables notifications must not be sent faster than a certain
Expand Down
16 changes: 14 additions & 2 deletions lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ NPT_SET_LOCAL_LOGGER("platinum.core.statevariable")
PLT_StateVariable::PLT_StateVariable(PLT_Service* service) :
m_Service(service),
m_AllowedValueRange(NULL),
m_IsSendingEventsIndirectly(true)
m_IsSendingEventsIndirectly(true),
m_ShouldClearOnSend(false)
{
}

Expand Down Expand Up @@ -145,7 +146,7 @@ PLT_StateVariable::SetRate(NPT_TimeInterval rate)
| PLT_StateVariable::SetValue
+---------------------------------------------------------------------*/
NPT_Result
PLT_StateVariable::SetValue(const char* value)
PLT_StateVariable::SetValue(const char* value, const bool clearonsend /*=false*/)
{
if (value == NULL) {
return NPT_FAILURE;
Expand All @@ -159,6 +160,7 @@ PLT_StateVariable::SetValue(const char* value)
}

m_Value = value;
m_ShouldClearOnSend = clearonsend;
m_Service->AddChanged(this);
}

Expand All @@ -182,6 +184,16 @@ PLT_StateVariable::IsReadyToPublish()
return false;
}

/*----------------------------------------------------------------------
| PLT_StateVariable::OnSendCompleted
+---------------------------------------------------------------------*/
void
PLT_StateVariable::OnSendCompleted()
{
if(m_ShouldClearOnSend)
m_Value = m_DefaultValue;
}

/*----------------------------------------------------------------------
| PLT_StateVariable::ValidateValue
+---------------------------------------------------------------------*/
Expand Down
10 changes: 9 additions & 1 deletion lib/libUPnP/Platinum/Source/Core/PltStateVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ class PLT_StateVariable
it is an allowed value. Once the value is validated, it is marked for eventing by
calling the PLT_Service AddChanged function.
@param value new state variable value. Can be a comma separated list of values.
@param clearonsend whether the statevariable should be cleared immediatly after sending
*/
NPT_Result SetValue(const char* value);
NPT_Result SetValue(const char* value, const bool clearonsend = false);

/**
Validate the new value of the state variable.
Expand Down Expand Up @@ -172,6 +173,12 @@ class PLT_StateVariable
*/
bool IsReadyToPublish();

/**
* If this statevariable should clear after sending to all subscribers, clears the value without
* eventing the change
*/
void OnSendCompleted();

/**
Serialize the state variable into xml.
*/
Expand All @@ -189,6 +196,7 @@ class PLT_StateVariable
NPT_String m_DefaultValue;
bool m_IsSendingEvents;
bool m_IsSendingEventsIndirectly;
bool m_ShouldClearOnSend;
NPT_TimeInterval m_Rate;
NPT_TimeStamp m_LastEvent;
NPT_Array<NPT_String*> m_AllowedValues;
Expand Down

0 comments on commit b1a28da

Please sign in to comment.