blob: 20e327372539cebc21d818a13c640060dcd84c3f [file] [log] [blame]
// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <base/macros.h>
#include <cromo/modem_handler.h>
#include <dbus-c++/types.h>
#include "gobi-cromo-plugin/gobi_modem.h"
class DeviceWatcher;
namespace gobi {
class Sdk;
} // namespace gobi
// This class cares about two orthogonal kinds of path: control paths and DBus
// paths. Control paths are only used internally, and are the names of the qcqmi
// device the modem is associated with (e.g., /dev/qcqmi0); DBus paths are used
// externally and are associated with DBus objects (e.g.
// /org/chromium/ModemManager/Gobi/0). Public methods always deal in DBus paths,
// and private methods always deal in control paths.
class GobiModemHandler : public ModemHandler {
explicit GobiModemHandler(CromoServer& server);
virtual ~GobiModemHandler();
virtual std::vector<DBus::Path> EnumerateDevices(DBus::Error& error);
virtual bool Initialize();
void HandleUdevMessage(const char *action, const char *device);
void HandlePollEvent();
void ExitLeavingModemsForCleanup();
GobiModem* LookupByDbusPath(const std::string& dbuspath);
void Remove(GobiModem *m);
typedef std::map<std::string, GobiModem *> ControlPathToModem;
bool DevicePresentByControlPath(const char *path);
void RemoveDeviceByControlPath(const char *path);
RemoveDeviceByIterator(ControlPathToModem::iterator p);
// On clean exit clear the list of devices that need to be reset
void ClearDeviceListFile();
// Write a list of devices to a file so that upstart can reset the
// devices if we exit unexpectedly.
void WriteDeviceListFile(const ControlPathToModem &modems);
bool GetDeviceList();
void MonitorDevices();
ControlPathToModem control_path_to_modem_;
bool clear_device_list_on_destroy_;
DeviceWatcher *device_watcher_;
ControlPathToModem key_to_modem_;
int scan_generation_;
std::unique_ptr<gobi::Sdk> sdk_;