package cn.diaovision.omnicontrol.core.model.device.splicer;

import org.reactivestreams.Subscriber;

import java.util.List;

import cn.diaovision.omnicontrol.core.message.SplicerMessage;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by TaoYimin on 2017/7/27.
 */

public class MediaSplicerRemoter {
    MediaSplicer splicer;

    public MediaSplicerRemoter(MediaSplicer splicer) {
        this.splicer = splicer;
    }

    public MediaSplicer getSplicer() {
        return splicer;
    }

    public void setSplicer(MediaSplicer splicer) {
        this.splicer = splicer;
    }

    public void getSceneList(final int groupId, Subscriber subscriber) {
        Flowable.create(new FlowableOnSubscribe<List<Scene>>() {
            @Override
            public void subscribe(FlowableEmitter<List<Scene>> e) throws Exception {
                SplicerMessage msg = SplicerMessage.buildRlstMessage(groupId);
                List<byte[]> recvs = splicer.getController().send(msg.toBytes(), msg.toBytes().length, true);
                e.onNext(SplicerMessage.parseSceneMessage(recvs));
            }
        }, BackpressureStrategy.BUFFER)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }
}

@@ -91,24 +91,52 @@
 ubscriber;%0A%0A
+import java.io.IOException;%0A
 import java.
@@ -146,16 +146,16 @@
 l.List;%0A
-
 %0Aimport 
@@ -209,16 +209,112 @@
 essage;%0A
+import cn.diaovision.omnicontrol.rx.RxMessage;%0Aimport cn.diaovision.omnicontrol.util.ByteUtils;%0A
 import i
@@ -911,32 +911,47 @@
 splicer;%0A    %7D%0A%0A
+    /*%E8%8E%B7%E5%8F%96%E5%9C%BA%E6%99%AF%E5%88%97%E8%A1%A8*/%0A
     public void 
@@ -992,16 +992,29 @@
 bscriber
+%3CList%3CScene%3E%3E
  subscri
@@ -1254,11 +1254,16 @@
 ildR
-lst
+eadScene
 Mess
@@ -1467,16 +1467,16 @@
       %7D%0A
-
         
@@ -1658,10 +1658,1888 @@
 ;%0A    %7D%0A
+    %0A    /*%E8%B0%83%E7%94%A8%E5%9C%BA%E6%99%AF*/%0A    public void loadScene(final int sceneId,Subscriber%3CRxMessage%3E subscriber)%7B%0A        Flowable.create(new FlowableOnSubscribe%3CRxMessage%3E() %7B%0A            @Override%0A            public void subscribe(FlowableEmitter%3CRxMessage%3E e) throws Exception %7B%0A                SplicerMessage msg=SplicerMessage.buildLoadSceneMessage(sceneId);%0A                List%3Cbyte%5B%5D%3E recvs = splicer.getController().send(msg.toBytes(),msg.toBytes().length,true);%0A                if(recvs.size()%3E0&&ByteUtils.bytes2ascii(recvs.get(recvs.size()-1)).endsWith(%22OK%3E%22))%7B%0A                    e.onNext(new RxMessage(RxMessage.DONE));%0A                %7Delse%7B%0A                    e.onError(new IOException());%0A                %7D%0A            %7D%0A        %7D,BackpressureStrategy.BUFFER)%0A                .subscribeOn(Schedulers.io())%0A                .observeOn(AndroidSchedulers.mainThread())%0A                .subscribe(subscriber);%0A    %7D%0A%0A    /*%E4%BF%AE%E6%94%B9%E5%9C%BA%E6%99%AF%E5%90%8D%E7%A7%B0*/%0A    public void renameScene(final int sceneId, final String name, final int groupId, Subscriber%3CRxMessage%3E subscriber)%7B%0A        Flowable.create(new FlowableOnSubscribe%3CRxMessage%3E() %7B%0A            @Override%0A            public void subscribe(FlowableEmitter%3CRxMessage%3E e) throws Exception %7B%0A                SplicerMessage msg=SplicerMessage.buildRenameSceneMessage(sceneId,name,groupId);%0A                List%3Cbyte%5B%5D%3E recvs=splicer.getController().send(msg.toBytes(),msg.toBytes().length,true);%0A                if(recvs.size()%3E0&&ByteUtils.bytes2ascii(recvs.get(recvs.size()-1)).endsWith(%22OK%3E%22))%7B%0A                    e.onNext(new RxMessage(RxMessage.DONE));%0A                %7Delse%7B%0A                    e.onError(new IOException());%0A                %7D%0A            %7D%0A        %7D,BackpressureStrategy.BUFFER)%0A                .subscribeOn(Schedulers.io())%0A                .observeOn(AndroidSchedulers.mainThread())%0A                .subscribe(subscriber);%0A    %7D%0A
 %7D%0A

add load scene and rename scene methods