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

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

  ViewVC Help
Powered by ViewVC