NUGU SDK Linux  1.7.5
capability.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 SK Telecom Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __NUGU_CAPABILITY_H__
18 #define __NUGU_CAPABILITY_H__
19 
20 #include <algorithm>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include <base/nugu_event.h>
28 
29 namespace NuguClientKit {
30 
46 class Capability;
47 
52 public:
53  explicit CapabilityEvent(const std::string& name, Capability* cap);
54  virtual ~CapabilityEvent();
55 
60  std::string getName();
61 
66  std::string getDialogRequestId();
67 
72  std::string getMessageId();
73 
78  void setDialogRequestId(const std::string& id);
79 
84  void setType(enum nugu_event_type type);
85 
90  void setMimeType(const std::string& type);
91 
95  void forceClose();
96 
102  void sendEvent(const std::string& context, const std::string& payload);
103 
110  void sendAttachmentEvent(bool is_end, size_t size, unsigned char* data);
111 
112 private:
113  struct Impl;
114  std::unique_ptr<Impl> pimpl;
115 };
116 
120 class Capability : virtual public ICapabilityInterface {
121 public:
122  explicit Capability(const std::string& name, const std::string& ver = "1.0");
123  virtual ~Capability();
124 
130 
134  void initialize() override;
135 
139  void deInitialize() override;
140 
146 
150  void suspend() override;
151 
155  void restore() override;
156 
162  void addEventResultCallback(const std::string& ename, EventResultCallback callback) override;
163 
168  void removeEventResultCallback(const std::string& ename) override;
169 
174  void notifyEventResult(const std::string& event_desc) override;
175 
182  void notifyEventResponse(const std::string& msg_id, const std::string& data, bool success) override;
183 
189  void addReferrerEvents(const std::string& ename, const std::string& dname);
190 
196  void addBlockingPolicy(const std::string& dname, BlockingPolicy policy);
197 
203  std::string getReferrerDialogRequestId(const std::string& ename);
204 
210  void setReferrerDialogRequestId(const std::string& dname, const std::string& id);
211 
216  void setName(const std::string& name);
217 
222  std::string getName() override;
223 
228  void setVersion(const std::string& ver);
229 
234  std::string getVersion() override;
235 
241  std::string getPlayServiceIdInStackControl(const NJson::Value& playstack_control);
242 
248  std::string getPlayServiceIdInStackControl(const char* payload);
249 
254  InteractionMode getInteractionMode(const NJson::Value& interaction_control);
255 
260  void preprocessDirective(NuguDirective* ndir) override;
261 
266  void cancelDirective(NuguDirective* ndir) override;
267 
272  void processDirective(NuguDirective* ndir) override final;
273 
279  void destroyDirective(NuguDirective* ndir, bool is_cancel = false);
280 
286 
294  std::string sendEvent(const std::string& name, const std::string& context, const std::string& payload, EventResultCallback cb = nullptr);
295 
302  void sendEvent(CapabilityEvent* event, const std::string& context, const std::string& payload, EventResultCallback cb = nullptr);
303 
311  void sendAttachmentEvent(CapabilityEvent* event, bool is_end, size_t size, unsigned char* data);
312 
321  bool getProperty(const std::string& property, std::string& value) override;
322 
331  bool getProperties(const std::string& property, std::list<std::string>& values) override;
332 
337  void setCapabilityListener(ICapabilityListener* clistener) override;
338 
344  void setCancelPolicy(bool cancel_previous_dialog, DirectiveCancelPolicy&& cancel_policy = { true }) override;
345 
355  bool receiveCommand(const std::string& from, const std::string& command, const std::string& param) override;
356 
362  void receiveCommandAll(const std::string& command, const std::string& param) override;
363 
369  virtual void parsingDirective(const char* dname, const char* message);
370 
375  virtual std::string getContextInfo();
376 
381  virtual void updateCompactContext(NJson::Value& ctx) override;
382 
388 
389 protected:
391  bool initialized = false;
392 
395 
397  bool suspended = false;
398 
401 
404 
407 
410 
413 
416 
419 
422 
425 
426 private:
427  struct Impl;
428  std::unique_ptr<Impl> pimpl;
429  std::map<std::string, EventResultCallback> event_result_cbs;
430 };
431 
436 } // NuguClientKit
437 
438 #endif
CapabilityEvent.
Definition: capability.hh:51
void setMimeType(const std::string &type)
Set mime type.
void sendEvent(const std::string &context, const std::string &payload)
Send event to server.
std::string getMessageId()
Get message id.
void sendAttachmentEvent(bool is_end, size_t size, unsigned char *data)
Send attachment event to server.
std::string getDialogRequestId()
Get dialog request id.
void forceClose()
Close event forcibly.
void setDialogRequestId(const std::string &id)
Set dialog request id.
void setType(enum nugu_event_type type)
Set event type.
std::string getName()
Get event name.
Capability.
Definition: capability.hh:120
void setReferrerDialogRequestId(const std::string &dname, const std::string &id)
Set referred dialog request id.
std::string getVersion() override
Get the capability version of the current object.
IInteractionControlManager * interaction_control_manager
IInteractionControlManager instance for using interaction control management.
Definition: capability.hh:415
void notifyEventResult(const std::string &event_desc) override
Notify event result.
void sendAttachmentEvent(CapabilityEvent *event, bool is_end, size_t size, unsigned char *data)
Send attachment event to server.
IPlaySyncManager * playsync_manager
IPlaySyncManager instance for using playsync management.
Definition: capability.hh:406
void setVersion(const std::string &ver)
Set the capability version of the current object.
std::string getName() override
Get the capability name of the current object.
void sendEvent(CapabilityEvent *event, const std::string &context, const std::string &payload, EventResultCallback cb=nullptr)
Send event to server.
IRoutineManager * routine_manager
IRoutineManager instance for using routine management.
Definition: capability.hh:421
bool destroy_directive_by_agent
whether destroy received directive by agent
Definition: capability.hh:394
virtual void parsingDirective(const char *dname, const char *message)
Parsing directive and do the required action.
void cancelDirective(NuguDirective *ndir) override
Receive a directive cancellation from the Directive sequencer.
ICapabilityHelper * getCapabilityHelper()
Get ICapabilityHelper instance for using NuguCore functions.
ISessionManager * session_manager
ISessionManager instance for using session management.
Definition: capability.hh:412
std::string getPlayServiceIdInStackControl(const NJson::Value &playstack_control)
Get play service id which is managed by play stack control.
virtual std::string getContextInfo()
Get current context info.
void setNuguCoreContainer(INuguCoreContainer *core_container) override
Set INuguCoreContainer for using functions in NuguCore.
bool getProperties(const std::string &property, std::list< std::string > &values) override
It is possible to share own property values among objects.
SuspendPolicy suspend_policy
SuspendPolicy variable for deciding suspend action (default:STOP)
Definition: capability.hh:424
void setSuspendPolicy(SuspendPolicy policy=SuspendPolicy::STOP) override
Set capability suspend policy.
void initialize() override
Initialize the current object.
std::string getPlayServiceIdInStackControl(const char *payload)
Get play service id which is managed by play stack control.
void setName(const std::string &name)
Set the capability name of the current object.
void removeEventResultCallback(const std::string &ename) override
Remove event result callback.
InteractionMode getInteractionMode(const NJson::Value &interaction_control)
Get interaction mode which is included in interactionControl.
std::string getReferrerDialogRequestId(const std::string &ename)
Get referred dialog request id.
NuguDirective * getNuguDirective()
Get directive received from Directive Sequencer.
IDirectiveSequencer * directive_sequencer
IDirectiveSequencer instance for directive sequence management.
Definition: capability.hh:418
void preprocessDirective(NuguDirective *ndir) override
Receive a directive preprocessing request from Directive sequencer.
bool receiveCommand(const std::string &from, const std::string &command, const std::string &param) override
Process command from other objects.
void notifyEventResponse(const std::string &msg_id, const std::string &data, bool success) override
Notify event response info.
void destroyDirective(NuguDirective *ndir, bool is_cancel=false)
Destroy directive received from Directive Sequencer.
IFocusManager * focus_manager
IFocusManager instance for using audio focus.
Definition: capability.hh:409
std::string sendEvent(const std::string &name, const std::string &context, const std::string &payload, EventResultCallback cb=nullptr)
Send event to server.
virtual void updateCompactContext(NJson::Value &ctx) override
Update the compact context information of the capability agent.
void setCancelPolicy(bool cancel_previous_dialog, DirectiveCancelPolicy &&cancel_policy={ true }) override
Set directive cancel policy.
bool initialized
whether capability initialized
Definition: capability.hh:391
bool getProperty(const std::string &property, std::string &value) override
It is possible to share own property value among objects.
void setCapabilityListener(ICapabilityListener *clistener) override
Set the listener object.
bool suspended
whether capability suspend
Definition: capability.hh:397
void addEventResultCallback(const std::string &ename, EventResultCallback callback) override
Add event result callback for error handling.
INuguCoreContainer * core_container
INuguCoreContainer instance for using NuguCore functions.
Definition: capability.hh:400
void receiveCommandAll(const std::string &command, const std::string &param) override
Process command received from capability manager.
void suspend() override
Suspend current action.
ICapabilityHelper * capa_helper
ICapabilityHelper instance for using NuguCore functions.
Definition: capability.hh:403
void addReferrerEvents(const std::string &ename, const std::string &dname)
Add event name and directive name for referred dialog request id.
void processDirective(NuguDirective *ndir) override final
Receive a directive processing request from Directive sequencer.
void addBlockingPolicy(const std::string &dname, BlockingPolicy policy)
Add blocking policy for directive name.
void restore() override
Restore previous suspended action.
void deInitialize() override
Deinitialize the current object.
CapabilityHelper interface.
Definition: capability_helper_interface.hh:46
capability interface
Definition: capability_interface.hh:81
SuspendPolicy
Capability suspend policy.
Definition: capability_interface.hh:86
std::function< void(const std::string &, const std::string &, const std::string &, int, int)> EventResultCallback
Event result callback for error handling.
Definition: capability_interface.hh:99
capability listener interface
Definition: capability_interface.hh:59
IDirectiveSequencer.
Definition: directive_sequencer_interface.hh:93
IFocusManager.
Definition: focus_manager_interface.hh:126
InteractionControlManager interface.
Definition: interaction_control_manager_interface.hh:67
NuguCoreContainer interface.
Definition: nugu_core_container_interface.hh:43
IPlaySyncManager interface.
Definition: playsync_manager_interface.hh:95
IRoutineManager interface.
Definition: routine_manager_interface.hh:75
SessionManager interface.
Definition: session_manager_interface.hh:71
InteractionMode
Interaction Mode.
Definition: interaction_control_manager_interface.hh:38
struct _nugu_directive NuguDirective
Directive object.
Definition: nugu_directive.h:47
nugu_event_type
event types
Definition: nugu_event.h:46
BlockingPolicy.
Definition: directive_sequencer_interface.hh:51
Policy about canceling directives which are belong to the specific dialog id.
Definition: capability_interface.hh:45