Back to index

unity  6.0.0
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
unity::dash::HomeLens::ResultsMerger Class Reference
Inheritance diagram for unity::dash::HomeLens::ResultsMerger:
Inheritance graph
[legend]
Collaboration diagram for unity::dash::HomeLens::ResultsMerger:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ResultsMerger (glib::Object< DeeModel > target, HomeLens::CategoryRegistry *cat_registry)
void AddSource (glib::Object< DeeModel > source)

Protected Member Functions

void OnSourceRowAdded (DeeModel *model, DeeModelIter *iter)
void OnSourceRowRemoved (DeeModel *model, DeeModelIter *iter)
void OnSourceRowChanged (DeeModel *model, DeeModelIter *iter)
void CheckCategoryRegistryDirty ()
void EnsureRowBuf (DeeModel *source)
DeeModelTag * FindSourceToTargetTag (DeeModel *model)

Protected Attributes

glib::SignalManager sig_manager_
GVariant ** row_buf_
unsigned int n_cols_
glib::Object< DeeModel > target_
std::map< DeeModel
*, DeeModelTag * > 
source_to_target_tags_

Private Attributes

HomeLens::CategoryRegistrycat_registry_

Detailed Description

Definition at line 223 of file HomeLens.cpp.


Constructor & Destructor Documentation

Definition at line 310 of file HomeLens.cpp.

  : HomeLens::ModelMerger::ModelMerger(target)
  , cat_registry_(cat_registry)
{}

Member Function Documentation

void unity::dash::HomeLens::ModelMerger::AddSource ( glib::Object< DeeModel >  source) [inherited]

Definition at line 333 of file HomeLens.cpp.

{
  typedef glib::Signal<void, DeeModel*, DeeModelIter*> RowSignalType;

  if (!source)
  {
    LOG_ERROR(logger) << "Trying to add NULL source to ModelMerger";
    return;
  }

  DeeModelTag* merger_tag = dee_model_register_tag(source, NULL);
  source_to_target_tags_[source.RawPtr()] = merger_tag;

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                     "row-added",
                                     sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowAdded)));

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                       "row-removed",
                                       sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowRemoved)));

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                       "row-changed",
                                       sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowChanged)));
}

Here is the call graph for this function:

Definition at line 623 of file HomeLens.cpp.

{
  DeeModel* source;
  DeeModelTag* target_tag;
  const unsigned int CATEGORY_COLUMN = 2;
  std::map<DeeModel*,DeeModelTag*>::iterator i, end;

  if (G_LIKELY(!cat_registry_->CheckDirty()))
    return;

  LOG_DEBUG(logger) << "Category registry marked dirty. Fixing category offsets.";

  /*
   * Iterate over all results in each source model and re-calculate the
   * the category offset in the corresponding rows in the target model
   */
  for (i = source_to_target_tags_.begin(), end = source_to_target_tags_.end();
       i != end; i++)
  {
    source = i->first;
    target_tag = i->second;

    DeeModelIter* source_iter = dee_model_get_first_iter(source);
    DeeModelIter* source_end = dee_model_get_last_iter(source);

    for (source_iter = dee_model_get_first_iter(source), source_end = dee_model_get_last_iter(source);
         source_iter != source_end;
         source_iter = dee_model_next(source, source_iter))
    {
      DeeModelIter* target_iter = static_cast<DeeModelIter*>(dee_model_get_tag(source, source_iter, target_tag));

      /* No guarantee that rows in the source are mapped to the target */
      if (target_iter == NULL)
        continue;

      unsigned int source_cat_offset = dee_model_get_uint32(source, source_iter, CATEGORY_COLUMN);
      int cat_offset = cat_registry_->FindCategoryOffset(source, source_cat_offset);

      if (G_LIKELY(cat_offset >= 0))
      {
        dee_model_set_value(target_, target_iter, CATEGORY_COLUMN,
                            g_variant_new_uint32(cat_offset));
      }
      else
      {
        LOG_ERROR(logger) << "No registered category id for category "
            << source_cat_offset << " on result source model "
            << source << ".";
        /* We can't really recover from this :-( */
      }
    }
  }
}
void unity::dash::HomeLens::ModelMerger::EnsureRowBuf ( DeeModel *  source) [protected, inherited]

Definition at line 557 of file HomeLens.cpp.

