% LISTCONNECTIONS list all connections in the repository manager.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: LISTCONNECTIONS list all connections in the repository
%              manager.
%
% CALL:        rm.listConnections
%              listConnections(rm)
%
% <a href="matlab:web(LTPDARepositoryManager.getInfo('listConnections').tohtml, '-helpbrowser')">Parameters Description</a>
%
% VERSION:     $Id: listConnections.m,v 1.4 2011/04/08 08:56:35 hewitson Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = listConnections(varargin)

  % Check if this is a call for parameters
  if utils.helper.isinfocall(varargin{:})
    varargout{1} = getInfo(varargin{3});
    return
  end
  
  rm = varargin{1};
  conns = rm.manager.getConnections;
  for i=1:conns.size
    conn = conns.get(i-1);
    if (conn.isConnected)
      message = sprintf('connected for %2.2f seconds', conn.ageConnected());
    else
      message = 'not connected';
    end
    disp(sprintf('%02d: %s@%s:%s [%s]', i, char(conn.getUsername), ...
      char(conn.getHostname), char(conn.getDatabase), message));
  end
end

%--------------------------------------------------------------------------
% Get Info Object
%--------------------------------------------------------------------------
function ii = getInfo(varargin)
  if nargin == 1 && strcmpi(varargin{1}, 'None')
    sets = {};
    pl   = [];
  else
    sets = {'Default'};
    pl   = getDefaultPlist;
  end
  % Build info object
  ii = minfo(mfilename, 'LTPDARepositoryManager', 'ltpda', utils.const.categories.internal, '$Id: listConnections.m,v 1.4 2011/04/08 08:56:35 hewitson Exp $', sets, pl);
  ii.setModifier(false);
  ii.setOutmin(0);
end

%--------------------------------------------------------------------------
% Get Default Plist
%--------------------------------------------------------------------------
function pl = getDefaultPlist()
  pl = plist();
end
