/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/Client.java
ViewVC logotype

Diff of /jlscp/trunk/src/org/linuxsampler/lscp/Client.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1139 by iliev, Mon Apr 2 20:43:58 2007 UTC revision 1340 by iliev, Mon Sep 10 21:26:10 2007 UTC
# Line 69  public class Client { Line 69  public class Client {
69          private String address;          private String address;
70          private int port;          private int port;
71          private Socket sock = null;          private Socket sock = null;
72          private int soTimeout = 10000;          private int soTimeout = 20000;
73                    
74          private LscpInputStream in = null;          private LscpInputStream in = null;
75          private LscpOutputStream out = null;          private LscpOutputStream out = null;
# Line 79  public class Client { Line 79  public class Client {
79          private boolean printOnlyMode = false;          private boolean printOnlyMode = false;
80                    
81          class EventThread extends Thread {          class EventThread extends Thread {
82                    private Vector<String> queue = new Vector<String>();
83                  private boolean terminate = false;                  private boolean terminate = false;
84                                    
85                  EventThread() { super("LSCP-Event-Thread"); }                  EventThread() { super("LSCP-Event-Thread"); }
# Line 86  public class Client { Line 87  public class Client {
87                  public void                  public void
88                  run() {                  run() {
89                          while(!mustTerminate()) {                          while(!mustTerminate()) {
90                                  try { processNotifications(); }                                  try {
91                                  catch(Exception x) {                                          processQueue();
92                                            processNotifications();
93                                    } catch(Exception x) {
94                                          getLogger().log(Level.FINE, x.getMessage(), x);                                          getLogger().log(Level.FINE, x.getMessage(), x);
95                                  }                                  }
96                                  try { synchronized(this) { wait(100); } }                                  try { synchronized(this) { wait(100); } }
# Line 105  public class Client { Line 108  public class Client {
108                          terminate = true;                          terminate = true;
109                          this.notifyAll();                          this.notifyAll();
110                  }                  }
111                    
112                    public synchronized void
113                    scheduleNotification(String s) { queue.add(s); }
114                    
115                    private void
116                    processQueue() {
117                            String[] notifications = popAllNotifications();
118                            for(String n : notifications) fireEvent(n);
119                    }
120                    
121                    private synchronized String[]
122                    popAllNotifications() {
123                            String[] notifications = queue.toArray(new String[queue.size()]);
124                            queue.removeAllElements();
125                            return notifications;
126                    }
127          }          }
128                    
129          /**          /**
# Line 329  public class Client { Line 348  public class Client {
348                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
349                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");
350                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");
351                    if(!llID.isEmpty()) {
352                            subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
353                            subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
354                            subscribe("DB_INSTRUMENT_COUNT");
355                            subscribe("DB_INSTRUMENT_INFO");
356                    }
357                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");
358          }          }
359                    
# Line 376  public class Client { Line 401  public class Client {
401                  String s;                  String s;
402                  for(;;) {                  for(;;) {
403                          s = in.readLine();                          s = in.readLine();
404                          if(s.startsWith("NOTIFY:")) fireEvent(s.substring("NOTIFY:".length()));                          if(s.startsWith("NOTIFY:")) {
405                                    eventThread.scheduleNotification(s.substring("NOTIFY:".length()));
406                            }
407                          else break;                          else break;
408                  }                  }
409                  return s;                  return s;
# Line 469  public class Client { Line 496  public class Client {
496          /** MIDI instrument info listeners */          /** MIDI instrument info listeners */
497          private final Vector<MidiInstrumentInfoListener> llMII =          private final Vector<MidiInstrumentInfoListener> llMII =
498                  new Vector<MidiInstrumentInfoListener>();                  new Vector<MidiInstrumentInfoListener>();
499            private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>();
500          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();
501                    
502                    
# Line 498  public class Client { Line 526  public class Client {
526                          !llMIMI.isEmpty() ||                          !llMIMI.isEmpty() ||
527                          !llMIC.isEmpty()  ||                          !llMIC.isEmpty()  ||
528                          !llMII.isEmpty()  ||                          !llMII.isEmpty()  ||
529                            !llID.isEmpty()   ||
530                          !llGI.isEmpty();                          !llGI.isEmpty();
531          }          }
532                    
533          private void          private synchronized void
534          fireEvent(String s) {          fireEvent(String s) {
535                  if(s.startsWith("CHANNEL_COUNT:")) {                   if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) {
536                            s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length());
537                            InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
538                            for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);
539                    } else if(s.startsWith("DB_INSTRUMENT_DIRECTORY_INFO:")) {
540                            InstrumentsDbEvent e;
541                            s = s.substring("DB_INSTRUMENT_DIRECTORY_INFO:".length());
542                            if(s.startsWith("NAME ")) {
543                                    String[] list;
544                                    try {
545                                            list = parseQuotedStringList(s.substring("NAME ".length()), ' ');
546                                            if(list.length != 2) throw new LscpException();
547                                            e = new InstrumentsDbEvent(this, list[0], list[1]);
548                                            for(InstrumentsDbListener l : llID) {
549                                                    l.directoryNameChanged(e);
550                                            }
551                                    } catch(LscpException x) {
552                                            getLogger().log (
553                                                    Level.WARNING,
554                                                    LscpI18n.getLogMsg("CommandFailed!"),
555                                                    x
556                                            );
557                                    }
558                            } else {
559                                    e = new InstrumentsDbEvent(this, s);
560                                    for(InstrumentsDbListener l : llID) l.directoryInfoChanged(e);
561                            }
562                    } else if(s.startsWith("DB_INSTRUMENT_COUNT:")) {
563                            s = s.substring("DB_INSTRUMENT_COUNT:".length());
564                            InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
565                            for(InstrumentsDbListener l : llID) l.instrumentCountChanged(e);
566                    } else if(s.startsWith("DB_INSTRUMENT_INFO:")) {
567                            InstrumentsDbEvent e;
568                            s = s.substring("DB_INSTRUMENT_INFO:".length());
569                            if(s.startsWith("NAME ")) {
570                                    String[] list;
571                                    try {
572                                            list = parseQuotedStringList(s.substring("NAME ".length()), ' ');
573                                            if(list.length != 2) throw new LscpException();
574                                            e = new InstrumentsDbEvent(this, list[0], list[1]);
575                                            for(InstrumentsDbListener l : llID) {
576                                                    l.instrumentNameChanged(e);
577                                            }
578                                    } catch(LscpException x) {
579                                            getLogger().log (
580                                                    Level.WARNING,
581                                                    LscpI18n.getLogMsg("CommandFailed!"),
582                                                    x
583                                            );
584                                    }
585                            } else {
586                                    e = new InstrumentsDbEvent(this, s);
587                                    for(InstrumentsDbListener l : llID) l.instrumentInfoChanged(e);
588                            }
589                    } else if(s.startsWith("DB_INSTRUMENTS_JOB_INFO:")) {
590                            s = s.substring("DB_INSTRUMENTS_JOB_INFO:".length());
591                            try {
592                                    int i = Integer.parseInt(s);
593                                    InstrumentsDbEvent e = new InstrumentsDbEvent(this, i);
594                                    for(InstrumentsDbListener l : llID) l.jobStatusChanged(e);
595                            } catch(NumberFormatException x) {
596                                    s = "Unknown DB_INSTRUMENTS_JOB_INFO format";
597                                    getLogger().log(Level.WARNING, s, x);
598                            }
599                            
600                    } else if(s.startsWith("CHANNEL_COUNT:")) {
601                          try {                          try {
602                                  int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));                                  int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));
603                                  ChannelCountEvent e = new ChannelCountEvent(this, i);                                  ChannelCountEvent e = new ChannelCountEvent(this, i);
# Line 1145  public class Client { Line 1239  public class Client {
1239          /**          /**
1240           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1241           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1242             * @param l The <code>InstrumentsDbListener</code> to register.
1243             */
1244            public synchronized void
1245            addInstrumentsDbListener(InstrumentsDbListener l) {
1246                    if(llID.isEmpty()) {
1247                            subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1248                            subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1249                            subscribe("DB_INSTRUMENT_COUNT");
1250                            subscribe("DB_INSTRUMENT_INFO");
1251                            subscribe("DB_INSTRUMENTS_JOB_INFO");
1252                    }
1253                    llID.add(l);
1254            }
1255            
1256            /**
1257             * Removes the specified listener.
1258             * Listeners can be removed regardless of the connection state.
1259             * @param l The <code>InstrumentsDbListener</code> to remove.
1260             */
1261            public synchronized void
1262            removeInstrumentsDbListener(InstrumentsDbListener l) {
1263                    boolean b = llID.remove(l);
1264                    if(b && llID.isEmpty()) {
1265                            unsubscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1266                            unsubscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1267                            unsubscribe("DB_INSTRUMENT_COUNT");
1268                            unsubscribe("DB_INSTRUMENT_INFO");
1269                            unsubscribe("DB_INSTRUMENTS_JOB_INFO");
1270                    }
1271            }
1272            
1273            /**
1274             * Registers the specified listener for receiving event messages.
1275             * Listeners can be registered regardless of the connection state.
1276           * @param l The <code>GlobalInfoListener</code> to register.           * @param l The <code>GlobalInfoListener</code> to register.
1277           */           */
1278          public synchronized void          public synchronized void
# Line 1227  public class Client { Line 1355  public class Client {
1355          /**          /**
1356           * Gets detailed information about a specific audio output driver.           * Gets detailed information about a specific audio output driver.
1357           * @param driverName The name of the audio output driver.           * @param driverName The name of the audio output driver.
1358           *           * @param depList An optional list of dependences parameters.
1359           * @return An <code>AudioOutputDriver</code> object containing           * @return An <code>AudioOutputDriver</code> object containing
1360           * information about the specified audio output driver.           * information about the specified audio output driver.
1361           *           *
# Line 1237  public class Client { Line 1365  public class Client {
1365           *           *
1366           * @see #getAudioOutputDriverNames           * @see #getAudioOutputDriverNames
1367           */           */
1368          private synchronized AudioOutputDriver          public synchronized AudioOutputDriver
1369          getAudioOutputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getAudioOutputDriverInfo(String driverName, Parameter... depList)
1370                                            throws IOException, LscpException, LSException {
1371                    
1372                  verifyConnection();                  verifyConnection();
1373                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);
1374                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1248  public class Client { Line 1378  public class Client {
1378                  aod.setName(driverName);                  aod.setName(driverName);
1379                                    
1380                  for(String s : aod.getParameterNames())                  for(String s : aod.getParameterNames())
1381                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s));                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s, depList));
1382                                    
1383                  return aod;                  return aod;
1384          }          }
# Line 1282  public class Client { Line 1412  public class Client {
1412                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
1413                  args.append(' ').append(param);                  args.append(' ').append(param);
1414                                    
1415                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
1416                            if(p.getValue() == null) continue;
1417                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1418                    }
1419                                    
1420                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());
1421                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1344  public class Client { Line 1476  public class Client {
1476                  verifyConnection();                  verifyConnection();
1477                  StringBuffer args = new StringBuffer(aoDriver);                  StringBuffer args = new StringBuffer(aoDriver);
1478                                    
1479                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
1480                            if(p.getValue() == null) continue;
1481                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1482                    }
1483                                    
1484                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());
1485                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 1806  public class Client { Line 1940  public class Client {
1940          /**          /**
1941           * Gets detailed information about a specific MIDI input driver.           * Gets detailed information about a specific MIDI input driver.
1942           * @param driverName The name of the MIDI input driver.           * @param driverName The name of the MIDI input driver.
1943           *           * @param depList An optional list of dependences parameters.
1944           * @return A <code>MidiInputDriver</code> object containing           * @return A <code>MidiInputDriver</code> object containing
1945           * information about the specified MIDI input driver.           * information about the specified MIDI input driver.
1946           *           *
# Line 1816  public class Client { Line 1950  public class Client {
1950           *           *
1951           * @see #getMidiInputDriverNames           * @see #getMidiInputDriverNames
1952           */           */
1953          private synchronized MidiInputDriver          public synchronized MidiInputDriver
1954          getMidiInputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getMidiInputDriverInfo(String driverName, Parameter... depList)
1955                                            throws IOException, LscpException, LSException {
1956                    
1957                  verifyConnection();                  verifyConnection();
1958                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);
1959                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1828  public class Client { Line 1964  public class Client {
1964                  mid.setName(driverName);                  mid.setName(driverName);
1965                                    
1966                  for(String s : mid.getParameterNames())                  for(String s : mid.getParameterNames())
1967                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s));                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s, depList));
1968                                    
1969                  return mid;                  return mid;
1970          }          }
# Line 1862  public class Client { Line 1998  public class Client {
1998                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
1999                  args.append(' ').append(param);                  args.append(' ').append(param);
2000                                    
2001                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
2002                            if(p.getValue() == null) continue;
2003                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2004                    }
2005                                    
2006                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());
2007                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1925  public class Client { Line 2063  public class Client {
2063                  verifyConnection();                  verifyConnection();
2064                  StringBuffer args = new StringBuffer(miDriver);                  StringBuffer args = new StringBuffer(miDriver);
2065                                    
2066                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
2067                            if(p.getValue() == null) continue;
2068                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2069                    }
2070                                    
2071                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());
2072                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 2472  public class Client { Line 2612  public class Client {
2612                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
2613          }          }
2614                    
2615            
2616            
2617          /**          /**
2618           * Creates or replaces a MIDI instrument map entry.           * Creates or replaces a MIDI instrument map entry.
2619           * @param mapId The ID of the map, where this instrument should be mapped.           * @param mapId The ID of the map, where this instrument should be mapped.
# Line 2486  public class Client { Line 2628  public class Client {
2628          public synchronized void          public synchronized void
2629          mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)          mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)
2630                                          throws IOException, LSException, LscpException {                                          throws IOException, LSException, LscpException {
2631                    mapMidiInstrument(mapId, entry, info, false);
2632            }
2633            
2634            /**
2635             * Creates or replaces a MIDI instrument map entry.
2636             * @param mapId The ID of the map, where this instrument should be mapped.
2637             * @param entry Specifies the position of the MIDI instrument in the MIDI instrument map.
2638             * @param info Provides the needed information of the
2639             * MIDI instrument, which will be mapped to the specified MIDI instrument map.
2640             * @param nonModal If <code>true</code> the function returns immediately
2641             * and the mapping is established in the background.
2642             * @throws IOException If some I/O error occurs.
2643             * @throws LSException If the mapping failed.
2644             * @throws LscpException If LSCP protocol corruption occurs.
2645             * @see #unmapMidiInstrument
2646             */
2647            public synchronized void
2648            mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info, boolean nonModal)
2649                                            throws IOException, LSException, LscpException {
2650                                    
2651                  verifyConnection();                  verifyConnection();
2652                  StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");                  StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");
2653                    if(nonModal) cmd.append("NON_MODAL ");
2654                  cmd.append(mapId).append(' ');                  cmd.append(mapId).append(' ');
2655                  cmd.append(entry.getMidiBank()).append(' ');                  cmd.append(entry.getMidiBank()).append(' ');
2656                  cmd.append(entry.getMidiProgram()).append(' ');                  cmd.append(entry.getMidiProgram()).append(' ');
2657                  cmd.append(info.getEngine()).append(" '");                  cmd.append(info.getEngine()).append(" '");
2658                  cmd.append(info.getFileName()).append("' ");                  cmd.append(info.getFilePath()).append("' ");
2659                  cmd.append(info.getInstrumentIndex()).append(' ');                  cmd.append(info.getInstrumentIndex()).append(' ');
2660                  cmd.append(info.getVolume());                  cmd.append(info.getVolume());
2661                  if(!info.getLoadMode().name().equals("DEFAULT")) {                  if(!info.getLoadMode().name().equals("DEFAULT")) {
# Line 2695  public class Client { Line 2857  public class Client {
2857          loadInstrument(String filename, int instrIdx, int samplerChn, boolean nonModal)          loadInstrument(String filename, int instrIdx, int samplerChn, boolean nonModal)
2858                                                  throws IOException, LscpException, LSException {                                                  throws IOException, LscpException, LSException {
2859                                    
2860                    filename = getEscapedString(filename);
2861                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";
2862                  String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn;                  String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn;
2863                                    
# Line 2877  public class Client { Line 3040  public class Client {
3040                  out.writeLine("LIST AVAILABLE_ENGINES");                  out.writeLine("LIST AVAILABLE_ENGINES");
3041                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
3042                                    
3043                  return parseStringList(getSingleLineResultSet().getResult());                  return parseQuotedStringList(getSingleLineResultSet().getResult());
3044          }          }
3045                    
3046          /**          /**
# Line 3568  public class Client { Line 3731  public class Client {
3731          }          }
3732                    
3733          /**          /**
3734             * Starts an instrument editor for editing the loaded instrument
3735             * on the specified sampler channel.
3736             * @param samplerChn The sampler channel number.
3737             * @throws IOException If some I/O error occurs.
3738             * @throws LscpException If LSCP protocol corruption occurs.
3739             * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
3740             * there is no instrument loaded on the specified sampler channel.
3741             * @see #getSamplerChannels
3742             */
3743            public synchronized void
3744            editInstrument(int samplerChn) throws IOException, LscpException, LSException {
3745                    verifyConnection();
3746                    out.writeLine("EDIT INSTRUMENT " + samplerChn);
3747                    if(getPrintOnlyMode()) return;
3748                    
3749                    ResultSet rs = getEmptyResultSet();
3750            }
3751            
3752            
3753            
3754            /**
3755             * Adds the specified directory to the instruments database.
3756             * @param dir The absolute path name of the directory to add.
3757             * @throws IOException If some I/O error occurs.
3758             * @throws LSException If the creation of the directory failed.
3759             * @throws LscpException If LSCP protocol corruption occurs.
3760             */
3761            public synchronized void
3762            addDbDirectory(String dir) throws IOException, LSException, LscpException {
3763                    verifyConnection();
3764                    out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'");
3765                    if(getPrintOnlyMode()) return;
3766                    
3767                    ResultSet rs = getEmptyResultSet();
3768            }
3769            
3770            /**
3771             * Removes the specified directory from the instruments database.
3772             * @param dir The absolute path name of the directory to remove.
3773             * @throws IOException If some I/O error occurs.
3774             * @throws LscpException If LSCP protocol corruption occurs.
3775             * @throws LSException If the specified directory is not
3776             * empty or if the removal of the directory failed.
3777             */
3778            public synchronized void
3779            removeDbDirectory(String dir) throws IOException, LscpException, LSException {
3780                    removeDbDirectory(dir, false);
3781            }
3782            
3783            /**
3784             * Removes the specified directory from the instruments database.
3785             * @param dir The absolute path name of the directory to remove.
3786             * @param force If <code>true</code> forces the removal of non-empty
3787             * directory and all its content.
3788             * @throws IOException If some I/O error occurs.
3789             * @throws LscpException If LSCP protocol corruption occurs.
3790             * @throws LSException If the removing of the directory failed.
3791             */
3792            public synchronized void
3793            removeDbDirectory(String dir, boolean force)
3794                                    throws IOException, LscpException, LSException {
3795                    
3796                    verifyConnection();
3797                    String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3798                    if(force) s += "FORCE ";
3799                    out.writeLine(s + "'" + dir + "'");
3800                    if(getPrintOnlyMode()) return;
3801                    
3802                    ResultSet rs = getEmptyResultSet();
3803            }
3804            
3805            /**
3806             * Removes the specified directories from the instruments database.
3807             * @param dirs The absolute path names of the directories to remove.
3808             * @param force If <code>true</code> forces the removal of non-empty
3809             * directories.
3810             * @throws IOException If some I/O error occurs.
3811             * @throws LscpException If LSCP protocol corruption occurs.
3812             * @throws LSException If the removing of the directores failed.
3813             */
3814            public synchronized void
3815            removeDbDirectories(String[] dirs, boolean force)
3816                                    throws IOException, LscpException, LSException {
3817                    
3818                    verifyConnection();
3819                    String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3820                    if(force) cmd += "FORCE ";
3821                    
3822                    for(String s : dirs) out.writeLine(cmd + "'" + s + "'");
3823                    
3824                    if(getPrintOnlyMode()) return;
3825                    
3826                    getEmptyResultSets(dirs.length, "Client.dirDeletionFailed!");
3827            }
3828            
3829            /**
3830             * Gets the number of directories in the specified directory.
3831             * @return The current number of directories in the specified directory.
3832             * @param dir The absolute path name of the directory.
3833             * @throws IOException If some I/O error occurs.
3834             * @throws LscpException If LSCP protocol corruption occurs.
3835             * @throws LSException If some other error occurs.
3836             */
3837            public synchronized int
3838            getDbDirectoryCount(String dir) throws IOException, LscpException, LSException {
3839                    return getDbDirectoryCount(dir, false);
3840            }
3841            
3842            /**
3843             * Gets the number of directories in the specified directory.
3844             * @return The current number of directories in the specified directory.
3845             * @param dir The absolute path name of the directory.
3846             * @param recursive If <code>true</code>, the number of all directories
3847             * in the specified subtree will be returned.
3848             * @throws IOException If some I/O error occurs.
3849             * @throws LscpException If LSCP protocol corruption occurs.
3850             * @throws LSException If some other error occurs.
3851             */
3852            public synchronized int
3853            getDbDirectoryCount(String dir, boolean recursive)
3854                                    throws IOException, LscpException, LSException {
3855                    
3856                    verifyConnection();
3857                    String s;
3858                    if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
3859                    else s = "GET DB_INSTRUMENT_DIRECTORIES '";
3860                    out.writeLine(s + dir + "'");
3861                    if(getPrintOnlyMode()) return -1;
3862                    
3863                    s = getSingleLineResultSet().getResult();
3864                    return parseInt(s);
3865            }
3866            
3867            /**
3868             * Gets the list of directories in the specified directory.
3869             * @param dir The absolute path name of the directory.
3870             * @return A <code>String</code> array providing the names of
3871             * all directories in the specified directory.
3872             * @throws IOException If some I/O error occurs.
3873             * @throws LscpException If LSCP protocol corruption occurs.
3874             * @throws LSException If the specified path name is invalid.
3875             */
3876            public synchronized String[]
3877            getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
3878                    verifyConnection();
3879                    out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");
3880                    if(getPrintOnlyMode()) return null;
3881                    
3882                    return parseQuotedStringList(getSingleLineResultSet().getResult());
3883            }
3884            
3885            /**
3886             * Gets information about the specified directory.
3887             * @param dir The absolute path name of the directory.
3888             * @return A <code>DbDirectoryInfo</code> instance providing information
3889             * about the specified directory.
3890             * @throws IOException If some I/O error occurs.
3891             * @throws LscpException If LSCP protocol corruption occurs.
3892             * @throws LSException If the specified directory is not found.
3893             */
3894            public synchronized DbDirectoryInfo
3895            getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
3896                    verifyConnection();
3897                    out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'");
3898                    if(getPrintOnlyMode()) return null;
3899                    
3900                    ResultSet rs = getMultiLineResultSet();
3901                    DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());
3902                    if(dir.equals("/")) {
3903                            info.setName("/");
3904                    } else if(dir.length() > 1 && dir.charAt(dir.length() - 1) == '/') {
3905                            dir = dir.substring(0, dir.length() - 1);
3906                    }
3907                    int i = dir.lastIndexOf('/');
3908                    if(i != -1 && i < dir.length() - 1) {
3909                            info.setName(dir.substring(i + 1));
3910                            if(i == 0) info.setParentDirectoryPath("/");
3911                            else info.setParentDirectoryPath(dir.substring(0, i));
3912                    }
3913                    
3914                    return info;
3915            }
3916            
3917            /**
3918             * Gets the list of directories in the specified directory.
3919             * @param dir The absolute path name of the directory.
3920             * @return A <code>DbDirectoryInfo</code> array providing
3921             * information about all directories in the specified directory.
3922             * @throws IOException If some I/O error occurs.
3923             * @throws LscpException If LSCP protocol corruption occurs.
3924             * @throws LSException If the specified path name is invalid.
3925             */
3926            public synchronized DbDirectoryInfo[]
3927            getDbDirectories(String dir) throws IOException, LscpException, LSException {
3928                    String[] dirS = getDbDirectoryNames(dir);
3929                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
3930                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3931                    for(int i = 0; i < dirS.length; i++) infoS[i] = getDbDirectoryInfo(dir + dirS[i]);
3932                    return infoS;
3933            }
3934            
3935            /**
3936             * Gets the list of directories in the specified directory.
3937             * @param dir The absolute path name of the directory.
3938             * @return A <code>DbDirectoryInfo</code> array providing
3939             * information about all directories in the specified directory.
3940             * @throws IOException If some I/O error occurs.
3941             * @throws LscpException If LSCP protocol corruption occurs.
3942             * @throws LSException If the specified path name is invalid.
3943             *
3944            public synchronized DbDirectoryInfo[]
3945            getDbDirectories(String dir) throws IOException, LscpException, LSException {
3946                    String[] dirS = getDbDirectoryNames(dir);
3947                    if(dirS.length == 0) return new DbDirectoryInfo[0];
3948                    
3949                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
3950                    
3951                    for(int i = 0; i < dirS.length; i++) {
3952                            out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'");
3953                    }
3954                    
3955                    if(getPrintOnlyMode()) return null;
3956                    
3957                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
3958                    StringBuffer sb = new StringBuffer();
3959                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3960                    for(int i = 0; i < dirS.length; i++) {
3961                            try {
3962                                    ResultSet rs = getMultiLineResultSet();
3963                                    infoS[i] = new DbDirectoryInfo(rs.getMultiLineResult());
3964                                    infoS[i].setName(dirS[i]);
3965                                    infoS[i].setParentDirectoryPath(dir);
3966                            } catch (SocketTimeoutException e) {
3967                                    getLogger().log(Level.FINE, e.getMessage(), e);
3968                                    sb.append(e.getMessage()).append("\n");
3969                                    break;
3970                            } catch (Exception e) {
3971                                    getLogger().log(Level.FINE, e.getMessage(), e);
3972                                    sb.append(e.getMessage()).append("\n");
3973                            }
3974                    }
3975                    
3976                    String details = sb.toString();
3977                    if(details.length() > 0) {
3978                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
3979                            throw new LSException(0, err, details);
3980                    }
3981                    
3982                    return infoS;
3983            }*/
3984            
3985            /**
3986             * Renames the specified directory.
3987             * @param dir The absolute path name of the directory to rename.
3988             * @param name The new name for the directory.
3989             * @throws IOException If some I/O error occurs.
3990             * @throws LSException If the renaming of the directory failed.
3991             * @throws LscpException If LSCP protocol corruption occurs.
3992             */
3993            public synchronized void
3994            renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
3995                    verifyConnection();
3996                    out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");
3997                    if(getPrintOnlyMode()) return;
3998                    
3999                    ResultSet rs = getEmptyResultSet();
4000            }
4001            
4002            /**
4003             * Moves the specified directory into the specified location.
4004             * @param dir The absolute path name of the directory to move.
4005             * @param dst The location where the directory will be moved to.
4006             * @throws IOException If some I/O error occurs.
4007             * @throws LSException If the operation failed.
4008             * @throws LscpException If LSCP protocol corruption occurs.
4009             */
4010            public synchronized void
4011            moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4012                    verifyConnection();
4013                    out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
4014                    if(getPrintOnlyMode()) return;
4015                    
4016                    ResultSet rs = getEmptyResultSet();
4017            }
4018            
4019            /**
4020             * Moves the specified directories into the specified location.
4021             * @param dirs The absolute path names of the directories to move.
4022             * @param dst The location where the directories will be moved to.
4023             * @throws IOException If some I/O error occurs.
4024             * @throws LSException If the operation failed.
4025             * @throws LscpException If LSCP protocol corruption occurs.
4026             */
4027            public synchronized void
4028            moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
4029                    verifyConnection();
4030                    for(String s : dirs) {
4031                            out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4032                    }
4033                    if(getPrintOnlyMode()) return;
4034                    
4035                    getEmptyResultSets(dirs.length, "Client.dirMovingFailed!");
4036            }
4037            
4038            /**
4039             * Copies the specified directory into the specified location.
4040             * @param dir The absolute path name of the directory to copy.
4041             * @param dst The location where the directory will be copied to.
4042             * @throws IOException If some I/O error occurs.
4043             * @throws LSException If the operation failed.
4044             * @throws LscpException If LSCP protocol corruption occurs.
4045             */
4046            public synchronized void
4047            copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4048                    verifyConnection();
4049                    out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
4050                    if(getPrintOnlyMode()) return;
4051                    
4052                    ResultSet rs = getEmptyResultSet();
4053            }
4054            
4055            /**
4056             * Copies the specified directories into the specified location.
4057             * @param dirs The absolute path names of the directories to copy.
4058             * @param dst The location where the directories will be copied to.
4059             * @throws IOException If some I/O error occurs.
4060             * @throws LSException If the operation failed.
4061             * @throws LscpException If LSCP protocol corruption occurs.
4062             */
4063            public synchronized void
4064            copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4065                    verifyConnection();
4066                    for(String s : dirs) {
4067                            out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4068                    }
4069                    if(getPrintOnlyMode()) return;
4070                    
4071                    getEmptyResultSets(dirs.length, "Client.dirCopyingFailed!");
4072            }
4073            
4074            /**
4075             * Changes the description of the specified directory.
4076             * @param dir The absolute path name of the directory.
4077             * @param desc The new description for the directory.
4078             * @throws IOException If some I/O error occurs.
4079             * @throws LSException If failed to change the description.
4080             * @throws LscpException If LSCP protocol corruption occurs.
4081             */
4082            public synchronized void
4083            setDbDirectoryDescription(String dir, String desc)
4084                                    throws IOException, LSException, LscpException {
4085                    
4086                    verifyConnection();
4087                    String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4088                    out.writeLine(s + dir + "' '" + desc + "'");
4089                    if(getPrintOnlyMode()) return;
4090                    
4091                    ResultSet rs = getEmptyResultSet();
4092            }
4093            
4094            public static enum ScanMode {
4095                    RECURSIVE, NON_RECURSIVE, FLAT
4096            }
4097            
4098            /**
4099             * Adds the specified instrument to the specified instruments database directory.
4100             * @param dbDir The absolute path name of the database directory in which the
4101             * specified instrument will be added.
4102             * @param filePath The absolute path name of the instrument file.
4103             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4104             * @throws IOException If some I/O error occurs.
4105             * @throws LSException If the operation failed.
4106             * @throws LscpException If LSCP protocol corruption occurs.
4107             */
4108            public synchronized void
4109            addDbInstrument(String dbDir, String filePath, int instrIndex)
4110                                            throws IOException, LSException, LscpException {
4111                    
4112                    addDbInstrument(dbDir, filePath, instrIndex, false);
4113            }
4114            
4115            /**
4116             * Adds the specified instrument to the specified instruments database directory.
4117             * @param dbDir The absolute path name of the database directory in which the
4118             * specified instrument will be added.
4119             * @param filePath The absolute path name of the instrument file.
4120             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4121             * @param background If <code>true</code>, the scan will be done
4122             * in background and this method may return before the job is finished.
4123             * @return If <code>background</code> is <code>true</code>, the ID
4124             * of the scan job.
4125             * @throws IOException If some I/O error occurs.
4126             * @throws LSException If the operation failed.
4127             * @throws LscpException If LSCP protocol corruption occurs.
4128             * @see #addInstrumentsDbListener
4129             */
4130            public synchronized int
4131            addDbInstrument(String dbDir, String filePath, int instrIndex, boolean background)
4132                                            throws IOException, LSException, LscpException {
4133                    
4134                    verifyConnection();
4135                    String s = "ADD DB_INSTRUMENTS";
4136                    if(background) s += " NON_MODAL";
4137                    s += " '" + dbDir + "' '" + filePath + "' ";
4138                    out.writeLine(s + String.valueOf(instrIndex));
4139                    if(getPrintOnlyMode()) return -1;
4140                    
4141                    ResultSet rs = getEmptyResultSet();
4142                    return rs.getIndex();
4143            }
4144            
4145            /**
4146             * Adds the instruments in the specified file to the specified
4147             * instruments database directory.
4148             * @param dbDir The absolute path name of the database directory
4149             * in which the the supported instruments will be added.
4150             * @param filePath The absolute path name of the file to scan for instruments.
4151             * @throws IOException If some I/O error occurs.
4152             * @throws LSException If the operation failed.
4153             * @throws LscpException If LSCP protocol corruption occurs.
4154             */
4155            public synchronized void
4156            addDbInstruments(String dbDir, String filePath)
4157                                            throws IOException, LSException, LscpException {
4158                    
4159                    addDbInstruments(dbDir, filePath, false);
4160            }
4161            
4162            /**
4163             * Adds the instruments in the specified file to the specified
4164             * instruments database directory.
4165             * @param dbDir The absolute path name of the database directory
4166             * in which the the supported instruments will be added.
4167             * @param filePath The absolute path name of the file to scan for instruments.
4168             * @param background If <code>true</code>, the scan will be done
4169             * in background and this method may return before the job is finished.
4170             * @return If <code>background</code> is <code>true</code>, the ID
4171             * of the scan job.
4172             * @throws IOException If some I/O error occurs.
4173             * @throws LSException If the operation failed.
4174             * @throws LscpException If LSCP protocol corruption occurs.
4175             * @see #addInstrumentsDbListener
4176             */
4177            public synchronized int
4178            addDbInstruments(String dbDir, String filePath, boolean background)
4179                                            throws IOException, LSException, LscpException {
4180                    
4181                    verifyConnection();
4182                    String s = "ADD DB_INSTRUMENTS";
4183                    if(background) s += " NON_MODAL";
4184                    out.writeLine(s + " '" + dbDir + "' '" + filePath + "'");
4185                    if(getPrintOnlyMode()) return -1;
4186                    
4187                    ResultSet rs = getEmptyResultSet();
4188                    return rs.getIndex();
4189            }
4190            
4191            /**
4192             * Adds the instruments in the specified file system directory
4193             * to the specified instruments database directory.
4194             * @param mode Determines the scanning mode. If RECURSIVE is
4195             * specified, all supported instruments in the specified file system
4196             * direcotry will be added to the specified instruments database
4197             * directory, including the instruments in subdirectories
4198             * of the supplied directory. If NON_RECURSIVE is specified,
4199             * the instruments in the subdirectories will not be processed.
4200             * If FLAT is specified, all supported instruments in the specified
4201             * file system direcotry will be added, including the instruments in
4202             * subdirectories of the supplied directory, but the respective
4203             * subdirectory structure will not be recreated in the instruments
4204             * database and all instruments will be added directly in the
4205             * specified database directory.
4206             * @param dbDir The absolute path name of the database directory
4207             * in which the supported instruments will be added.
4208             * @param fsDir The absolute path name of the file system directory.
4209             * @throws IOException If some I/O error occurs.
4210             * @throws LSException If the operation failed.
4211             * @throws LscpException If LSCP protocol corruption occurs.
4212             */
4213            public synchronized void
4214            addDbInstruments(ScanMode mode, String dbDir, String fsDir)
4215                                            throws IOException, LSException, LscpException {
4216                    
4217                    addDbInstruments(mode, dbDir, fsDir, false);
4218            }
4219            
4220            /**
4221             * Adds the instruments in the specified file system directory
4222             * to the specified instruments database directory.
4223             * @param mode Determines the scanning mode. If RECURSIVE is
4224             * specified, all supported instruments in the specified file system
4225             * direcotry will be added to the specified instruments database
4226             * directory, including the instruments in subdirectories
4227             * of the supplied directory. If NON_RECURSIVE is specified,
4228             * the instruments in the subdirectories will not be processed.
4229             * If FLAT is specified, all supported instruments in the specified
4230             * file system direcotry will be added, including the instruments in
4231             * subdirectories of the supplied directory, but the respective
4232             * subdirectory structure will not be recreated in the instruments
4233             * database and all instruments will be added directly in the
4234             * specified database directory.
4235             * @param dbDir The absolute path name of the database directory
4236             * in which the supported instruments will be added.
4237             * @param fsDir The absolute path name of the file system directory.
4238             * @param background If <code>true</code>, the scan will be done
4239             * in background and this method may return before the job is finished.
4240             * @return If <code>background</code> is <code>true</code>, the ID
4241             * of the scan job.
4242             * @throws IOException If some I/O error occurs.
4243             * @throws LSException If the operation failed.
4244             * @throws LscpException If LSCP protocol corruption occurs.
4245             * @see #addInstrumentsDbListener
4246             */
4247            public synchronized int
4248            addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background)
4249                                            throws IOException, LSException, LscpException {
4250                    
4251                    verifyConnection();
4252                    StringBuffer sb = new StringBuffer("ADD DB_INSTRUMENTS");
4253                    if(background) sb.append(" NON_MODAL");
4254                    
4255                    switch(mode) {
4256                            case RECURSIVE:
4257                                    sb.append(" RECURSIVE");
4258                                    break;
4259                            case NON_RECURSIVE:
4260                                    sb.append(" NON_RECURSIVE");
4261                                    break;
4262                            case FLAT:
4263                                    sb.append(" FLAT");
4264                                    break;
4265                    }
4266                    
4267                    sb.append(" '").append(dbDir).append("' '").append(fsDir).append("'");
4268                    out.writeLine(sb.toString());
4269                    if(getPrintOnlyMode()) return -1;
4270                    
4271                    ResultSet rs = getEmptyResultSet();
4272                    return rs.getIndex();
4273            }
4274            
4275            /**
4276             * Removes the specified instrument from the instruments database.
4277             * @param instr The absolute path name of the instrument to remove.
4278             * @throws IOException If some I/O error occurs.
4279             * @throws LscpException If LSCP protocol corruption occurs.
4280             * @throws LSException If the removing of the instrument failed.
4281             */
4282            public synchronized void
4283            removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4284                    
4285                    verifyConnection();
4286                    out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'");
4287                    if(getPrintOnlyMode()) return;
4288                    
4289                    ResultSet rs = getEmptyResultSet();
4290            }
4291            
4292            /**
4293             * Removes the specified instruments from the instruments database.
4294             * @param instrs The absolute path names of the instruments to remove.
4295             * @throws IOException If some I/O error occurs.
4296             * @throws LscpException If LSCP protocol corruption occurs.
4297             * @throws LSException If the removing of the instruments failed.
4298             */
4299            public synchronized void
4300            removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4301                    verifyConnection();
4302                    for(String s : instrs) {
4303                            out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'");
4304                    }
4305                    if(getPrintOnlyMode()) return;
4306                    
4307                    getEmptyResultSets(instrs.length, "Client.instrDeletionFailed!");
4308            }
4309            
4310            /**
4311             * Gets the number of instruments in the specified directory.
4312             * @return The current number of instruments in the specified directory.
4313             * @param dir The absolute path name of the directory.
4314             * @throws IOException If some I/O error occurs.
4315             * @throws LscpException If LSCP protocol corruption occurs.
4316             * @throws LSException If some other error occurs.
4317             */
4318            public synchronized int
4319            getDbInstrumentCount(String dir) throws IOException, LscpException, LSException {
4320                    return getDbInstrumentCount(dir, false);
4321            }
4322            
4323            /**
4324             * Gets the number of instruments in the specified directory.
4325             * @return The current number of instruments in the specified directory.
4326             * @param dir The absolute path name of the directory.
4327             * @param recursive If <code>true</code>, the number of all instruments
4328             * in the specified subtree will be returned.
4329             * @throws IOException If some I/O error occurs.
4330             * @throws LscpException If LSCP protocol corruption occurs.
4331             * @throws LSException If some other error occurs.
4332             */
4333            public synchronized int
4334            getDbInstrumentCount(String dir, boolean recursive)
4335                                    throws IOException, LscpException, LSException {
4336                    
4337                    verifyConnection();
4338                    String s;
4339                    if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4340                    else s = "GET DB_INSTRUMENTS '";
4341                    out.writeLine(s + dir + "'");
4342                    if(getPrintOnlyMode()) return -1;
4343                    
4344                    s = getSingleLineResultSet().getResult();
4345                    return parseInt(s);
4346            }
4347            
4348            /**
4349             * Gets the list of instruments in the specified directory.
4350             * @param dir The absolute path name of the directory.
4351             * @return A <code>String</code> array providing the names of
4352             * all instruments in the specified directory.
4353             * @throws IOException If some I/O error occurs.
4354             * @throws LscpException If LSCP protocol corruption occurs.
4355             * @throws LSException If the specified path name is invalid.
4356             */
4357            public synchronized String[]
4358            getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4359                    verifyConnection();
4360                    out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");
4361                    if(getPrintOnlyMode()) return null;
4362                    
4363                    return parseQuotedStringList(getSingleLineResultSet().getResult());
4364            }
4365            
4366            /**
4367             * Gets information about the specified instrument.
4368             * @param instr The absolute path name of the instrument.
4369             * @return A <code>DbInstrumentInfo</code> instance providing information
4370             * about the specified instrument.
4371             * @throws IOException If some I/O error occurs.
4372             * @throws LscpException If LSCP protocol corruption occurs.
4373             * @throws LSException If the specified instrument is not found.
4374             */
4375            public synchronized DbInstrumentInfo
4376            getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4377                    verifyConnection();
4378                    out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'");
4379                    if(getPrintOnlyMode()) return null;
4380                    
4381                    ResultSet rs = getMultiLineResultSet();
4382                    DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());
4383                    int i = instr.lastIndexOf('/');
4384                    if(i != -1 && i < instr.length() - 1) {
4385                            info.setName(instr.substring(i + 1));
4386                            if(i == 0) info.setDirectoryPath("/");
4387                            else info.setDirectoryPath(instr.substring(0, i));
4388                    }
4389                    
4390                    return info;
4391            }
4392            
4393            /**
4394             * Gets the list of instruments in the specified directory.
4395             * @param dir The absolute path name of the directory.
4396             * @return A <code>DbInstrumentInfo</code> array providing
4397             * information about all instruments in the specified directory.
4398             * @throws IOException If some I/O error occurs.
4399             * @throws LscpException If LSCP protocol corruption occurs.
4400             * @throws LSException If the specified path name is invalid.
4401             */
4402            public synchronized DbInstrumentInfo[]
4403            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4404                    String[] instrS = getDbInstrumentNames(dir);
4405                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
4406                    
4407                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4408                    for(int i = 0; i < instrS.length; i++) {
4409                            infoS[i] = getDbInstrumentInfo(dir + instrS[i]);
4410                    }
4411                    return infoS;
4412            }
4413            
4414            /**
4415             * Gets the list of instruments in the specified directory.
4416             * @param dir The absolute path name of the directory.
4417             * @return A <code>DbInstrumentInfo</code> array providing
4418             * information about all instruments in the specified directory.
4419             * @throws IOException If some I/O error occurs.
4420             * @throws LscpException If LSCP protocol corruption occurs.
4421             * @throws LSException If the specified path name is invalid.
4422             *
4423            public synchronized DbInstrumentInfo[]
4424            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4425                    String[] instrS = getDbInstrumentNames(dir);
4426                    if(instrS.length == 0) return new DbInstrumentInfo[0];
4427                    
4428                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
4429                    
4430                    for(int i = 0; i < instrS.length; i++) {
4431                            out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'");
4432                    }
4433                    
4434                    if(getPrintOnlyMode()) return null;
4435                    
4436                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
4437                    StringBuffer sb = new StringBuffer();
4438                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4439                    for(int i = 0; i < instrS.length; i++) {
4440                            try {
4441                                    ResultSet rs = getMultiLineResultSet();
4442                                    infoS[i] = new DbInstrumentInfo(rs.getMultiLineResult());
4443                                    infoS[i].setName(instrS[i]);
4444                                    infoS[i].setDirectoryPath(dir);
4445                            } catch (SocketTimeoutException e) {
4446                                    getLogger().log(Level.FINE, e.getMessage(), e);
4447                                    sb.append(e.getMessage()).append("\n");
4448                                    break;
4449                            } catch (Exception e) {
4450                                    getLogger().log(Level.FINE, e.getMessage(), e);
4451                                    sb.append(e.getMessage()).append("\n");
4452                            }
4453                    }
4454                    
4455                    String details = sb.toString();
4456                    if(details.length() > 0) {
4457                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
4458                            throw new LSException(0, err, details);
4459                    }
4460                    
4461                    return infoS;
4462            }*/
4463            
4464            /**
4465             * Renames the specified instrument.
4466             * @param instr The absolute path name of the instrument to rename.
4467             * @param name The new name for the instrument.
4468             * @throws IOException If some I/O error occurs.
4469             * @throws LSException If the renaming of the instrument failed.
4470             * @throws LscpException If LSCP protocol corruption occurs.
4471             */
4472            public synchronized void
4473            renameDbInstrument(String instr, String name)
4474                                    throws IOException, LSException, LscpException {
4475                    
4476                    verifyConnection();
4477                    out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");
4478                    if(getPrintOnlyMode()) return;
4479                    
4480                    ResultSet rs = getEmptyResultSet();
4481            }
4482            
4483            /**
4484             * Moves the specified instrument into the specified location.
4485             * @param instr The absolute path name of the instrument to move.
4486             * @param dst The directory where the specified instrument will be moved to.
4487             * @throws IOException If some I/O error occurs.
4488             * @throws LSException If the operation failed.
4489             * @throws LscpException If LSCP protocol corruption occurs.
4490             */
4491            public synchronized void
4492            moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4493                    verifyConnection();
4494                    out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4495                    if(getPrintOnlyMode()) return;
4496                    
4497                    ResultSet rs = getEmptyResultSet();
4498            }
4499            
4500            /**
4501             * Moves the specified instruments into the specified location.
4502             * @param instrs The absolute path names of the instruments to move.
4503             * @param dst The directory where the specified instruments will be moved to.
4504             * @throws IOException If some I/O error occurs.
4505             * @throws LSException If the operation failed.
4506             * @throws LscpException If LSCP protocol corruption occurs.
4507             */
4508            public synchronized void
4509            moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4510                    verifyConnection();
4511                    for(String s : instrs) {
4512                            out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'");
4513                    }
4514                    if(getPrintOnlyMode()) return;
4515                    
4516                    getEmptyResultSets(instrs.length, "Client.instrMovingFailed!");
4517            }
4518            
4519            /**
4520             * Copies the specified instrument into the specified location.
4521             * @param instr The absolute path name of the instrument to copy.
4522             * @param dst The directory where the specified instrument will be copied to.
4523             * @throws IOException If some I/O error occurs.
4524             * @throws LSException If the operation failed.
4525             * @throws LscpException If LSCP protocol corruption occurs.
4526             */
4527            public synchronized void
4528            copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4529                    verifyConnection();
4530                    out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4531                    if(getPrintOnlyMode()) return;
4532                    
4533                    ResultSet rs = getEmptyResultSet();
4534            }
4535            
4536            /**
4537             * Copies the specified instruments into the specified location.
4538             * @param instrs The absolute path name of the instruments to copy.
4539             * @param dst The directory where the specified instruments will be copied to.
4540             * @throws IOException If some I/O error occurs.
4541             * @throws LSException If the operation failed.
4542             * @throws LscpException If LSCP protocol corruption occurs.
4543             */
4544            public synchronized void
4545            copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4546                    verifyConnection();
4547                    for(String s : instrs) {
4548                            out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'");
4549                    }
4550                    if(getPrintOnlyMode()) return;
4551                    
4552                    getEmptyResultSets(instrs.length, "Client.instrCopyingFailed!");
4553            }
4554            
4555            /**
4556             * Changes the description of the specified instrument.
4557             * @param instr The absolute path name of the instrument.
4558             * @param desc The new description for the instrument.
4559             * @throws IOException If some I/O error occurs.
4560             * @throws LSException If failed to change the description.
4561             * @throws LscpException If LSCP protocol corruption occurs.
4562             */
4563            public synchronized void
4564            setDbInstrumentDescription(String instr, String desc)
4565                                    throws IOException, LSException, LscpException {
4566                    
4567                    verifyConnection();
4568                    out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");
4569                    if(getPrintOnlyMode()) return;
4570                    
4571                    ResultSet rs = getEmptyResultSet();
4572            }
4573            
4574            /**
4575             * Finds all directories in the specified directory
4576             * that corresponds to the specified search criterias.
4577             * @param dir The absolute path name of the directory to search.
4578             * @param query Provides the search criterias.
4579             * @return A <code>DbDirectoryInfo</code> array providing
4580             * information about all directories that are found in the specified directory.
4581             * @throws IOException If some I/O error occurs.
4582             * @throws LscpException If LSCP protocol corruption occurs.
4583             * @throws LSException If the specified path name is invalid.
4584             */
4585            public synchronized DbDirectoryInfo[]
4586            findDbDirectories(String dir, DbSearchQuery query)
4587                                    throws IOException, LscpException, LSException {
4588                    
4589                    return findDbDirectories(dir, query, false);
4590            }
4591            
4592            /**
4593             * Finds all directories in the specified directory
4594             * that corresponds to the specified search criterias.
4595             * @param dir The absolute path name of the directory to search.
4596             * @param query Provides the search criterias.
4597             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4598             * @return A <code>DbDirectoryInfo</code> array providing
4599             * information about all directories that are found in the specified directory.
4600             * @throws IOException If some I/O error occurs.
4601             * @throws LscpException If LSCP protocol corruption occurs.
4602             * @throws LSException If the specified path name is invalid.
4603             */
4604            public synchronized DbDirectoryInfo[]
4605            findDbDirectories(String dir, DbSearchQuery query, boolean nonRecursive)
4606                                    throws IOException, LscpException, LSException {
4607                    
4608                    verifyConnection();
4609                    StringBuffer sb = new StringBuffer();
4610                    sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4611                    if(nonRecursive) sb.append(" NON_RECURSIVE");
4612                    sb.append(" '").append(dir).append("'");
4613                    
4614                    if(query.name != null && query.name.length() > 0) {
4615                            sb.append(" NAME='").append(query.name).append("'");
4616                    }
4617                    
4618                    String s = query.getCreatedAfter();
4619                    String s2 = query.getCreatedBefore();
4620                    if(s != null || s2 != null) {
4621                            sb.append(" CREATED='");
4622                            if(s != null) sb.append(s);
4623                            sb.append("..");
4624                            if(s2 != null) sb.append(s2);
4625                            sb.append("'");
4626                    }
4627                    
4628                    s = query.getModifiedAfter();
4629                    s2 = query.getModifiedBefore();
4630                    if(s != null || s2 != null) {
4631                            sb.append(" MODIFIED='");
4632                            if(s != null) sb.append(s);
4633                            sb.append("..");
4634                            if(s2 != null) sb.append(s2);
4635                            sb.append("'");
4636                    }
4637                    
4638                    if(query.description != null && query.description.length() > 0) {
4639                            sb.append(" DESCRIPTION='").append(query.description).append("'");
4640                    }
4641                    
4642                    out.writeLine(sb.toString());
4643                    if(getPrintOnlyMode()) return null;
4644                    
4645                    String[] dirS = parseQuotedStringList(getSingleLineResultSet().getResult());
4646                    
4647                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4648                    for(int i = 0; i < dirS.length; i++) {
4649                            infoS[i] = getDbDirectoryInfo(dirS[i]);
4650                    }
4651                    return infoS;
4652            }
4653            
4654            /**
4655             * Finds all instruments in the specified directory
4656             * that corresponds to the specified search criterias.
4657             * @param dir The absolute path name of the directory to search.
4658             * @param query Provides the search criterias.
4659             * @return A <code>DbInstrumentInfo</code> array providing
4660             * information about all instruments that are found in the specified directory.
4661             * @throws IOException If some I/O error occurs.
4662             * @throws LscpException If LSCP protocol corruption occurs.
4663             * @throws LSException If the specified path name is invalid.
4664             */
4665            public synchronized DbInstrumentInfo[]
4666            findDbInstruments(String dir, DbSearchQuery query)
4667                                    throws IOException, LscpException, LSException {
4668                    
4669                    return findDbInstruments(dir, query, false);
4670            }
4671            
4672            /**
4673             * Finds all instruments in the specified directory
4674             * that corresponds to the specified search criterias.
4675             * @param dir The absolute path name of the directory to search.
4676             * @param query Provides the search criterias.
4677             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4678             * @return A <code>DbInstrumentInfo</code> array providing
4679             * information about all instruments that are found in the specified directory.
4680             * @throws IOException If some I/O error occurs.
4681             * @throws LscpException If LSCP protocol corruption occurs.
4682             * @throws LSException If the specified path name is invalid.
4683             */
4684            public synchronized DbInstrumentInfo[]
4685            findDbInstruments(String dir, DbSearchQuery query, boolean nonRecursive)
4686                                    throws IOException, LscpException, LSException {
4687                    
4688                    verifyConnection();
4689                    StringBuffer sb = new StringBuffer();
4690                    sb.append("FIND DB_INSTRUMENTS");
4691                    if(nonRecursive) sb.append(" NON_RECURSIVE");
4692                    sb.append(" '").append(dir).append("'");
4693                    
4694                    if(query.name != null && query.name.length() > 0) {
4695                            sb.append(" NAME='").append(query.name).append("'");
4696                    }
4697                    
4698                    if(query.formatFamilies.size() > 0) {
4699                            sb.append(" FORMAT_FAMILIES='").append(query.formatFamilies.get(0));
4700                            for(int i = 1; i < query.formatFamilies.size(); i++) {
4701                                    sb.append(',').append(query.formatFamilies.get(i));
4702                            }
4703                            sb.append("'");
4704                    }
4705                    
4706                    if(query.minSize != -1 || query.maxSize != -1) {
4707                            sb.append(" SIZE='");
4708                            if(query.minSize != -1) sb.append(query.minSize);
4709                            sb.append("..");
4710                            if(query.maxSize != -1) sb.append(query.maxSize);
4711                            sb.append("'");
4712                    }
4713                    
4714                    String s = query.getCreatedAfter();
4715                    String s2 = query.getCreatedBefore();
4716                    if(s != null || s2 != null) {
4717                            sb.append(" CREATED='");
4718                            if(s != null) sb.append(s);
4719                            sb.append("..");
4720                            if(s2 != null) sb.append(s2);
4721                            sb.append("'");
4722                    }
4723                    
4724                    s = query.getModifiedAfter();
4725                    s2 = query.getModifiedBefore();
4726                    if(s != null || s2 != null) {
4727                            sb.append(" MODIFIED='");
4728                            if(s != null) sb.append(s);
4729                            sb.append("..");
4730                            if(s2 != null) sb.append(s2);
4731                            sb.append("'");
4732                    }
4733                    
4734                    if(query.description != null && query.description.length() > 0) {
4735                            sb.append(" DESCRIPTION='").append(query.description).append("'");
4736                    }
4737                    
4738                    if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
4739                            sb.append(" IS_DRUM=");
4740                            if(query.instrumentType == DbSearchQuery.InstrumentType.DRUM) {
4741                                    sb.append("'true'");
4742                            } else {
4743                                    sb.append("'false'");
4744                            }
4745                    }
4746                    
4747                    if(query.product != null && query.product.length() > 0) {
4748                            sb.append(" PRODUCT='").append(query.product).append("'");
4749                    }
4750                    
4751                    if(query.artists != null && query.artists.length() > 0) {
4752                            sb.append(" ARTISTS='").append(query.artists).append("'");
4753                    }
4754                    
4755                    if(query.keywords != null && query.keywords.length() > 0) {
4756                            sb.append(" KEYWORDS='").append(query.keywords).append("'");
4757                    }
4758                    
4759                    out.writeLine(sb.toString());
4760                    if(getPrintOnlyMode()) return null;
4761                    
4762                    String[] instrS = parseQuotedStringList(getSingleLineResultSet().getResult());
4763                    
4764                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4765                    for(int i = 0; i < instrS.length; i++) {
4766                            infoS[i] = getDbInstrumentInfo(instrS[i]);
4767                    }
4768                    return infoS;
4769            }
4770            
4771            /**
4772             * Gets status information about the specified job.
4773             * @param jobId The ID of the job.
4774             * @return A <code>ScanJobInfo</code> instance providing information
4775             * about the specified job.
4776             * @throws IOException If some I/O error occurs.
4777             * @throws LscpException If LSCP protocol corruption occurs.
4778             * @throws LSException If the specified job is not found.
4779             */
4780            public synchronized ScanJobInfo
4781            getDbInstrumentsJobInfo(int jobId) throws IOException, LscpException, LSException {
4782                    verifyConnection();
4783                    out.writeLine("GET DB_INSTRUMENTS_JOB INFO " + String.valueOf(jobId));
4784                    if(getPrintOnlyMode()) return null;
4785                    
4786                    ResultSet rs = getMultiLineResultSet();
4787                    ScanJobInfo info = new ScanJobInfo(rs.getMultiLineResult());
4788                    
4789                    return info;
4790            }
4791            
4792            /**
4793           * Resets the specified sampler channel.           * Resets the specified sampler channel.
4794           *           *
4795           * @param samplerChn The sampler channel number.           * @param samplerChn The sampler channel number.
# Line 3692  public class Client { Line 4914  public class Client {
4914                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
4915          }          }
4916                    
4917            private void
4918            getEmptyResultSets(int count, String err) throws LSException {
4919                    StringBuffer sb = new StringBuffer();
4920                    for(int i = 0; i < count; i++) {
4921                            try { getEmptyResultSet(); }
4922                            catch (SocketTimeoutException e) {
4923                                    getLogger().log(Level.FINE, e.getMessage(), e);
4924                                    sb.append(e.getMessage()).append("\n");
4925                                    break;
4926                            } catch (Exception e) {
4927                                    getLogger().log(Level.FINE, e.getMessage(), e);
4928                                    sb.append(e.getMessage()).append("\n");
4929                            }
4930                    }
4931                    
4932                    String details = sb.toString();
4933                    if(details.length() > 0) {
4934                            String s = LscpI18n.getLogMsg(err);
4935                            throw new LSException(0, s, details);
4936                    }
4937            }
4938            
4939          /**          /**
4940           * Returns the logger for this library.           * Returns the logger for this library.
4941           * @return The logger for this library.           * @return The logger for this library.

Legend:
Removed from v.1139  
changed lines
  Added in v.1340

  ViewVC Help
Powered by ViewVC