{
  if (G_UNLIKELY (n_cols_ == 0))
  {
    /* We have two things to accomplish here.
     * 1) Allocate the row_buf_, and
     * 2) Make sure that the target model has the correct schema set.
     *
     * INVARIANT: n_cols_ == 0 iff row_buf_ == NULL.
     */

    n_cols_ = dee_model_get_n_columns(model);

    if (n_cols_ == 0)
    {
      LOG_ERROR(logger) << "Source model has not provided a schema for the model merger!";
      return;
    }

    /* Lazily adopt schema from source if we don't have one.
     * If we do have a schema let's validate that they match the source */
    if (dee_model_get_n_columns(target_) == 0)
    {
      dee_model_set_schema_full(target_,
                                dee_model_get_schema(model, NULL),
                                n_cols_);
    }
    else
    {
      unsigned int n_cols1;
      const gchar* const *schema1 = dee_model_get_schema(target_, &n_cols1);
      const gchar* const *schema2 = dee_model_get_schema(model, NULL);

      /* At the very least we should have an equal number of rows */
      if (n_cols_ != n_cols1)
      {
        LOG_ERROR(logger) << "Schema mismatch between source and target model. Expected "
                          << n_cols1 << " columns, but found "
                          << n_cols_ << ".";
        n_cols_ = 0;
        return;
      }

      /* Compare schemas */
      for (unsigned int i = 0; i < n_cols_; i++)
      {
        if (g_strcmp0(schema1[i], schema2[i]) != 0)
        {
          LOG_ERROR(logger) << "Schema mismatch between source and target model. Expected column "
                            << i << " to be '" << schema1[i] << "', but found '"
                            << schema2[i] << "'.";
          n_cols_ = 0;
          return;
        }
      }
    }

    row_buf_ = g_new0 (GVariant*, n_cols_);
  }
}
DeeModelTag * unity::dash::HomeLens::ModelMerger::FindSourceToTargetTag ( DeeModel *  model) [protected, inherited]

Definition at line 618 of file HomeLens.cpp.

{
  return source_to_target_tags_[model];
}
void unity::dash::HomeLens::ResultsMerger::OnSourceRowAdded ( DeeModel *  model,
DeeModelIter *  iter 
) [protected, virtual]

Reimplemented from unity::dash::HomeLens::ModelMerger.

Definition at line 364 of file HomeLens.cpp.

{
  DeeModelIter* target_iter;
  DeeModelTag*  target_tag;
  int target_cat_offset, source_cat_offset;
  const unsigned int CATEGORY_COLUMN = 2;

  EnsureRowBuf(model);
  CheckCategoryRegistryDirty();

  dee_model_get_row (model, iter, row_buf_);
  target_tag = FindSourceToTargetTag(model);

  /* Update the row with the corrected category offset */
  source_cat_offset = dee_model_get_uint32(model, iter, CATEGORY_COLUMN);
  target_cat_offset = cat_registry_->FindCategoryOffset(model, source_cat_offset);

  if (target_cat_offset >= 0)
  {
    g_variant_unref (row_buf_[CATEGORY_COLUMN]);
    row_buf_[CATEGORY_COLUMN] = g_variant_new_uint32(target_cat_offset);

    /* Sink the ref on the new row member. By Dee API contract they must all
     * be strong refs, not floating */
    g_variant_ref_sink(row_buf_[CATEGORY_COLUMN]);

    target_iter = dee_model_append_row (target_, row_buf_);
    dee_model_set_tag(model, iter, target_tag, target_iter);

    LOG_DEBUG(logger) << "Found " << dee_model_get_string(model, iter, 0)
                      << " (source cat " << source_cat_offset << ", target cat "
                      << target_cat_offset << ")";
  }
  else
  {
    LOG_ERROR(logger) << "No category registered for model "
                      << model << ", source offset " << source_cat_offset
                      << ": " << dee_model_get_string(model, iter, 0);
  }

  for (unsigned int i = 0; i < n_cols_; i++) g_variant_unref(row_buf_[i]);
}
void unity::dash::HomeLens::ResultsMerger::OnSourceRowChanged ( DeeModel *  model,
DeeModelIter *  iter 
) [protected, virtual]

Reimplemented from unity::dash::HomeLens::ModelMerger.

Definition at line 546 of file HomeLens.cpp.

{
  // FIXME: We can support this, but we need to re-calculate the category offset
  LOG_WARN(logger) << "In-line changing of results not supported in the home lens. Sorry.";
}
void unity::dash::HomeLens::ResultsMerger::OnSourceRowRemoved ( DeeModel *  model,
DeeModelIter *  iter 
) [protected, virtual]

Reimplemented from unity::dash::HomeLens::ModelMerger.

Definition at line 517 of file HomeLens.cpp.

Here is the call graph for this function:


Member Data Documentation

Definition at line 236 of file HomeLens.cpp.

unsigned int unity::dash::HomeLens::ModelMerger::n_cols_ [protected, inherited]

Definition at line 206 of file HomeLens.cpp.

GVariant** unity::dash::HomeLens::ModelMerger::row_buf_ [protected, inherited]

Definition at line 205 of file HomeLens.cpp.

Definition at line 204 of file HomeLens.cpp.

std::map<DeeModel*,DeeModelTag*> unity::dash::HomeLens::ModelMerger::source_to_target_tags_ [protected, inherited]

Definition at line 208 of file HomeLens.cpp.

Definition at line 207 of file HomeLens.cpp.


The documentation for this class was generated from the following file: