/*## (c) SECURITY EXPLORATIONS    2018 poland                                #*/
/*##     http://www.security-explorations.com                                #*/

/* THIS SOFTWARE IS PROTECTED BY DOMESTIC AND INTERNATIONAL COPYRIGHT LAWS    */
/* UNAUTHORISED COPYING OF THIS SOFTWARE IN EITHER SOURCE OR BINARY FORM IS   */
/* EXPRESSLY FORBIDDEN. ANY USE, INCLUDING THE REPRODUCTION, MODIFICATION,    */
/* DISTRIBUTION, TRANSMISSION, RE-PUBLICATION, STORAGE OR DISPLAY OF ANY      */
/* PART OF THE SOFTWARE, FOR COMMERCIAL OR ANY OTHER PURPOSES REQUIRES A      */
/* VALID LICENSE FROM THE COPYRIGHT HOLDER.                                   */

/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS    */
/* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,*/
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    */
/* SECURITY EXPLORATIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  */
/* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE     */
/* SOFTWARE.                                                                  */

import java.lang.*;
import org.dvb.dsmcc.*;
import javax.tv.service.*;
import javax.tv.service.selection.*;
import javax.tv.locator.*;
import org.davic.net.dvb.*;
import tv.osmosys.tci.service.db.*;
import tv.osmosys.tci.service.util.*;

public class DSMCC {
 public static String mount_carousel(String s) {
  String res=null;
 
  try {
   LocatorFactory lf=LocatorFactory.getInstance();
   DvbLocator loc=(DvbLocator)lf.createLocator(s);

   int onid=loc.getOriginalNetworkId();
   int tsid=loc.getTransportStreamId();
   int svid=loc.getServiceId();

   String filter="and(equ(tr:dvb.onid,"+onid+"),equ(tr:dvb.tsid,"+tsid+"),equ(sv:dvb.svid,"+svid+"))";

   ServiceView sv=ServiceViewManager.createServiceView();
   sv.setFilteringExpression(filter);

   ServiceViewIterator svi=sv.getServiceViewIterator();
   Service srv=svi.nextServiceDoNotMove();

   ServiceContext ctx=SrvUtils.current_service_context();

   if (ctx!=null) {
    ctx.select(srv);

    ctx=tv.osmosys.tci.service.ServiceContextFactory.createContext("nulltarget://dsmcc,lowpriority");
    ctx.select(srv);
  
    ServiceDomain sd=new ServiceDomain();
    sd.attach(loc);

    if (sd.isAttached()) {
     DSMCCObject dsmcco=sd.getMountPoint();

     res=dsmcco.toString();
    }
   }
  } catch(Throwable t) {}

  return res;
 }
}
