~ubuntu-branches/ubuntu/precise/telepathy-glib/precise-proposed

« back to all changes in this revision

Viewing changes to telepathy-glib/channel-dispatch-operation.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2011-06-22 16:29:01 UTC
  • mfrom: (1.6.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20110622162901-tc492ifcn229lmkh
Tags: 0.15.2-2
Cherry-pick upstream fix to increase timeout of the contact-lists
test on slower architectures like armel, mips, and mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1661
1661
 * @error: a #GError to fill
1662
1662
 *
1663
1663
 * Finishes an async operation initiated using
1664
 
 * tp_channel_dispatch_operation_close_channels_finish().
 
1664
 * tp_channel_dispatch_operation_close_channels_async().
1665
1665
 *
1666
1666
 * Returns: %TRUE if the Claim() call was successful and
1667
1667
 * Close() has at least been attempted on all the channels, otherwise %FALSE
1677
1677
  _tp_implement_finish_void (self, \
1678
1678
      tp_channel_dispatch_operation_close_channels_async)
1679
1679
}
 
1680
 
 
1681
typedef struct
 
1682
{
 
1683
  TpChannelGroupChangeReason reason;
 
1684
  gchar *message;
 
1685
} LeaveChannelsCtx;
 
1686
 
 
1687
static LeaveChannelsCtx *
 
1688
leave_channels_ctx_new (TpChannelGroupChangeReason reason,
 
1689
    const gchar *message)
 
1690
{
 
1691
  LeaveChannelsCtx *ctx = g_slice_new (LeaveChannelsCtx);
 
1692
 
 
1693
  ctx->reason = reason;
 
1694
  ctx->message = g_strdup (message);
 
1695
  return ctx;
 
1696
}
 
1697
 
 
1698
static void
 
1699
leave_channels_ctx_free (LeaveChannelsCtx *ctx)
 
1700
{
 
1701
  g_free (ctx->message);
 
1702
  g_slice_free (LeaveChannelsCtx, ctx);
 
1703
}
 
1704
 
 
1705
static void
 
1706
channel_leave_cb (GObject *source,
 
1707
    GAsyncResult *result,
 
1708
    gpointer user_data)
 
1709
{
 
1710
  GError *error = NULL;
 
1711
 
 
1712
  if (!tp_channel_leave_finish (TP_CHANNEL (source), result, &error))
 
1713
    {
 
1714
      DEBUG ("Failed to leave %s: %s", tp_proxy_get_object_path (source),
 
1715
          error->message);
 
1716
 
 
1717
      g_error_free (error);
 
1718
    }
 
1719
}
 
1720
 
 
1721
static void
 
1722
claim_leave_channels_cb (TpChannelDispatchOperation *self,
 
1723
    GSimpleAsyncResult *result)
 
1724
{
 
1725
  guint i;
 
1726
  LeaveChannelsCtx *ctx;
 
1727
 
 
1728
  ctx = g_simple_async_result_get_op_res_gpointer (result);
 
1729
 
 
1730
  for (i = 0; i < self->priv->channels->len; i++)
 
1731
    {
 
1732
      TpChannel *channel = g_ptr_array_index (self->priv->channels, i);
 
1733
 
 
1734
      tp_channel_leave_async (channel, ctx->reason, ctx->message,
 
1735
          channel_leave_cb, NULL);
 
1736
    }
 
1737
 
 
1738
  g_simple_async_result_complete (result);
 
1739
  g_object_unref (result);
 
1740
}
 
1741
 
 
1742
/**
 
1743
 * tp_channel_dispatch_operation_leave_channels_async:
 
1744
 * @self: a #TpChannelDispatchOperation
 
1745
 * @reason: the leave reason
 
1746
 * @message: the leave message
 
1747
 * @callback: a callback to call when the request has been satisfied
 
1748
 * @user_data: data to pass to @callback
 
1749
 *
 
1750
 * Called by an approver to claim channels and leave them all right away.
 
1751
 * If this method is called successfully, @self has been claimed and
 
1752
 * tp_channel_leave_async() has been called on all of its channels.
 
1753
 *
 
1754
 * If successful, this method will cause the #TpProxy::invalidated signal
 
1755
 * to be emitted, in the same way as for
 
1756
 * tp_channel_dispatch_operation_handle_with_async().
 
1757
 *
 
1758
 * This method may fail because the dispatch operation has already
 
1759
 * been completed. Again, see tp_channel_dispatch_operation_handle_with_async()
 
1760
 * for more details.
 
1761
 *
 
1762
 * Since: 0.15.2
 
1763
 */
 
1764
void
 
1765
tp_channel_dispatch_operation_leave_channels_async (
 
1766
    TpChannelDispatchOperation *self,
 
1767
    TpChannelGroupChangeReason reason,
 
1768
    const gchar *message,
 
1769
    GAsyncReadyCallback callback,
 
1770
    gpointer user_data)
 
1771
{
 
1772
  GSimpleAsyncResult *result;
 
1773
 
 
1774
  result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
 
1775
      tp_channel_dispatch_operation_leave_channels_async);
 
1776
 
 
1777
  g_simple_async_result_set_op_res_gpointer (result,
 
1778
      leave_channels_ctx_new (reason, message),
 
1779
      (GDestroyNotify) leave_channels_ctx_free);
 
