*/
/*!
+ \enum QNetworkSession::UsagePolicies
+
+ These flags allow the system to inform the application of network usage restrictions that
+ may be in place.
+
+ \value NoPolicy No policy in force, usage is unrestricted.
+ \value NoBackgroundTrafficPolicy Background network traffic (not user initiated) should be avoided
+ for example to save battery or data charges
+*/
+
+/*!
\fn void QNetworkSession::stateChanged(QNetworkSession::State state)
This signal is emitted whenever the state of the network session changes.
*/
/*!
+ \fn void QNetworkSession::usagePoliciesChanged(UsagePolicies)
+
+ This signal is emitted when the usage policies in force are changed by the system.
+*/
+
+/*!
Constructs a session based on \a connectionConfig with the given \a parent.
\sa QNetworkConfiguration
this, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)));
connect(d, SIGNAL(newConfigurationActivated()),
this, SIGNAL(newConfigurationActivated()));
+ connect(d, SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)),
+ this, SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)));
break;
}
}
qRegisterMetaType<QNetworkSession::State>();
qRegisterMetaType<QNetworkSession::SessionError>();
+ qRegisterMetaType<QNetworkSession::UsagePolicies>();
}
/*!
}
/*!
+ Returns the network usage policies currently in force by the system.
+*/
+QNetworkSession::UsagePolicies QNetworkSession::usagePolicies() const
+{
+ return d ? d->usagePolicies() : QNetworkSession::NoPolicy;
+}
+
+/*!
+ \internal
+ Change usage policies for unit testing.
+ In normal use, the policies are published by the bearer plugin
+*/
+void QNetworkSessionPrivate::setUsagePolicies(QNetworkSession &session, QNetworkSession::UsagePolicies policies)
+{
+ if (!session.d)
+ return;
+ session.d->setUsagePolicies(policies);
+}
+
+/*!
\internal
This function is required to detect whether the client wants to control
InvalidConfigurationError
};
+ enum UsagePolicy {
+ NoPolicy = 0,
+ NoBackgroundTrafficPolicy = 1
+ };
+
+ Q_DECLARE_FLAGS(UsagePolicies, UsagePolicy)
+
explicit QNetworkSession(const QNetworkConfiguration &connConfig, QObject *parent = 0);
virtual ~QNetworkSession();
quint64 bytesWritten() const;
quint64 bytesReceived() const;
quint64 activeTime() const;
-
+
+ QNetworkSession::UsagePolicies usagePolicies() const;
+
bool waitForOpened(int msecs = 30000);
public Q_SLOTS:
void error(QNetworkSession::SessionError);
void preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless);
void newConfigurationActivated();
+ void usagePoliciesChanged(QNetworkSession::UsagePolicies);
protected:
virtual void connectNotify(const char *signal);
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QNetworkSession::State)
Q_DECLARE_METATYPE(QNetworkSession::SessionError)
+Q_DECLARE_METATYPE(QNetworkSession::UsagePolicies)
QT_END_HEADER
virtual quint64 bytesReceived() const = 0;
virtual quint64 activeTime() const = 0;
+ virtual QNetworkSession::UsagePolicies usagePolicies() const = 0;
+ virtual void setUsagePolicies(QNetworkSession::UsagePolicies) = 0;
+
+ static void setUsagePolicies(QNetworkSession&, QNetworkSession::UsagePolicies); //for unit testing
protected:
inline QNetworkConfigurationPrivatePointer privateConfiguration(const QNetworkConfiguration &config) const
{
void closed();
void newConfigurationActivated();
void preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless);
+ void usagePoliciesChanged(QNetworkSession::UsagePolicies);
protected:
QNetworkSession *q;
return Q_UINT64_C(0);
}
+QNetworkSession::UsagePolicies QNetworkSessionPrivateImpl::usagePolicies() const
+{
+ return currentPolicies;
+}
+
+void QNetworkSessionPrivateImpl::setUsagePolicies(QNetworkSession::UsagePolicies newPolicies)
+{
+ if (newPolicies != currentPolicies) {
+ currentPolicies = newPolicies;
+ emit usagePoliciesChanged(currentPolicies);
+ }
+}
+
void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork()
{
QNetworkSession::State oldState = state;
public:
QNetworkSessionPrivateImpl()
- : startTime(0), sessionTimeout(-1)
+ : engine(0), startTime(0), lastError(QNetworkSession::UnknownSessionError), sessionTimeout(-1), currentPolicies(QNetworkSession::NoPolicy), opened(false)
{}
~QNetworkSessionPrivateImpl()
{}
quint64 bytesReceived() const;
quint64 activeTime() const;
+ QNetworkSession::UsagePolicies usagePolicies() const;
+ void setUsagePolicies(QNetworkSession::UsagePolicies);
+
private Q_SLOTS:
void networkConfigurationsChanged();
void configurationChanged(QNetworkConfigurationPrivatePointer config);
QNetworkSession::SessionError lastError;
int sessionTimeout;
+ QNetworkSession::UsagePolicies currentPolicies;
bool opened;
};