/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*/
package org.thingml.externalthingplugins.c.posix.dnssd.strategies;
import org.sintef.thingml.State;
import org.sintef.thingml.StateMachine;
import org.sintef.thingml.Thing;
import org.sintef.thingml.constraints.ThingMLHelpers;
import org.sintef.thingml.helpers.CompositeStateHelper;
import org.thingml.compilers.c.CCompilerContext;
import org.thingml.compilers.interfaces.c.ICThingApiStateIDStrategy;
import org.thingml.externalthingplugins.c.posix.PosixDNSSDExternalThingPlugin;
import org.thingml.externalthingplugins.c.posix.dnssd.utils.DNSSDUtils;
import java.util.List;
/**
* Created by vassik on 15.11.16.
*/
public class PosixThingApiStateIDStrategy implements ICThingApiStateIDStrategy {
private PosixDNSSDExternalThingPlugin plugin;
public PosixThingApiStateIDStrategy(PosixDNSSDExternalThingPlugin _plugin) {
plugin = _plugin;
}
@Override
public void generateStateIDs(Thing thing, StringBuilder builder, CCompilerContext ctx) {
builder.append("//Definition of the DNSSD terminate state. Generated by: " + this.getClass().getSimpleName() + "\n");
if (ThingMLHelpers.allStateMachines(thing).size() > 0) {// There should be only one if there is one
StateMachine sm = ThingMLHelpers.allStateMachines(thing).get(0);
List<State> states = CompositeStateHelper.allContainedStatesIncludingSessions(sm);
builder.append("#define " + getTerminateStateName(thing) + " " + states.size() + "\n");
builder.append("\n");
}
}
private String getTerminateStateName(Thing thing) {
return DNSSDUtils.getTerminateStateName(thing);
}
}