1780
 
 
1781
  prepare_core_and_claim (self, claim_leave_channels_cb, result);
 
1782
}
 
1783
 
 
1784
/**
 
1785
 * tp_channel_dispatch_operation_leave_channels_finish:
 
1786
 * @self: a #TpChannelDispatchOperation
 
1787
 * @result: a #GAsyncResult
 
1788
 * @error: a #GError to fill
 
1789
 *
 
1790
 * Finishes an async operation initiated using
 
1791
 * tp_channel_dispatch_operation_leave_channels_async().
 
1792
 *
 
1793
 * Returns: %TRUE if the Claim() call was successful and
 
1794
 * tp_channel_leave_async() has at least been attempted on all the
 
1795
 * channels, otherwise %FALSE
 
1796
 *
 
1797
 * Since: 0.15.2
 
1798
 */
 
1799
gboolean
 
1800
tp_channel_dispatch_operation_leave_channels_finish (
 
1801
    TpChannelDispatchOperation *self,
 
1802
    GAsyncResult *result,
 
1803
    GError **error)
 
1804
{
 
1805
  _tp_implement_finish_void (self, \
 
1806
      tp_channel_dispatch_operation_leave_channels_async)
 
1807
}
 
1808
 
 
1809
static void
 
1810
channel_destroy_cb (GObject *source,
 
1811
    GAsyncResult *result,
 
1812
    gpointer user_data)
 
1813
{
 
1814
  GError *error = NULL;
 
1815
 
 
1816
  if (!tp_channel_destroy_finish (TP_CHANNEL (source), result, &error))
 
1817
    {
 
1818
      DEBUG ("Failed to destroy %s: %s", tp_proxy_get_object_path (source),
 
1819
          error->message);
 
1820
 
 
1821
      g_error_free (error);
 
1822
    }
 
1823
}
 
1824
 
 
1825
static void
 
1826
claim_destroy_channels_cb (TpChannelDispatchOperation *self,
 
1827
    GSimpleAsyncResult *result)
 
1828
{
 
1829
  guint i;
 
1830
 
 
1831
  for (i = 0; i < self->priv->channels->len; i++)
 
1832
    {
 
1833
      TpChannel *channel = g_ptr_array_index (self->priv->channels, i);
 
1834
 
 
1835
      tp_channel_destroy_async (channel, channel_destroy_cb, NULL);
 
1836
    }
 
1837
 
 
1838
  g_simple_async_result_complete (result);
 
1839
  g_object_unref (result);
 
1840
}
 
1841
 
 
1842
/**
 
1843
 * tp_channel_dispatch_operation_destroy_channels_async:
 
1844
 * @self: a #TpChannelDispatchOperation
 
1845
 * @callback: a callback to call when the request has been satisfied
 
1846
 * @user_data: data to pass to @callback
 
1847
 *
 
1848
 * Called by an approver to claim channels and destroy them all right away.
 
1849
 * If this method is called successfully, @self has been claimed and
 
1850
 * tp_channel_destroy_async() has been called on all of its channels.
 
1851
 *
 
1852
 * If successful, this method will cause the #TpProxy::invalidated signal
 
1853
 * to be emitted, in the same way as for
 
1854
 * tp_channel_dispatch_operation_handle_with_async().
 
1855
 *
 
1856
 * This method may fail because the dispatch operation has already
 
1857
 * been completed. Again, see tp_channel_dispatch_operation_handle_with_async()
 
1858
 * for more details.
 
1859
 *
 
1860
 * Since: 0.15.2
 
1861
 */
 
1862
void
 
1863
tp_channel_dispatch_operation_destroy_channels_async (
 
1864
    TpChannelDispatchOperation *self,
 
1865
    GAsyncReadyCallback callback,
 
1866
    gpointer user_data)
 
1867
{
 
1868
  GSimpleAsyncResult *result;
 
1869
 
 
1870
  result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
 
1871
      tp_channel_dispatch_operation_destroy_channels_async);
 
1872
 
 
1873
  prepare_core_and_claim (self, claim_destroy_channels_cb, result);
 
1874
}
 
1875
 
 
1876
/**
 
1877
 * tp_channel_dispatch_operation_destroy_channels_finish:
 
1878
 * @self: a #TpChannelDispatchOperation
 
1879
 * @result: a #GAsyncResult
 
1880
 * @error: a #GError to fill
 
1881
 *
 
1882
 * Finishes an async operation initiated using
 
1883
 * tp_channel_dispatch_operation_destroy_channels_async().
 
1884
 *
 
1885
 * Returns: %TRUE if the Claim() call was successful and
 
1886
 * tp_channel_destroy_async() has at least been attempted on all the
 
1887
 * channels, otherwise %FALSE
 
1888
 *
 
1889
 * Since: 0.15.2
 
1890
 */
 
1891
gboolean
 
1892
tp_channel_dispatch_operation_destroy_channels_finish (
 
1893
    TpChannelDispatchOperation *self,
 
1894
    GAsyncResult *result,
 
1895
    GError **error)
 
1896
{
 
1897
  _tp_implement_finish_void (self, \
 
1898
      tp_channel_dispatch_operation_destroy_channels_async)
 
1899
}